File size: 1,316 Bytes
bf68204
3bdad20
 
0e03c56
 
 
 
 
 
 
 
bf68204
 
de47419
838b57c
3bdad20
bf68204
de47419
bf68204
743c678
838b57c
bf68204
3bdad20
bf68204
838b57c
bf68204
838b57c
57912bc
 
bf68204
 
 
3bdad20
bf68204
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from pathlib import Path
import gradio as gr

css = """.hamburger-button {
    width: 30px !important;
    background-color: transparent !important;
    border: none !important;
    padding: 0 !important;
    outline: none !important;
}"""

def upload_file(filepath):
    name = Path(filepath).name
    return [gr.UploadButton(interactive=False, icon='icon4.png',), 
            gr.DownloadButton( value=filepath, interactive=True, icon='icon2.png',)] #label=f"Download {name}",

def download_file():
    return [gr.UploadButton(interactive=True), gr.DownloadButton(interactive=False, icon='icon1.png',)]

with gr.Blocks(css=css, 
               theme=gr.themes.Base(radius_size=gr.themes.sizes.radius_none,)) as demo:
    tb = gr.Textbox(value = "First upload a file and and then you'll be able download it (but only once!)")
    with gr.Row():
      with gr.Column(scale=1):
        u = gr.UploadButton(icon='icon3.png', elem_classes="hamburger-button", label="", file_count="single", size='sm')
      with gr.Column(scale=1):
        d = gr.DownloadButton( icon='icon1.png', elem_classes="hamburger-button", label="", interactive=False, size='sm')
      with gr.Column(scale=8):
        t = gr.Textbox(visible=False, )

    u.upload(upload_file, u, [u, d])
    d.click(download_file, None, [u, d])

demo.launch()