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.72k stars 2.56k forks source link

Can't trigger `.select()` function of `gr.Image` #9182

Closed dogevspenguin closed 2 weeks ago

dogevspenguin commented 2 months ago

Describe the bug

I created this code, And it worked for sometime, until today,at which point it broke, Where as before, hovering over an image displays an aiming crosshair, Now, the default cursor is visible instead, Any click does not get registered, and printing does not work, However, there is no crash, no error, no freezing as other function still works fine, Even the gradio demo for img.select() is broken

Have you searched existing issues? 🔎

Reproduction

import gradio as gr
import numpy as np
#from Modules import calcs
# Global list to store clicked points
clicked_points = []
def draw_circle_on_img(img, center, radius=10, color=[255, 0, 0]):
    """Draw a circle on the image with the given radius and color."""
    y, x = center
    height, width, _ = img.shape
    rr, cc = np.ogrid[:height, :width]
    dist = (rr - y) ** 2 + (cc - x) ** 2
    mask = dist <= radius ** 2
    img[mask] = color
    return img

def get_click_coords(img, evt: gr.SelectData):
    print("CLICKED")
    global clicked_points
    out = img.copy()
    if len(clicked_points) < 5:
        clicked_points.append((evt.index[0], evt.index[1]))

        # Draw a circle around each clicked point
        for x, y in clicked_points:
            out = draw_circle_on_img(out, (y, x), radius=4, color=[0, 255, 255])  # Red color for circles

        # Return the updated image for both input and output
    return out,img
def reset(img):
    print("RESET")
    global clicked_points
    clicked_points = []
    return img, img

with gr.Blocks() as demo:
    with gr.Row():
        input_img = gr.Image(label="Input", type="numpy")
        #output_img = gr.Image(label="Image with Clicks", type="numpy")
        # Function to handle click events and update both images
        input_img.select(get_click_coords, [input_img], [input_img, input_img])
        input_img.upload(reset, [input_img], [input_img, input_img])

if __name__ == "__main__":
    demo.launch()

Screenshot

No response

Logs

None

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 4.42.0
gradio_client version: 1.3.0

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

aiofiles: 23.2.1
anyio: 4.4.0
fastapi: 0.112.1
ffmpy: 0.4.0
gradio-client==1.3.0 is not installed.
httpx: 0.27.0
huggingface-hub: 0.24.6
importlib-resources: 6.4.4
jinja2: 3.1.4
markupsafe: 2.1.5
matplotlib: 3.9.2
numpy: 2.1.0
orjson: 3.10.7
packaging: 24.1
pandas: 2.2.2
pillow: 10.4.0
pydantic: 2.8.2
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.2
ruff: 0.6.2
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.4
typing-extensions: 4.12.2
urllib3: 2.2.2
uvicorn: 0.30.6
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.6.1
httpx: 0.27.0
huggingface-hub: 0.24.6
packaging: 24.1
typing-extensions: 4.12.2
websockets: 12.0

Severity

Blocking usage of gradio

robwsinnott commented 2 months ago

This is also an issue for me!

Itto1992 commented 2 months ago

Thank you for creating this issue. I am also in this trouble.

Itto1992 commented 2 months ago

It seems this bug is occurred when I use the latest version: v4.42.0 I downgraded the version to v4.41.0, then the problem was solved

ukaprch commented 2 months ago

Thank you for creating this issue. I am also in this trouble. I downgraded the version to v4.41.0, then the problem was solved

Prgckwb commented 1 month ago

Any update?

p890040 commented 1 month ago

This is a critical issue. It's means image.select is broken in recent version. Any update?

freddyaboulton commented 1 month ago

We let this slip through. Someone from the team can pick this up but contributions welcome!!

thinkthinking commented 2 weeks ago

gradio v4.40.0 work gradio v5.x doesn't work