Classtest / app.py
simonraj's picture
Update app.py
7962920 verified
raw
history blame
873 Bytes
import gradio as gr
# Function to dynamically update the student numbers based on the selected class
def update_dropdown(class_prefix):
# Generate student numbers for the selected class
return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]
# Define the class options for the first dropdown
class_options = ["5H", "5E", "5RS"]
# Create the Gradio interface
with gr.Blocks() as demo:
# Create the first dropdown with class options
class_dropdown = gr.Dropdown(label="Class", choices=class_options)
# Initialize the second dropdown with an empty list; it will be updated dynamically
student_dropdown = gr.Dropdown(label="Student", choices=[])
# When the class dropdown changes, update the student dropdown
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)
# Launch the app
demo.launch()