File size: 845 Bytes
c943374
 
d6e756e
 
 
 
 
 
 
 
7962920
d6e756e
c2a9970
c943374
d6e756e
c943374
c2a9970
d6e756e
c943374
d6e756e
 
 
 
c943374
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr

def update_dropdown(class_prefix):
    # Check if a class prefix is selected
    if class_prefix is None:
        # If no class is selected, return an empty list
        return []
    else:
        # Generate student numbers for the selected class
        return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]

# Define the options for the first dropdown
class_options = ["5H", "5E", "5RS"]

# Create the Gradio interface
with gr.Blocks() as demo:
    class_dropdown = gr.Dropdown(label="Class", choices=class_options, value="5H")
    student_dropdown = gr.Dropdown(label="Student", choices=update_dropdown("5H"))

    # When the selected class changes, update the student dropdown
    class_dropdown.change(fn=update_dropdown, inputs=[class_dropdown], outputs=[student_dropdown])

# Launch the app
demo.launch()