Straive-Kripa commited on
Commit
e5394d1
·
verified ·
1 Parent(s): 6905819

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import gradio as gr
3
+
4
+ def upload_file(filepath):
5
+ name = Path(filepath).name
6
+ return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
7
+
8
+ def download_file():
9
+ return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
10
+
11
+ with gr.Blocks() as demo:
12
+ gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
13
+ with gr.Row():
14
+ u = gr.UploadButton("Upload a file", file_count="single")
15
+ d = gr.DownloadButton("Download the file", visible=False)
16
+
17
+ u.upload(upload_file, u, [u, d])
18
+ d.click(download_file, None, [u, d])
19
+
20
+
21
+ if __name__ == "__main__":
22
+ demo.launch()