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
32.15k stars 2.4k forks source link

Audio stop_recording/start_recording events triggered multiple times when you pass in custom js #9180

Closed freddyaboulton closed 3 days ago

freddyaboulton commented 3 weeks ago

Describe the bug

Run this demo

import gradio as gr

custom_js = """
function customJS(num) {
    console.log("calling js");
    return num;
}
"""

def add_one(num):
    print(f"calling python {num}")
    return num + 1

with gr.Blocks() as demo:
    n_calls = gr.Number(value=0, label="Number of calls")
    audio = gr.Audio(sources="microphone", label="Audio")

    audio.stop_recording(add_one,  n_calls, n_calls, js=custom_js)

demo.launch()

After you stop recording you'll see multiple lines printed to the console like

calling python 0
calling python 0
calling python 0
calling python 0
calling python 0

And the "calling js" line was printed multiple times

image

Have you searched existing issues? 🔎

Reproduction

Above^

Screenshot

record_stop_bug

Logs

No response

System Info

main

Severity

Blocking usage of gradio

freddyaboulton commented 3 weeks ago

If you remove the js, the python function is only called once