|
import gradio as gr |
|
|
|
|
|
def upload_and_save_file(input_file): |
|
|
|
file_path = "uploaded_file.txt" |
|
with open(file_path, "wb") as f: |
|
f.write(input_file.read()) |
|
return "File uploaded successfully!" |
|
|
|
|
|
def download_file(): |
|
|
|
file_path = "uploaded_file.txt" |
|
with open(file_path, "rb") as f: |
|
file_contents = f.read() |
|
return file_contents |
|
|
|
|
|
inputs = gr.File(label="Upload File") |
|
output = gr.File(label="Download File") |
|
|
|
|
|
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() |
|
|
|
|
|
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() |
|
|