Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
#
|
4 |
-
def
|
5 |
-
#
|
6 |
-
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
|
11 |
-
# Create the Gradio interface
|
12 |
with gr.Blocks() as demo:
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
17 |
|
18 |
-
# When the first dropdown changes, the second dropdown's choices are updated
|
19 |
-
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
20 |
-
|
21 |
-
# Launch the app
|
22 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# This function is called whenever the class dropdown changes.
|
4 |
+
def update_student_dropdown(class_selection):
|
5 |
+
# Generate the list of student numbers for the selected class
|
6 |
+
student_numbers = [f"{class_selection}{str(i).zfill(2)}" for i in range(1, 41)]
|
7 |
+
return student_numbers
|
8 |
|
9 |
+
# Define your class options for the dropdown
|
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=update_student_dropdown("5H"))
|
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()
|