Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
|
|
|
3 |
def update_dropdown(class_prefix):
|
4 |
-
#
|
5 |
-
|
6 |
-
return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
|
7 |
-
return []
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
# Create the Gradio interface
|
13 |
with gr.Blocks() as demo:
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
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 |
+
# Function to update the second dropdown based on the first
|
4 |
def update_dropdown(class_prefix):
|
5 |
+
# This generates a list of values like "5H01", "5H02", ..., "5H40"
|
6 |
+
return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
|
|
|
|
|
7 |
|
8 |
+
# This is the initial value for the first dropdown
|
9 |
+
initial_class = "5H"
|
10 |
|
11 |
# Create the Gradio interface
|
12 |
with gr.Blocks() as demo:
|
13 |
+
# The first dropdown is initialized with "5H" as the default value
|
14 |
+
class_dropdown = gr.Dropdown(label="Class", choices=["5H", "5E", "5RS"], value=initial_class)
|
15 |
+
# The second dropdown is initialized with the values corresponding to "5H"
|
16 |
+
student_dropdown = gr.Dropdown(label="Student", choices=update_dropdown(initial_class))
|
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
|