Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,21 @@
|
|
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
|
6 |
-
|
|
|
|
|
7 |
|
8 |
-
# Define
|
9 |
class_options = ["5H", "5E", "5RS"]
|
10 |
|
11 |
# Create the Gradio interface
|
12 |
with gr.Blocks() as demo:
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
student_dropdown = gr.Dropdown(label="Student", choices=[])
|
17 |
|
18 |
-
#
|
19 |
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
20 |
|
21 |
# Launch the app
|
|
|
1 |
import gradio as gr
|
2 |
|
|
|
3 |
def update_dropdown(class_prefix):
|
4 |
+
# Generate a list of student numbers for the class
|
5 |
+
if class_prefix is not None:
|
6 |
+
return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
|
7 |
+
return []
|
8 |
|
9 |
+
# Define class options for the first dropdown
|
10 |
class_options = ["5H", "5E", "5RS"]
|
11 |
|
12 |
# Create the Gradio interface
|
13 |
with gr.Blocks() as demo:
|
14 |
+
class_dropdown = gr.Dropdown(label="Class", choices=class_options, value=class_options[0])
|
15 |
+
# Initialize the second dropdown with the values from the first class as default
|
16 |
+
student_dropdown = gr.Dropdown(label="Student", choices=update_dropdown(class_options[0]))
|
|
|
17 |
|
18 |
+
# Bind the update function to the class dropdown
|
19 |
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
20 |
|
21 |
# Launch the app
|