Skip to content

Commit

Permalink
smart preview management, remove preview as inputs (#1944)
Browse files Browse the repository at this point in the history
* smart preview management, remove preview as inputs

* smart preview management, remove preview as inputs
  • Loading branch information
lllyasviel authored Aug 22, 2023
1 parent ab42c2d commit 36b3cfb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion scripts/controlnet_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_flag = 'v1.1.304'
version_flag = 'v1.1.305'

from scripts.logging import logger

Expand Down

0 comments on commit 36b3cfb

Please sign in to comment.