Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from urllib.parse import quote
|
3 |
+
|
4 |
+
def shorten_url(long_url):
|
5 |
+
# Basic hash-based "shortening" — not a real URL shortener
|
6 |
+
root = 'https://cos.twcc.ai/taiwanesecorpus/twasr_talking2/'
|
7 |
+
length = len(root)
|
8 |
+
fn = long_url[length:]
|
9 |
+
return root+quote(fn, safe='') # encode all characters including slashes
|
10 |
+
|
11 |
+
with gr.Blocks(title="URL Encoder with Copy") as demo:
|
12 |
+
gr.Markdown("## 🔐 URL Encoder")
|
13 |
+
|
14 |
+
input_url = gr.Textbox(label="Enter URL", placeholder="https://example.com/hello world/?q=python&lang=en")
|
15 |
+
encoded_output = gr.Textbox(label="Encoded URL", interactive=True, show_copy_button=True)
|
16 |
+
|
17 |
+
encode_button = gr.Button("Encode URL")
|
18 |
+
encode_button.click(fn=shorten_url, inputs=input_url, outputs=encoded_output)
|
19 |
+
|
20 |
+
demo.launch()
|