File size: 954 Bytes
d6e49e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
import gradio as gr
import requests

def fetch_file(url):
    try:
        response = requests.get(url)
        response.raise_for_status()  # Raise an error for bad status codes
        file_name = url.split('/')[-1]  # Extract the file name from the URL
        return file_name, response.content
    except requests.exceptions.RequestException as e:
        return None, str(e)

def gradio_fetch_file(url):
    file_name, file_content = fetch_file(url)
    if file_name:
        return file_name, file_content
    else:
        return None, file_content

# Create the Gradio interface
iface = gr.Interface(
    fn=gradio_fetch_file,
    inputs=gr.Textbox(lines=1, placeholder="Enter the URL of the file..."),
    outputs=[
        gr.File(label="Downloaded File"),
        gr.Textbox(label="Error Message")
    ],
    title="File Fetcher",
    description="Enter the URL of the file to fetch and download it."
)

# Launch the Gradio app
iface.launch()