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
30.56k stars 2.27k forks source link

When `every` set in gr.Button.click, the inner function cannot get live camera images #8463

Open P2Oileen opened 3 weeks ago

P2Oileen commented 3 weeks ago

Describe the bug

I am trying to show the camera image, but when I set button.click(every=xxx), it cannot get any image. This problem doesn't happen when I delete every=xxx and click the button by myself.

Have you searched existing issues? 🔎

Reproduction

import gradio as gr

def echo(webcam_image):
    if webcam_image is not None:
        gr.Info("webcam_image get")
    else:
        gr.Info("no webcam_image")
    return webcam_image

def main():
    with gr.Blocks() as demo:
        webcam = gr.Image(sources=["webcam"], height=300, streaming=True)
        img = gr.Image()
        button = gr.Button("Start!")
        button.click(echo, inputs=[webcam], outputs=[img], every=5)
    demo.launch(server_name="0.0.0.0")
    demo.queue()

if __name__ == "__main__":
    main()

Screenshot

image

Logs

No response

System Info

Gradio Environment Information: 
------------------------------
Operating System: Linux
gradio version: 4.32.2
gradio_client version: 0.17.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.3.0
fastapi: 0.110.2
ffmpy: 0.3.2
gradio-client==0.17.0 is not installed.
httpx: 0.27.0
huggingface-hub: 0.22.2
importlib-resources: 6.4.0
jinja2: 3.0.3
markupsafe: 2.1.2
matplotlib: 3.7.1
numpy: 1.24.4
orjson: 3.10.1
packaging: 23.1
pandas: 2.0.1
pillow: 9.5.0
pydantic: 2.7.1
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 5.4.1
ruff: 0.4.1
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.3
typing-extensions: 4.11.0
urllib3: 2.2.1
uvicorn: 0.29.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.3.1
httpx: 0.27.0
huggingface-hub: 0.22.2
packaging: 23.1
typing-extensions: 4.11.0
websockets: 11.0.3

Severity

Blocking usage of gradio