simonraj commited on
Commit
9f654db
·
verified ·
1 Parent(s): c943374

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -1,20 +1,27 @@
1
  import gradio as gr
2
 
 
3
  def update_dropdown(class_prefix):
4
- # Create a list of options based on the selected class prefix
5
- student_numbers = [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
6
- return student_numbers
 
 
 
 
 
7
 
8
- # Define the options for the first dropdown
9
  class_options = ["5H", "5E", "5RS"]
10
 
11
- # Create the Gradio interface
12
  with gr.Blocks() as demo:
13
  with gr.Row():
14
  class_dropdown = gr.Dropdown(label="Class", choices=class_options)
15
- student_dropdown = gr.Dropdown(label="Student")
16
 
 
17
  class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
18
 
19
- # Launch the app
20
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ # Function to update the student numbers dropdown based on the selected class
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
+ # List of class options for the dropdown
15
  class_options = ["5H", "5E", "5RS"]
16
 
17
+ # Create the Gradio interface with two dropdowns
18
  with gr.Blocks() as demo:
19
  with gr.Row():
20
  class_dropdown = gr.Dropdown(label="Class", choices=class_options)
21
+ student_dropdown = gr.Dropdown(label="Student", choices=[])
22
 
23
+ # Update student dropdown when class dropdown changes
24
  class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
25
 
26
+ # Run the app
27
  demo.launch()