Skip to content

Commit

Permalink
Gradio has a bug where an image change triggers twice. see
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Roel Kluin committed Jul 22, 2023
1 parent e7489cd commit 5807cf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tagger/interrogator.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Interrogator:
"output_dir": '',
}
output = None
# odd_increment = 0
odd_increment = 0

@classmethod
def flip(cls, key):
Expand Down
22 changes: 13 additions & 9 deletions tagger/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ def on_gallery() -> List:
return QData.get_image_dups()


def on_interrogate_image(
image: Image, name: str, filt: str, *args
) -> COMMON_OUTPUT:
def on_interrogate_image(*args) -> COMMON_OUTPUT:
# hack brcause image interrogaion occurs twice
# It.odd_increment = It.odd_increment + 1
# if It.odd_increment & 1 == 1:
# return (None, None, None, None, None, '')
It.odd_increment = It.odd_increment + 1
if It.odd_increment & 1 == 1:
return (None, None, None, None, None, '')
return on_interrogate_image_submit(*args)

def on_interrogate_image_submit(
image: Image, name: str, filt: str, *args
) -> COMMON_OUTPUT:
for i, val in enumerate(args):
part = TAG_INPUTS[i]
if val != It.input[part]:
Expand Down Expand Up @@ -453,9 +455,11 @@ def refresh():
[tag_input[tag] for tag in TAG_INPUTS]

# interrogation events
for func in [image.change, image_submit.click]:
func(fn=wrap_gradio_gpu_call(on_interrogate_image),
inputs=[image] + common_input, outputs=common_output)
image_submit.click(fn=wrap_gradio_gpu_call(on_interrogate_image_submit),
inputs=[image] + common_input, outputs=common_output)

image.change(fn=wrap_gradio_gpu_call(on_interrogate_image),
inputs=[image] + common_input, outputs=common_output)

batch_submit.click(fn=wrap_gradio_gpu_call(on_interrogate),
inputs=[input_glob, output_dir] + common_input,
Expand Down

0 comments on commit 5807cf5

Please sign in to comment.