gradio icon indicating copy to clipboard operation
gradio copied to clipboard

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

Open dogevspenguin opened this issue 1 year ago • 8 comments

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? 🔎

  • [X] I have searched and found no 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

dogevspenguin avatar Aug 23 '24 05:08 dogevspenguin

This is also an issue for me!

robwsinnott avatar Aug 26 '24 13:08 robwsinnott

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

Itto1992 avatar Aug 30 '24 06:08 Itto1992

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

Itto1992 avatar Aug 30 '24 06:08 Itto1992

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

ukaprch avatar Sep 01 '24 13:09 ukaprch

Any update?

Prgckwb avatar Sep 19 '24 15:09 Prgckwb

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

p890040 avatar Sep 21 '24 07:09 p890040

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

freddyaboulton avatar Sep 26 '24 18:09 freddyaboulton

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

thinkthinking avatar Oct 16 '24 05:10 thinkthinking