File size: 708 Bytes
ce12923
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6bca2d
ce12923
e6bca2d
 
ce12923
e6bca2d
ce12923
 
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
import gradio as gr

options_1 = ['Paris', 'Berlin' ]
options_2 = {
    'Paris': ['Saint Denis', 'Eiffel Tower', 'Le Louvre'],
    'Berlin': ['Reichstag', 'Alexanderplatz', 'Kreuzberg'],
    }

with gr.Blocks() as demo:
    d1 = gr.Dropdown(choices=options_1, label="City dropdown")
    d2 = gr.Dropdown([])
    
    def update_second(first_val):
        d2 = gr.Dropdown(options_2[first_val])
        return d2 
    
    d1.input(update_second, d1, d2)

    #outputs = gr.Textbox()

    #def print_results(option_1, option_2):
        #return f"You selected '{option_1}' in the first dropdown and '{option_2}' in the second dropdown."
        
    #d2.input(print_results, [d1, d2], outputs) 

demo.launch()