Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def fetch_file(url):
|
5 |
+
try:
|
6 |
+
response = requests.get(url)
|
7 |
+
response.raise_for_status() # Raise an error for bad status codes
|
8 |
+
file_name = url.split('/')[-1] # Extract the file name from the URL
|
9 |
+
return file_name, response.content
|
10 |
+
except requests.exceptions.RequestException as e:
|
11 |
+
return None, str(e)
|
12 |
+
|
13 |
+
def gradio_fetch_file(url):
|
14 |
+
file_name, file_content = fetch_file(url)
|
15 |
+
if file_name:
|
16 |
+
return file_name, file_content
|
17 |
+
else:
|
18 |
+
return None, file_content
|
19 |
+
|
20 |
+
# Create the Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=gradio_fetch_file,
|
23 |
+
inputs=gr.Textbox(lines=1, placeholder="Enter the URL of the file..."),
|
24 |
+
outputs=[
|
25 |
+
gr.File(label="Downloaded File"),
|
26 |
+
gr.Textbox(label="Error Message")
|
27 |
+
],
|
28 |
+
title="File Fetcher",
|
29 |
+
description="Enter the URL of the file to fetch and download it."
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the Gradio app
|
33 |
+
iface.launch()
|