Cereus.ly / app.py
Afeezee's picture
Create app.py
38358f4 verified
raw
history blame
1.01 kB
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()