Spaces:
Sleeping
Sleeping
Test download button
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from typing import Dict
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
@@ -14,23 +15,21 @@ title = "This is title."
|
|
14 |
description = "This is description."
|
15 |
article = "This is article."
|
16 |
|
17 |
-
def
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
[
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
)
|
29 |
-
|
30 |
-
]
|
31 |
-
|
32 |
-
description="Enter gender as 'M', 'F', or 'O' for other.",
|
33 |
-
)
|
34 |
|
35 |
demo.launch(debug=False,
|
36 |
share=True)
|
|
|
1 |
from typing import Dict
|
2 |
+
from pathlib import Path
|
3 |
|
4 |
import gradio as gr
|
5 |
|
|
|
15 |
description = "This is description."
|
16 |
article = "This is article."
|
17 |
|
18 |
+
def upload_file(filepath):
|
19 |
+
name = Path(filepath).name
|
20 |
+
return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
|
21 |
+
|
22 |
+
def download_file():
|
23 |
+
return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
|
24 |
+
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
|
27 |
+
with gr.Row():
|
28 |
+
u = gr.UploadButton("Upload a file", file_count="single")
|
29 |
+
d = gr.DownloadButton("Download the file", visible=False)
|
30 |
+
|
31 |
+
u.upload(upload_file, u, [u, d])
|
32 |
+
d.click(download_file, None, [u, d])
|
|
|
|
|
33 |
|
34 |
demo.launch(debug=False,
|
35 |
share=True)
|