Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
# Define
|
10 |
class_options = ["5H", "5E", "5RS"]
|
11 |
|
|
|
12 |
with gr.Blocks() as demo:
|
13 |
class_dropdown = gr.Dropdown(label="Class", choices=class_options, value="5H")
|
14 |
-
student_dropdown = gr.Dropdown(label="Student", choices=
|
15 |
-
|
16 |
-
# Use the change event to update the student dropdown when the class changes
|
17 |
-
class_dropdown.change(fn=update_student_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
18 |
|
|
|
|
|
|
|
|
|
19 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
def update_dropdown(class_prefix):
|
4 |
+
# Check if a class prefix is selected
|
5 |
+
if class_prefix is None:
|
6 |
+
# If no class is selected, return an empty list
|
7 |
+
return []
|
8 |
+
else:
|
9 |
+
# Generate student numbers for the selected class
|
10 |
+
return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
|
11 |
|
12 |
+
# Define the options for the first dropdown
|
13 |
class_options = ["5H", "5E", "5RS"]
|
14 |
|
15 |
+
# Create the Gradio interface
|
16 |
with gr.Blocks() as demo:
|
17 |
class_dropdown = gr.Dropdown(label="Class", choices=class_options, value="5H")
|
18 |
+
student_dropdown = gr.Dropdown(label="Student", choices=update_dropdown("5H"))
|
|
|
|
|
|
|
19 |
|
20 |
+
# When the selected class changes, update the student dropdown
|
21 |
+
class_dropdown.change(fn=update_dropdown, inputs=[class_dropdown], outputs=[student_dropdown])
|
22 |
+
|
23 |
+
# Launch the app
|
24 |
demo.launch()
|