Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
#
|
4 |
-
def update_dropdown(class_prefix):
|
5 |
-
# Check if a class prefix is selected
|
6 |
-
if class_prefix:
|
7 |
-
# Generate student numbers for the selected class
|
8 |
-
student_numbers = [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
|
9 |
-
return student_numbers
|
10 |
-
else:
|
11 |
-
# Return an empty list if no class prefix is selected
|
12 |
-
return []
|
13 |
|
14 |
-
#
|
15 |
-
class_options = ["5H", "5E", "5RS"]
|
16 |
-
|
17 |
-
# Create the Gradio interface with two dropdowns
|
18 |
with gr.Blocks() as demo:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
#
|
24 |
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
25 |
|
26 |
# Run the app
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# ... (rest of your code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 a callable for dynamic updates
|
9 |
+
student_dropdown = gr.Dropdown(label="Student", choices=lambda: update_dropdown(class_options[0]))
|
10 |
|
11 |
+
# Bind the update function to the change event of the class dropdown
|
12 |
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
|
13 |
|
14 |
# Run the app
|