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()