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