import gradio as gr # Define the function to upload and save the file def upload_and_save_file(input_file): # Save the uploaded file with a specific name file_path = "uploaded_file.txt" with open(file_path, "wb") as f: f.write(input_file.read()) return "File uploaded successfully!" # Define the function to download the file def download_file(): # Read the file and return it for download file_path = "uploaded_file.txt" with open(file_path, "rb") as f: file_contents = f.read() return file_contents # Define the inputs and outputs for the Gradio interface inputs = gr.inputs.File(label="Upload File") output = gr.outputs.File(label="Download File") # Create the Gradio interface gr.Interface( fn=upload_and_save_file, inputs=inputs, outputs=None, title="File Uploader", description="Upload a file to download later", allow_flagging=False ).launch() # Create the download page download_interface = gr.Interface( fn=download_file, inputs=None, outputs=output, title="File Downloader", description="Download the previously uploaded file", allow_flagging=False ) download_interface.launch()