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

# Function to update the second dropdown based on the first
def update_dropdown(class_prefix):
    # This generates a list of values like "5H01", "5H02", ..., "5H40"
    return [f"{class_prefix}{str(i).zfill(2)}" for i in range(1, 41)]

# This is the initial value for the first dropdown
initial_class = "5H"

# Create the Gradio interface
with gr.Blocks() as demo:
    # The first dropdown is initialized with "5H" as the default value
    class_dropdown = gr.Dropdown(label="Class", choices=["5H", "5E", "5RS"], value=initial_class)
    # The second dropdown is initialized with the values corresponding to "5H"
    student_dropdown = gr.Dropdown(label="Student", choices=update_dropdown(initial_class))

    # When the first dropdown changes, the second dropdown's choices are updated
    class_dropdown.change(fn=update_dropdown, inputs=class_dropdown, outputs=student_dropdown)

# Launch the app
demo.launch()