Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
options_1 = ['Paris', 'Berlin' ]
|
4 |
+
options_2 = {
|
5 |
+
'Paris': ['Saint Denis', 'Eiffel Tower', 'Le Louvre'],
|
6 |
+
'Berlin': ['Reichstag', 'Alexanderplatz', 'Kreuzberg'],
|
7 |
+
}
|
8 |
+
|
9 |
+
with gr.Blocks() as demo:
|
10 |
+
d1 = gr.Dropdown(choices=options_1, label="City dropdown")
|
11 |
+
d2 = gr.Dropdown([])
|
12 |
+
|
13 |
+
def update_second(first_val):
|
14 |
+
d2 = gr.Dropdown(options_2[first_val])
|
15 |
+
return d2
|
16 |
+
|
17 |
+
d1.input(update_second, d1, d2)
|
18 |
+
|
19 |
+
outputs = gr.Textbox()
|
20 |
+
|
21 |
+
def print_results(option_1, option_2):
|
22 |
+
return f"You selected '{option_1}' in the first dropdown and '{option_2}' in the second dropdown."
|
23 |
+
|
24 |
+
d2.input(print_results, [d1, d2], outputs)
|
25 |
+
|
26 |
+
demo.launch()
|