import gradio as gr | |
# ... (rest of your code) | |
# Create the Gradio interface | |
with gr.Blocks() as demo: | |
class_dropdown = gr.Dropdown(label="Class", choices=class_options) | |
# Initialize the second dropdown with a callable for dynamic updates | |
student_dropdown = gr.Dropdown(label="Student", choices=lambda: update_dropdown(class_options[0])) | |
# Bind the update function to the change event of the class dropdown | |
class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown) | |
# Run the app | |
demo.launch() |