Skip to content

Commit

Permalink
smart preview management, remove preview as inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
lllyasviel committed Aug 22, 2023
1 parent e62411d commit f75e0ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 31 additions & 1 deletion scripts/controlnet_ui/controlnet_ui_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def shift_preview(is_on):
# generated_image_group
gr.update(visible=is_on),
# use_preview_as_input,
gr.update(visible=is_on),
gr.update(visible=False), # Now this is automatically managed
# download_pose_link
gr.update() if is_on else gr.update(value=None),
# modal edit button
Expand Down Expand Up @@ -822,6 +822,36 @@ def render_and_register_unit(self, tabname: str, is_img2img: bool):
fn=UiControlNetUnit, inputs=list(unit_args), outputs=unit
)

def clear_preview(x):
if x:
logger.info('Preview as input is cancelled.')
return gr.update(value=False), gr.update(value=None)

for comp in (
self.pixel_perfect,
self.module,
self.input_image,
self.processor_res,
self.threshold_a,
self.threshold_b,
):
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=clear_preview, inputs=self.use_preview_as_input, outputs=[self.use_preview_as_input,
self.generated_image]
)

# keep input_mode in sync
def ui_controlnet_unit_for_input_mode(input_mode, *args):
args = list(args)
Expand Down
2 changes: 2 additions & 0 deletions scripts/controlnet_ui/openpose_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from annotator.openpose import decode_json_as_poses, draw_poses
from scripts.controlnet_ui.modal import ModalInterface
from modules import shared
from scripts.logging import logger


def parse_data_url(data_url: str):
Expand Down Expand Up @@ -63,6 +64,7 @@ def register_callbacks(
def render_pose(pose_url: str) -> Tuple[Dict, Dict]:
json_string = parse_data_url(pose_url)
poses, height, weight = decode_json_as_poses(json_string)
logger.info('Preview as input is enabled.')
return (
# Generated image.
gr.update(
Expand Down

0 comments on commit f75e0ea

Please sign in to comment.