mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-05-01 03:31:21 +00:00
fix: find controlnet with modules.extensions
This commit is contained in:
@@ -1 +1 @@
|
|||||||
__version__ = "23.6.0"
|
__version__ = "23.6.1.dev0"
|
||||||
|
|||||||
@@ -5,28 +5,23 @@ import re
|
|||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from modules import sd_models, shared
|
from modules import extensions, sd_models, shared
|
||||||
from modules.paths import data_path, models_path, script_path
|
from modules.paths import data_path, models_path, script_path
|
||||||
|
|
||||||
ext_path = Path(data_path, "extensions")
|
ext_path = Path(data_path, "extensions")
|
||||||
ext_builtin_path = Path(script_path, "extensions-builtin")
|
ext_builtin_path = Path(script_path, "extensions-builtin")
|
||||||
is_in_builtin = False # compatibility for vladmandic/automatic
|
|
||||||
controlnet_exists = False
|
controlnet_exists = False
|
||||||
|
controlnet_path = None
|
||||||
|
cn_base_path = ""
|
||||||
|
|
||||||
if ext_path.exists():
|
for extension in extensions.active():
|
||||||
controlnet_exists = any(
|
if not extension.enabled:
|
||||||
p.name == "sd-webui-controlnet" for p in ext_path.iterdir() if p.is_dir()
|
continue
|
||||||
)
|
# For cases like sd-webui-controlnet-master
|
||||||
|
if "sd-webui-controlnet" in extension.name:
|
||||||
if not controlnet_exists and ext_builtin_path.exists():
|
controlnet_exists = True
|
||||||
controlnet_exists = any(
|
controlnet_path = Path(extension.path)
|
||||||
p.name == "sd-webui-controlnet"
|
cn_base_path = ".".join(controlnet_path.parts[-2:])
|
||||||
for p in ext_builtin_path.iterdir()
|
|
||||||
if p.is_dir()
|
|
||||||
)
|
|
||||||
|
|
||||||
if controlnet_exists:
|
|
||||||
is_in_builtin = True
|
|
||||||
|
|
||||||
cn_model_module = {
|
cn_model_module = {
|
||||||
"inpaint": "inpaint_global_harmonious",
|
"inpaint": "inpaint_global_harmonious",
|
||||||
@@ -45,10 +40,7 @@ class ControlNetExt:
|
|||||||
self.external_cn = None
|
self.external_cn = None
|
||||||
|
|
||||||
def init_controlnet(self):
|
def init_controlnet(self):
|
||||||
if is_in_builtin:
|
import_path = cn_base_path + ".scripts.external_code"
|
||||||
import_path = "extensions-builtin.sd-webui-controlnet.scripts.external_code"
|
|
||||||
else:
|
|
||||||
import_path = "extensions.sd-webui-controlnet.scripts.external_code"
|
|
||||||
|
|
||||||
self.external_cn = importlib.import_module(import_path, "external_code")
|
self.external_cn = importlib.import_module(import_path, "external_code")
|
||||||
self.cn_available = True
|
self.cn_available = True
|
||||||
@@ -84,15 +76,15 @@ class ControlNetExt:
|
|||||||
|
|
||||||
def get_cn_model_dirs() -> list[Path]:
|
def get_cn_model_dirs() -> list[Path]:
|
||||||
cn_model_dir = Path(models_path, "ControlNet")
|
cn_model_dir = Path(models_path, "ControlNet")
|
||||||
if is_in_builtin:
|
if controlnet_path is not None:
|
||||||
cn_model_dir_old = Path(ext_builtin_path, "sd-webui-controlnet", "models")
|
cn_model_dir_old = controlnet_path.joinpath("models")
|
||||||
else:
|
else:
|
||||||
cn_model_dir_old = Path(ext_path, "sd-webui-controlnet", "models")
|
cn_model_dir_old = None
|
||||||
ext_dir1 = shared.opts.data.get("control_net_models_path", "")
|
ext_dir1 = shared.opts.data.get("control_net_models_path", "")
|
||||||
ext_dir2 = shared.opts.data.get("controlnet_dir", "")
|
ext_dir2 = shared.opts.data.get("controlnet_dir", "")
|
||||||
|
|
||||||
dirs = [cn_model_dir, cn_model_dir_old]
|
dirs = [cn_model_dir]
|
||||||
for ext_dir in [ext_dir1, ext_dir2]:
|
for ext_dir in [cn_model_dir_old, ext_dir1, ext_dir2]:
|
||||||
if ext_dir:
|
if ext_dir:
|
||||||
dirs.append(Path(ext_dir))
|
dirs.append(Path(ext_dir))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user