Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Create the Gradio interface
|
6 |
with gr.Blocks() as demo:
|
|
|
7 |
class_dropdown = gr.Dropdown(label="Class", choices=class_options)
|
8 |
-
# Initialize the second dropdown with
|
9 |
-
student_dropdown = gr.Dropdown(label="Student", choices=
|
10 |
|
11 |
-
#
|
12 |
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
13 |
|
14 |
-
#
|
15 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# Function to dynamically update the student numbers based on the selected class
|
4 |
+
def update_dropdown(class_prefix):
|
5 |
+
# Generate student numbers for the selected class
|
6 |
+
return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
|
7 |
+
|
8 |
+
# Define the class options for the first dropdown
|
9 |
+
class_options = ["5H", "5E", "5RS"]
|
10 |
|
11 |
# Create the Gradio interface
|
12 |
with gr.Blocks() as demo:
|
13 |
+
# Create the first dropdown with class options
|
14 |
class_dropdown = gr.Dropdown(label="Class", choices=class_options)
|
15 |
+
# Initialize the second dropdown with an empty list; it will be updated dynamically
|
16 |
+
student_dropdown = gr.Dropdown(label="Student", choices=[])
|
17 |
|
18 |
+
# When the class dropdown changes, update the student dropdown
|
19 |
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
20 |
|
21 |
+
# Launch the app
|
22 |
demo.launch()
|