File size: 779 Bytes
53f5925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
from urllib.parse import quote

def shorten_url(long_url):
    # Basic hash-based "shortening" β€” not a real URL shortener
    root = 'https://cos.twcc.ai/taiwanesecorpus/twasr_talking2/'
    length = len(root)
    fn = long_url[length:]
    return root+quote(fn, safe='')  # encode all characters including slashes

with gr.Blocks(title="URL Encoder with Copy") as demo:
    gr.Markdown("## πŸ” URL Encoder")

    input_url = gr.Textbox(label="Enter URL", placeholder="https://example.com/hello world/?q=python&lang=en")
    encoded_output = gr.Textbox(label="Encoded URL", interactive=True, show_copy_button=True)

    encode_button = gr.Button("Encode URL")
    encode_button.click(fn=shorten_url, inputs=input_url, outputs=encoded_output)

demo.launch()