sd-webui-controlnet icon indicating copy to clipboard operation
sd-webui-controlnet copied to clipboard

Request] Disable ControlNet while running another script (in webUI)

Open tkgix opened this issue 1 year ago • 10 comments

Thank you for your hard work.

Please add one variable that can disable ControlNet while running another Script.

Previously, "ControlNet" was not applied as code that temporarily removes "ControlNet.py " from "alwaysson_scripts" or "scripts" from the Processing Param content while running other scripts. Now, this trick is not possible.

If possible, could you add variables to control the activation/deactivation of ControlNet in other scripts....?

I'm using Script to handle complex bulk tasks, but I need a procedure that applies ControlNet only to the first task and not to apply ControlNet after that.

Please consider it.

tkgix avatar Feb 28 '24 02:02 tkgix

I am not sure if I understand you correctly. You are developing another script (A1111 extension) that does bulk generation. In that script, you want to control the units enabled? If that is the case, you can refer to implementation in https://github.com/Bing-su/adetailer.

huchenlei avatar Feb 28 '24 04:02 huchenlei

Thank you for your answer, I think maybe what you understood is correct.

I want to apply ControlNet when running t2i or i2i, and then disable ControlNet while running additional tasks by Script.

tkgix avatar Feb 28 '24 04:02 tkgix

I looked at the Adetailer. I understood that it was replacing it with another ControlNet parameter, but I couldn't find the Turn Off ControlNet. I tried to implement it similarly, but after the ControlNet is applied in the first stage of T2I or i2i and the image is completed normally, it is transformed into a broken image while another Script is running. Your help would be greatly appreciated.

tkgix avatar Feb 28 '24 04:02 tkgix

You can look at impl here: https://github.com/Bing-su/adetailer/blob/8f01dfdaa9796108f0af16974edc732fe96d7231/controlnet_ext/controlnet_ext.py#L70-L108

ControlNetUnit accepts an arg enabled to control whether the unit is enabled or not.

huchenlei avatar Feb 28 '24 05:02 huchenlei

You can look at impl here: https://github.com/Bing-su/adetailer/blob/8f01dfdaa9796108f0af16974edc732fe96d7231/controlnet_ext/controlnet_ext.py#L70-L108

ControlNetUnit accepts an arg enabled to control whether the unit is enabled or not.

Thank you. I'll give it a try.

tkgix avatar Feb 28 '24 05:02 tkgix

1 2

Hmm... It's hard.

I would like to perform the following procedure with SCRIPT.

  1. Apply ControlNet to run i2i ( Image 1 )
  2. Disable ControlNet
  3. UPSCALE 1.5X image created as number 1
  4. Run i2i again using a different prompt ( Image 2 )

The first image is the image that generated T2I by applying ControlNet. The second image is the image created in the fourth step.

I don't know why, but upscale is not applied and the image is broken. (Once you turn off ControlNet from the UI, it works fine) The code executed in step 2 is as follows. Can I get some advice?

=======================================

import importlib from modules import extensions from modules.paths import extensions_builtin_dir, extensions_dir, models_path

class CNControler: def init(self): self.ext_path = Path(extensions_dir) self.ext_builtin_path = Path(extensions_builtin_dir) self.controlnet_exists = False self.controlnet_path = None self.cn_base_path = ""

    for extension in extensions.active():
        if not extension.enabled:
            continue
        # For cases like sd-webui-controlnet-master
        if "sd-webui-controlnet" in extension.name:
            self.controlnet_exists = True
            self.controlnet_path = Path(extension.path)
            self.cn_base_path = ".".join(self.controlnet_path.parts[-2:])
            break

    if self.controlnet_path is not None:
        sd_webui_controlnet_path = self.controlnet_path.resolve().parent
        if sd_webui_controlnet_path.stem in ("extensions", "extensions-builtin"):
            target_path = str(sd_webui_controlnet_path.parent)
            if target_path not in sys.path:
                sys.path.append(target_path)

    self.import_path = self.cn_base_path + ".scripts.external_code"
    self.external_cn = importlib.import_module(self.import_path, "external_code")

def Disable(self, p):
    cn_units = [ self.external_cn.ControlNetUnit( enabled=False ) ]
    self.external_cn.update_cn_script_in_processing(p, cn_units)

tkgix avatar Feb 28 '24 05:02 tkgix

If your use case is that simple, you can actually just call web api, instead of messing with A1111 extension. https://github.com/Mikubill/sd-webui-controlnet/wiki/API

huchenlei avatar Feb 28 '24 05:02 huchenlei

If your use case is that simple, you can actually just call web api, instead of messing with A1111 extension. https://github.com/Mikubill/sd-webui-controlnet/wiki/API

Thank you. But, The above example is intended to explain the current situation.

tkgix avatar Feb 28 '24 06:02 tkgix

I'm using a script that goes through complicated processes, but I need to disable ControlNet during this process. Is there anything I can do?

tkgix avatar Feb 28 '24 06:02 tkgix

The first image is the image that generated T2I by applying ControlNet. The second image is the image created in the fourth step.

I don't know why, but upscale is not applied and the image is broken. (Once you turn off ControlNet from the UI, it works f

That actually looks like the internal emphasis normalization in a1111 is the one messing with you on the fourth step. Are you perhaps using either PonyDiffusionXL_v6 or AnimagineXL_3.0 or 3.1? In settings open the Stable Diffusion section located between Sampler Parameters and Stable Diffusion XL section. In set it to same as within the red box in image msedge_UlDxFDbPyk

silveroxides avatar Apr 10 '24 07:04 silveroxides