File size: 1,176 Bytes
d23e3db fbc9df3 d23e3db |
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 34 35 36 37 38 39 40 41 42 43 44 |
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.File(label="Upload File")
output = gr.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()
|