Update app.py
Browse files
app.py
CHANGED
@@ -146,10 +146,35 @@
|
|
146 |
# demo.launch()
|
147 |
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
import gradio as gr
|
150 |
|
151 |
-
def
|
152 |
-
# Logic to determine new options based on selected option
|
153 |
if selected_option == "Option 1":
|
154 |
new_options = ["Suboption 1.1", "Suboption 1.2"]
|
155 |
elif selected_option == "Option 2":
|
@@ -157,17 +182,18 @@ def update_options(selected_option):
|
|
157 |
else:
|
158 |
new_options = ["Suboption 3.1", "Suboption 3.2"]
|
159 |
|
160 |
-
new_options
|
161 |
-
|
162 |
-
# Return the new options to update the second dropdown
|
163 |
-
return new_options # Return current selection to persist it in the first dropdown
|
164 |
|
165 |
with gr.Blocks() as demo:
|
166 |
with gr.Row():
|
167 |
-
dropdown_1 = gr.Dropdown(
|
168 |
-
dropdown_2 = gr.Dropdown(
|
|
|
|
|
|
|
|
|
169 |
|
170 |
-
|
171 |
-
dropdown_2.change(fn=update_options, inputs=dropdown_2, outputs=dropdown_1)
|
172 |
|
173 |
demo.launch()
|
|
|
|
146 |
# demo.launch()
|
147 |
|
148 |
|
149 |
+
# import gradio as gr
|
150 |
+
|
151 |
+
# def update_options(selected_option):
|
152 |
+
# # Logic to determine new options based on selected option
|
153 |
+
# if selected_option == "Option 1":
|
154 |
+
# new_options = ["Suboption 1.1", "Suboption 1.2"]
|
155 |
+
# elif selected_option == "Option 2":
|
156 |
+
# new_options = ["Suboption 2.1", "Suboption 2.2"]
|
157 |
+
# else:
|
158 |
+
# new_options = ["Suboption 3.1", "Suboption 3.2"]
|
159 |
+
|
160 |
+
# new_options = ['Something', 'something else']
|
161 |
+
|
162 |
+
# # Return the new options to update the second dropdown
|
163 |
+
# return new_options # Return current selection to persist it in the first dropdown
|
164 |
+
|
165 |
+
# with gr.Blocks() as demo:
|
166 |
+
# with gr.Row():
|
167 |
+
# dropdown_1 = gr.Dropdown(choices=["Option 1", "Option 2", "Option 3"], label="Main Options")
|
168 |
+
# dropdown_2 = gr.Dropdown(choices=['just here', 'for the sake of it'], label="Sub Options")
|
169 |
+
|
170 |
+
# # When the first dropdown changes, update the options in the second dropdown
|
171 |
+
# dropdown_2.change(fn=update_options, inputs=dropdown_2, outputs=dropdown_1)
|
172 |
+
|
173 |
+
# demo.launch()
|
174 |
+
|
175 |
import gradio as gr
|
176 |
|
177 |
+
def update_dropdown_2(selected_option, dropdown_2_choices):
|
|
|
178 |
if selected_option == "Option 1":
|
179 |
new_options = ["Suboption 1.1", "Suboption 1.2"]
|
180 |
elif selected_option == "Option 2":
|
|
|
182 |
else:
|
183 |
new_options = ["Suboption 3.1", "Suboption 3.2"]
|
184 |
|
185 |
+
return new_options
|
|
|
|
|
|
|
186 |
|
187 |
with gr.Blocks() as demo:
|
188 |
with gr.Row():
|
189 |
+
dropdown_1 = gr.Dropdown(["Option 1", "Option 2", "Option 3"], label="Main Options")
|
190 |
+
dropdown_2 = gr.Dropdown(["Suboption 1.1", "Suboption 1.2"], label="Sub Options")
|
191 |
+
|
192 |
+
def on_dropdown_1_change(selected_option):
|
193 |
+
new_choices = update_dropdown_2(selected_option, dropdown_2)
|
194 |
+
dropdown_2.update(choices=new_choices)
|
195 |
|
196 |
+
dropdown_1.change(on_dropdown_1_change, inputs=dropdown_1, outputs=dropdown_2)
|
|
|
197 |
|
198 |
demo.launch()
|
199 |
+
|