Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image.change event is triggered twice since 3.31.0 #4589

Closed
1 task done
nqdeng opened this issue Jun 21, 2023 · 5 comments 路 Fixed by #4793
Closed
1 task done

Image.change event is triggered twice since 3.31.0 #4589

nqdeng opened this issue Jun 21, 2023 · 5 comments 路 Fixed by #4793
Assignees
Labels
bug Something isn't working

Comments

@nqdeng
Copy link

nqdeng commented Jun 21, 2023

Describe the bug

Before 3.31.0, Image.change event is only triggered once by a function update, But since 3.31.0, the event is triggered twice.

Have you searched existing issues? 馃攷

  • I have searched and found no existing issues

Reproduction

import gradio as gr

def onchange(image):
    print(image)

block = gr.Blocks().queue()

with block:
    temp = gr.Image(source='upload', type='pil')
    image = gr.Image(source='upload', type='pil')
    temp.change(onchange, inputs=[temp])
    image.upload(lambda x:x, inputs=[image], outputs=[temp])

block.launch(server_name='0.0.0.0', server_port=5000)

After the service is started, you could click the second Image control to upload an image, and will see the following logs:

Running on local URL:  http://0.0.0.0:5000

To create a public link, set `share=True` in `launch()`.
<PIL.Image.Image image mode=RGB size=512x512 at 0x1628DF070>
<PIL.Image.Image image mode=RGB size=512x512 at 0x162B1EF80>

This issue only happens when gradio version >= 3.31.0, 3.30.0 and below are fine to me.

Screenshot

No response

Logs

No response

System Info

gradio>=3.31.0
MacOS 13.3.1
Chrome 113.0.5672.126

Severity

Blocking usage of gradio

@nqdeng nqdeng added the bug Something isn't working label Jun 21, 2023
@picobyte
Copy link

picobyte commented Jun 21, 2023

I've come across this issue as well. in my branch of stable-diffusion-webui-wd14-tagger I circumvented every first callback using:

def on_interrogate_image_change(*args):
    # FIXME for some reason an image change is triggered twice.
    # this is a dirty hack to prevent summation/flushing the output.
    print("interrogator: "+args[1])
    It.image_counter += 1
    if It.image_counter & 1 == 0:
        return It.results()
    return on_interrogate_image(*args)


def on_interrogate_image(image: Image, interrogator: str, unload_after: bool):
    if image is None:
        return [None, None, None, 'No image']

    if interrogator not in utils.interrogators:
        return [None, None, None, f"'{interrogator}': invalid interrogator"]

    interrogator: It = utils.interrogators[interrogator]
    return interrogator.interrogate_image(image, unload_after)

@freddyaboulton
Copy link
Collaborator

Thanks for filing @nqdeng and for posting the workaround @picobyte . Going to look into this.

@freddyaboulton freddyaboulton self-assigned this Jun 21, 2023
@picobyte
Copy link

picobyte commented Jul 1, 2023

Was the issue resolved? I rewrote my code a bit and now no longer seem to have the issue.

@abidlabs
Copy link
Member

abidlabs commented Jul 5, 2023

This issue is not resolved on main as far as I can tell. Just tested with a very simple demo:

import gradio as gr

def test(x):
    print("change called")
    return x

with gr.Blocks() as demo:
    a = gr.Image()
    b = gr.Image()
    
    a.change(test, a, b)
    
demo.launch()

I'm tackling the analogous issue for Video so lmk if I should take this as well @freddyaboulton

@freddyaboulton
Copy link
Collaborator

Feel free to take @abidlabs ! I have not started on this yet

@abidlabs abidlabs added this to the Component Cleanup milestone Jul 9, 2023
picobyte pushed a commit to picobyte/stable-diffusion-webui-wd14-tagger that referenced this issue Jul 22, 2023
gradio-app/gradio#4589

It was recently fixed, but gradio 3.32, required by webui, does not have
the change yet.

For a while I didn't seem to have the effects, but it still occurs, and I
it causes thresholds not to be adhered to, e.g. in ML interrogations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants