[Python] What am I doing wrong with gradio.Dropdown? How to dynamically modify the choices of...

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create a gradio webui that shows 2 dropdown, rs_hw changes dynamically according to the rs value. What am I doing wrong here?

    import gradio as gr

    languages = ['spanish', 'english']
    homeworks = {'spanish': ['hola', 'bien', 'gracias'], 'english': ['hello', 'good', 'thank you']}

    def rs_change(rs):
    return homeworks[rs]

    with gr.Blocks() as app:

    rs = gr.Dropdown(choices=languages)
    rs_hw = gr.Dropdown()

    rs.change(fn=rs_change, inputs=[rs], outputs=[rs_hw])

    app.launch()


    rs_hw keeps always empty

    Continue reading...

Compartilhe esta Página