Spaces:
Sleeping
Sleeping
| 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() |