Restore unit state update listeners (#2888)

pull/2891/head
Chenlei Hu 2024-05-13 21:07:50 -04:00 committed by GitHub
parent 3b4eedd90f
commit 5d7529915b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 0 deletions

View File

@ -667,6 +667,29 @@ class ControlNetUiGroup(object):
)
unit = gr.State(ControlNetUnit())
# It is necessary to update unit state actively to avoid potential
# flaky racing issue.
# https://github.com/Mikubill/sd-webui-controlnet/issues/2875
for comp in unit_args + (self.update_unit_counter,):
event_subscribers = []
if hasattr(comp, "edit"):
event_subscribers.append(comp.edit)
elif hasattr(comp, "click"):
event_subscribers.append(comp.click)
elif isinstance(comp, gr.Slider) and hasattr(comp, "release"):
event_subscribers.append(comp.release)
elif hasattr(comp, "change"):
event_subscribers.append(comp.change)
if hasattr(comp, "clear"):
event_subscribers.append(comp.clear)
for event_subscriber in event_subscribers:
event_subscriber(
fn=create_ui_unit, inputs=list(unit_args), outputs=unit
)
(
ControlNetUiGroup.a1111_context.img2img_submit_button
if self.is_img2img