feat: extra models path option

This commit is contained in:
Dowon
2023-10-21 16:52:07 +09:00
parent 6832136581
commit cebd492613
2 changed files with 23 additions and 12 deletions

View File

@@ -36,18 +36,16 @@ def hf_download(file: str):
return path
def scan_model_dir(path_: str | Path) -> list[Path]:
if not path_ or not (path := Path(path_)).is_dir():
return []
return [p for p in path.rglob("*") if p.is_file() and p.suffix in (".pt", ".pth")]
def get_models(
model_dir: Union[str, Path], huggingface: bool = True
) -> OrderedDict[str, Optional[str]]:
model_dir = Path(model_dir)
if model_dir.is_dir():
model_paths = [
p
for p in model_dir.rglob("*")
if p.is_file() and p.suffix in (".pt", ".pth")
]
else:
model_paths = []
model_dir: str | Path, extra_dir: str | Path = "", huggingface: bool = True
) -> OrderedDict[str, str | None]:
model_paths = [*scan_model_dir(model_dir), *scan_model_dir(extra_dir)]
models = OrderedDict()
if huggingface:

View File

@@ -53,7 +53,10 @@ from modules.shared import cmd_opts, opts, state
no_huggingface = getattr(cmd_opts, "ad_no_huggingface", False)
adetailer_dir = Path(models_path, "adetailer")
model_mapping = get_models(adetailer_dir, huggingface=not no_huggingface)
extra_models_dir = Path(shared.opts.data.get("ad_extra_models_dir", ""))
model_mapping = get_models(
adetailer_dir, extra_dir=extra_models_dir, huggingface=not no_huggingface
)
txt2img_submit_button = img2img_submit_button = None
SCRIPT_DEFAULT = "dynamic_prompting,dynamic_thresholding,wildcard_recursive,wildcards,lora_block_weight"
@@ -781,6 +784,16 @@ def on_ui_settings():
),
)
shared.opts.add_option(
"ad_extra_models_path",
shared.OptionInfo(
default="",
label="Extra path to scan adetailer models",
component=gr.Textbox,
section=section,
),
)
shared.opts.add_option(
"ad_save_previews",
shared.OptionInfo(False, "Save mask previews", section=section),