From 560e5a86e37c467ef44088baf82a96b23673dbf7 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 13 Jan 2024 08:44:23 -0500 Subject: [PATCH] handle en tags with same names as en itself --- extensions-builtin/sd-webui-controlnet | 2 +- javascript/extraNetworks.js | 14 +++++++++++--- modules/processing.py | 8 ++++++-- modules/shared.py | 14 +++++++------- wiki | 2 +- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/extensions-builtin/sd-webui-controlnet b/extensions-builtin/sd-webui-controlnet index d56f1b8bc..4729f8eb0 160000 --- a/extensions-builtin/sd-webui-controlnet +++ b/extensions-builtin/sd-webui-controlnet @@ -1 +1 @@ -Subproject commit d56f1b8bcb55df12bccbe36b7de66d476f23db1c +Subproject commit 4729f8eb075944b2420218e0e0c4d47829a1af85 diff --git a/javascript/extraNetworks.js b/javascript/extraNetworks.js index 88aadacd3..674eafa17 100644 --- a/javascript/extraNetworks.js +++ b/javascript/extraNetworks.js @@ -61,15 +61,23 @@ function getCardDetails(...args) { } function readCardTags(el, tags) { + const replaceOutsideBrackets = (input, target, replacement) => input.split(/(<[^>]*>|\{[^}]*\})/g).map((part, i) => { + if (i % 2 === 0) return part.split(target).join(replacement); // Only replace in the parts that are not inside brackets (which are at even indices) + return part; + }).join(''); + const clickTag = (e, tag) => { e.preventDefault(); e.stopPropagation(); const textarea = activePromptTextarea[getENActiveTab()]; - if (textarea.value.indexOf(` ${tag}`) !== -1) textarea.value = textarea.value.replace(` ${tag}`, ''); - else if (textarea.value.indexOf(`${tag} `) !== -1) textarea.value = textarea.value.replace(` ${tag} `, ''); - else textarea.value += ` ${tag}`; + let new_prompt = textarea.value; + new_prompt = replaceOutsideBrackets(new_prompt, ` ${tag}`, ''); // try to remove tag + new_prompt = replaceOutsideBrackets(new_prompt, `${tag} `, ''); + if (new_prompt === textarea.value) new_prompt += ` ${tag}`; // if not removed, then append it + textarea.value = new_prompt; updateInput(textarea); }; + if (tags.length === 0) return; const cardTags = tags.split('|'); if (!cardTags || cardTags.length === 0) return; diff --git a/modules/processing.py b/modules/processing.py index c9eeb69e4..7a0cd8525 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -55,8 +55,12 @@ def setup_color_correction(image): def apply_color_correction(correction, original_image): - shared.log.debug(f"Applying color correction: correction={correction} image={original_image}") - image = Image.fromarray(cv2.cvtColor(exposure.match_histograms(cv2.cvtColor(np.asarray(original_image), cv2.COLOR_RGB2LAB), correction, channel_axis=2), cv2.COLOR_LAB2RGB).astype("uint8")) + shared.log.debug(f"Applying color correction: correction={correction.shape} image={original_image}") + np_image = np.asarray(original_image) + np_recolor = cv2.cvtColor(np_image, cv2.COLOR_RGB2LAB) + np_match = exposure.match_histograms(np_recolor, correction, channel_axis=2) + np_output = cv2.cvtColor(np_match, cv2.COLOR_LAB2RGB) + image = Image.fromarray(np_output.astype("uint8")) image = blendLayers(image, original_image, BlendType.LUMINOSITY) return image diff --git a/modules/shared.py b/modules/shared.py index c9266f464..1e5b86ac5 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -173,7 +173,7 @@ if cmd_opts.backend is not None: # override with args backend = Backend.DIFFUSERS if cmd_opts.backend.lower() == 'diffusers' else Backend.ORIGINAL if cmd_opts.use_openvino: # override for openvino backend = Backend.DIFFUSERS - from modules.intel.openvino import get_device_list as get_openvino_device_list + from modules.intel.openvino import get_device_list as get_openvino_device_list # pylint: disable=ungrouped-imports class OptionInfo: @@ -462,12 +462,12 @@ options_templates.update(options_section(('saving-images', "Image Options"), { "font_color": OptionInfo("#FFFFFF", "Font color", ui_components.FormColorPicker, {}), "save_sep_options": OptionInfo("

Intermediate Image Saving

", "", gr.HTML), - "save_init_img": OptionInfo(False, "Save img2img init images"), - "save_images_before_highres_fix": OptionInfo(False, "Save image before applying hires"), - "save_images_before_refiner": OptionInfo(False, "Save image before running refiner"), - "save_images_before_face_restoration": OptionInfo(False, "Save image before doing face restoration"), - "save_images_before_color_correction": OptionInfo(False, "Save image before applying color correction"), - "save_mask": OptionInfo(False, "Save the inpainting greyscale mask"), + "save_init_img": OptionInfo(False, "Save init images"), + "save_images_before_highres_fix": OptionInfo(False, "Save image before hires"), + "save_images_before_refiner": OptionInfo(False, "Save image before refiner"), + "save_images_before_face_restoration": OptionInfo(False, "Save image before face restoration"), + "save_images_before_color_correction": OptionInfo(False, "Save image before color correction"), + "save_mask": OptionInfo(False, "Save inpainting mask"), "save_mask_composite": OptionInfo(False, "Save inpainting masked composite"), })) diff --git a/wiki b/wiki index 973a5b0fc..4142109ce 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 973a5b0fc10c962215550ba2d5734fe2ec91fd0b +Subproject commit 4142109ce176271d0bda3d31686213d94adf3f10