Spaces:
Runtime error
Runtime error
Update Upload_file
Browse files- Upload_file +21 -6
Upload_file
CHANGED
@@ -1,7 +1,22 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|