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.48k stars 2.43k forks source link

gradio.image events has a strange behavior using the past option #8269

Open marcoquin opened 4 months ago

marcoquin commented 4 months ago

Describe the bug

Hi, thanks so much for your work on Gradio. I am using gradio.image with two distinct events, image.upload to detect when an image is provide and image.clear to detect when it is clear. However, I have an issue with the past option. Indeed, I realise that when you past an image (cf the screenshot) image both the event image.upload and image.clear are triggered. I checked the documentation (https://www.gradio.app/docs/gradio/image) and the image.clear event as described in the doc should't be triggered as no user used the X button of the component. image

It really block me for my work. Could it be possible to clean this behaviour? The best would be to create a image.past event that is only triggered when you past an image, and change the behavior of image.upload (making it only being triggered by the upload option) and image.clear (only triggered when a real clear is made)

Have you searched existing issues? 🔎

Reproduction

import gradio as gr

with gr.Blocks() as io:
    title = gr.Markdown("1")
    image = gr.Image(
        show_download_button=True,
        type="filepath",
        elem_id="imagebox",
    )

    image.upload(
        fn=(lambda image: print("Upload triggered!")),
        inputs=[image],
        outputs=[],
    ).then(
        fn=(lambda image: print("Upload complete!")),
        inputs=[image],
        outputs=[],
    )
    image.clear(
        fn=(lambda image: print("Clear triggered!")),
        inputs=[image],
        outputs=[],
    ).then(
        fn=(lambda image: print("Clear complete!")),
        inputs=[image],
        outputs=[],
    )

io.launch()

A really simple code to show in logs that when you past an image, both the clear and upload event are triggered. (I use python 3.11.0)

Screenshot

No response

Logs

No response

System Info

result of a pip freeze
aiofiles==23.2.1
altair==5.3.0
annotated-types==0.6.0
anyio==4.3.0
attrs==23.2.0
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
contourpy==1.2.1
cycler==0.12.1
fastapi==0.110.1
ffmpy==0.3.2
filelock==3.13.4
fonttools==4.51.0
fsspec==2024.3.1
gradio==4.29.0
gradio_client==0.16.1
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
huggingface-hub==0.22.2
idna==3.7
importlib_resources==6.4.0
Jinja2==3.1.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
kiwisolver==1.4.5
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.8.4
mdurl==0.1.2
numpy==1.26.4
orjson==3.10.1
packaging==24.0
pandas==2.2.2
pillow==10.3.0
pydantic==2.7.0
pydantic_core==2.18.1
pydub==0.25.1
Pygments==2.17.2
pyparsing==3.1.2
python-dateutil==2.9.0.post0
python-multipart==0.0.9
pytz==2024.1
PyYAML==6.0.1
referencing==0.34.0
requests==2.31.0
rich==13.7.1
rpds-py==0.18.0
ruff==0.3.7
semantic-version==2.10.0
shellingham==1.5.4
six==1.16.0
sniffio==1.3.1
starlette==0.37.2
tomlkit==0.12.0
toolz==0.12.1
tqdm==4.66.2
typer==0.12.3
typing_extensions==4.11.0
tzdata==2024.1
urllib3==2.2.1
uvicorn==0.29.0
websockets==11.0.3

Severity

Blocking usage of gradio

pngwn commented 4 months ago

This is definitely a bug, we'll take a look as soon as we can.