Skip to content

Commit

Permalink
🔧 Add option to disable photopea quick edit (#2385)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Jan 2, 2024
1 parent ce3cb3d commit d47536f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions javascript/photopea.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@
function loadPhotopea() {
function registerCallbacks(accordion) {
const photopeaMainTrigger = accordion.querySelector('.cnet-photopea-main-trigger');
// Photopea edit feature disabled.
if (!photopeaMainTrigger) {
console.log("ControlNet photopea edit disabled.");
return;
}

const closeModalButton = accordion.querySelector('.cnet-photopea-edit .cnet-modal-close');
const tabs = accordion.querySelectorAll('.cnet-unit-tab');
const photopeaWindow = accordion.querySelector('.photopea-iframe').contentWindow;
Expand Down
7 changes: 5 additions & 2 deletions scripts/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def get_default_ui_unit(is_ui=True):
model="None"
)

def uigroup(self, tabname: str, is_img2img: bool, elem_id_tabname: str, photopea: Photopea) -> Tuple[ControlNetUiGroup, gr.State]:
def uigroup(self, tabname: str, is_img2img: bool, elem_id_tabname: str, photopea: Optional[Photopea]) -> Tuple[ControlNetUiGroup, gr.State]:
group = ControlNetUiGroup(
Script.get_default_ui_unit(),
self.preprocessor,
Expand Down Expand Up @@ -322,7 +322,7 @@ def ui(self, is_img2img):
elem_id_tabname = ("img2img" if is_img2img else "txt2img") + "_controlnet"
with gr.Group(elem_id=elem_id_tabname):
with gr.Accordion(f"ControlNet {controlnet_version.version_flag}", open = False, elem_id="controlnet"):
photopea = Photopea()
photopea = Photopea() if not shared.opts.data.get("controlnet_disable_photopea_edit", False) else None
if max_models > 1:
with gr.Tabs(elem_id=f"{elem_id_tabname}_tabs"):
for i in range(max_models):
Expand Down Expand Up @@ -686,6 +686,7 @@ def bound_check_params(unit: external_code.ControlNetUnit) -> None:
setattr(unit, param, default_value)
logger.warning(f'[{unit.module}.{param}] Invalid value({value}), using default value {default_value}.')

@staticmethod
def check_sd_version_compatible(unit: external_code.ControlNetUnit) -> None:
"""
Checks whether the given ControlNet unit has model compatible with the currently
Expand Down Expand Up @@ -1228,6 +1229,8 @@ def on_ui_settings():
False, "Increment seed after each controlnet batch iteration", gr.Checkbox, {"interactive": True}, section=section))
shared.opts.add_option("controlnet_disable_openpose_edit", shared.OptionInfo(
False, "Disable openpose edit", gr.Checkbox, {"interactive": True}, section=section))
shared.opts.add_option("controlnet_disable_photopea_edit", shared.OptionInfo(
False, "Disable photopea edit", gr.Checkbox, {"interactive": True}, section=section))
shared.opts.add_option("controlnet_ignore_noninpaint_mask", shared.OptionInfo(
False, "Ignore mask on ControlNet input image if control type is not inpaint",
gr.Checkbox, {"interactive": True}, section=section))
Expand Down
8 changes: 5 additions & 3 deletions scripts/controlnet_ui/controlnet_ui_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(
self,
default_unit: external_code.ControlNetUnit,
preprocessors: List[Callable],
photopea: Photopea,
photopea: Optional[Photopea],
):
self.default_unit = default_unit
self.preprocessors = preprocessors
Expand Down Expand Up @@ -217,7 +217,8 @@ def render(self, tabname: str, elem_id_tabname: str, is_img2img: bool) -> None:
with gr.Group(
elem_classes=["cnet-generated-image-control-group"]
):
self.photopea.render_child_trigger()
if self.photopea:
self.photopea.render_child_trigger()
self.openpose_editor.render_edit()
preview_check_elem_id = f"{elem_id_tabname}_{tabname}_controlnet_preprocessor_preview_checkbox"
preview_close_button_js = f"document.querySelector('#{preview_check_elem_id} input[type=\\'checkbox\\']').click();"
Expand All @@ -234,7 +235,8 @@ def render(self, tabname: str, elem_id_tabname: str, is_img2img: bool) -> None:
elem_id=f"{elem_id_tabname}_{tabname}_batch_image_dir",
)

self.photopea.attach_photopea_output(self.generated_image)
if self.photopea:
self.photopea.attach_photopea_output(self.generated_image)

with gr.Accordion(
label="Open New Canvas", visible=False
Expand Down

0 comments on commit d47536f

Please sign in to comment.