Spaces:
Sleeping
Sleeping
File size: 1,009 Bytes
38358f4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import pyshorteners
import gradio as gr
import os
#Initialize the URL shortener
shortener = pyshorteners.Shortener()
# Function to shorten a URL using TinyURL (default in pyshorteners)
def shorten_url(original_url):
try:
shortened_url = shortener.tinyurl.short(original_url)
return f'<a href="{shortened_url}" target="_blank">{shortened_url}</a>'
except Exception as e:
return f"Error: {str(e)}"
# Gradio Interface
with gr.Blocks() as demo:
gr.Markdown("**URL Shortener**", elem_id="title")
gr.Markdown("Enter a URL to shorten it using this app. More customized features coming.", elem_id="description")
with gr.Column():
url_input = gr.Textbox(label="Original URL", placeholder="Enter the original URL here...")
url_output = gr.HTML(label="Shortened URL")
generate_button = gr.Button("Generate Shortened URL")
generate_button.click(fn=shorten_url, inputs=url_input, outputs=url_output)
#Launch the interface
demo.launch() |