tnt306 commited on
Commit
47d95c0
·
1 Parent(s): 86bff09

Test download button

Browse files
Files changed (1) hide show
  1. app.py +16 -17
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 filter_records(records, gender):
18
- return records[records["gender"] == gender]
19
-
20
- demo = gr.Interface(
21
- filter_records,
22
- [
23
- gr.Dataframe(
24
- headers=["name", "age", "gender"],
25
- datatype=["str", "number", "str"],
26
- row_count=5,
27
- col_count=(3, "fixed"),
28
- ),
29
- gr.Dropdown(["M", "F", "O"]),
30
- ],
31
- "dataframe",
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)