Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
if __name__ == "__main__":
|
| 21 |
+
demo.launch()
|