File size: 1,025 Bytes
f1c5c38
 
 
bb219e7
 
 
 
f1c5c38
 
 
bb219e7
 
 
a0b7d04
bb219e7
f1c5c38
 
 
47322e4
71f5eaa
893d4cd
f56b74f
f1c5c38
e05ae18
f56b74f
71f5eaa
 
d93f52e
5ef912c
d93f52e
 
71f5eaa
 
ad269a2
 
 
 
f1c5c38
 
893d4cd
f1c5c38
893d4cd
 
f1c5c38
 
ad269a2
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
36
37
38
39
40
41
42
43
44
45
46
47
import time

import gradio as gr
from huggingface_hub import HfFileSystem


fs = HfFileSystem()


def init_choices():
    #t = time.gmtime(time.time())
    #return {"a": 1, "b": 2, f"{t.tm_min}:{t.tm_sec}": 3}
    path = "datasets/albertvillanova/tmp-state-on-load-ds/**/**/*.json"
    paths = HfFileSystem().glob(path)
    return {path: path for path in paths}


with gr.Blocks() as demo:
    dropdown = gr.Dropdown(label="Select", multiselect=True, choices=["a0", "b0"])
    dropdown2 = gr.Dropdown(label="Select", multiselect=True)
    state = gr.State()
    clear = gr.Button("Clear")

    gr.on(
        [demo.load, clear.click],
        fn=init_choices,
        outputs=state,
    ).then(
        fn=lambda x: gr.Dropdown(choices=list(x.keys()), interactive=True),
        inputs=state,
        outputs=dropdown2,
    )


demo.launch()

"""
    demo.load(
        fn=init_choices,
        outputs=state,
    ).then(
        fn=lambda x: gr.Dropdown(choices=x),
        inputs=state,
        outputs=dropdown,
    )
"""