simonraj commited on
Commit
d6e756e
·
verified ·
1 Parent(s): c2a9970

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,19 +1,24 @@
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()
 
1
  import gradio as gr
2
 
3
+ def update_dropdown(class_prefix):
4
+ # Check if a class prefix is selected
5
+ if class_prefix is None:
6
+ # If no class is selected, return an empty list
7
+ return []
8
+ else:
9
+ # Generate student numbers for the selected class
10
+ return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
11
 
12
+ # Define the options for the first dropdown
13
  class_options = ["5H", "5E", "5RS"]
14
 
15
+ # Create the Gradio interface
16
  with gr.Blocks() as demo:
17
  class_dropdown = gr.Dropdown(label="Class", choices=class_options, value="5H")
18
+ student_dropdown = gr.Dropdown(label="Student", choices=update_dropdown("5H"))
 
 
 
19
 
20
+ # When the selected class changes, update the student dropdown
21
+ class_dropdown.change(fn=update_dropdown, inputs=[class_dropdown], outputs=[student_dropdown])
22
+
23
+ # Launch the app
24
  demo.launch()