gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.79k stars 2.56k forks source link

Radio component doesn't work if updated. #7757

Closed GaiZhenbiao closed 7 months ago

GaiZhenbiao commented 7 months ago

Describe the bug

I'm encountering an issue where a Gradio app's Radio button component stops responding to user input after its choices are updated dynamically. Here's a breakdown of the problem:

Steps to reproduce

Create a Gradio app with a Radio button component and some initial choices. Include a function that displays a notification based on the selected radio option. Write code to dynamically alter the choices in the Radio button component. Try selecting a radio option after the choices have been updated.

Expected behavior

The notification function should execute, displaying the newly selected value.

Actual behavior

No notification appears, and the Radio button appears unresponsive.

Have you searched existing issues? 🔎

Reproduction

import gradio as gr

def select_llm(llm_name):
    gr.Info(f"Selected {llm_name}")

def update_llm_select():
    return gr.Radio(choices=["LLaMA", "Gemma", "Grok", "Phi"])

with gr.Blocks() as demo:
    radio = gr.Radio(choices=["Claude", "DialoGPT", "GPT-3", "MegaM", "Mitsuku", "Replika", "Simsimi", "Sofia", "Zo"])
    update_radio_btn = gr.Button("Update")

    radio.input(select_llm, radio, [])
    update_radio_btn.click(update_llm_select, [], [radio])

demo.queue().launch()

Screenshot

The reproduction code will pop a notification containing the user-selected value.

image

But if you update the choices of the radio group, it breaks; nothing happens after the user's action, nothing is executed.

image

There were no warnings or errors in either the Python console or the browser's JavaScript console.

Logs

No errors or warnings are displayed in either the Python console or the browser's JavaScript console.

System Info

Gradio version: 4.22.0
Python version: 3.10
Browser: Arc 1.34.0 (Chromium)
Operating system: macOS Sonoma

Severity

Blocking usage of gradio

freddyaboulton commented 7 months ago

This should work with the select event @GaiZhenbiao - but I think we can fix the issue with the input event.

hannahblair commented 7 months ago

Hi @GaiZhenbiao! Thanks for raising this. I'm not sure if I'm able to reproduce this. Here's a recording on my end:

Kapture 2024-03-20 at 16 41 32

freddyaboulton commented 7 months ago

Interesting I was able to repro

GaiZhenbiao commented 7 months ago

Hi @GaiZhenbiao! Thanks for raising this. I'm not sure if I'm able to reproduce this. Here's a recording on my end:

Kapture 2024-03-20 at 16 41 32

I'm using Gradio 4.22.0. This issue wasn't there a few versions ago.