Rahul8827 commited on
Commit
e3e6b7f
·
1 Parent(s): add1007

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ options = {
4
+ "A1": ["aa1", "aa11", "aa111"],
5
+ "A2": ["aa2", "aa22", "aa222"],
6
+ "A3": []
7
+ }
8
+
9
+ def greet(option1, option2):
10
+ return f"Selected Option 1: {option1}\nSelected Option 2: {option2}"
11
+
12
+ option1_dropdown = gr.inputs.Dropdown(choices=["A1", "A2", "A3"], label="Dropdown 1")
13
+ option2_dropdown = gr.inputs.Dropdown(choices=[], label="Dropdown 2") # Initial empty choices
14
+
15
+ output_text = gr.outputs.Textbox()
16
+
17
+ def update_options(option1):
18
+ option2_dropdown.choices = options.get(option1, []) # Update choices for option2 based on option1
19
+
20
+ gr.Interface(fn=greet, inputs=[option1_dropdown, option2_dropdown], outputs=output_text,
21
+ examples=[["A1", "aa1"], ["A2", "aa2"]], title="Dynamic Dropdowns",
22
+ preprocessing_hooks=[update_options]).launch()