Skip to content

Commit 51d6427

Browse files
Add support for loading extra paths from yaml file.
Rename extra_model_paths.yaml.example to extra_model_paths.yaml and edit it to point to your other UI.
1 parent 8bad322 commit 51d6427

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

extra_model_paths.yaml.example

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#Rename this to extra_model_paths.yaml and ComfyUI will load it
2+
3+
#config for a1111 ui
4+
#all you have to do is change the base_path to where yours is installed
5+
a111:
6+
base_path: path/to/stable-diffusion-webui/
7+
8+
checkpoints: models/Stable-diffusion
9+
configs: models/Stable-diffusion
10+
vae: models/VAE
11+
loras: models/Lora
12+
upscale_models: |
13+
models/ESRGAN
14+
models/SwinIR
15+
embeddings: embeddings
16+
controlnet: models/ControlNet
17+
18+
#other_ui:
19+
# base_path: path/to/ui
20+
# checkpoints: models/checkpoints
21+
22+
23+

folder_paths.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
folder_names_and_paths["upscale_models"] = ([os.path.join(models_dir, "upscale_models")], supported_pt_extensions)
2929

3030

31-
def add_model_folder(folder_name, full_folder_path):
31+
def add_model_folder_path(folder_name, full_folder_path):
3232
global folder_names_and_paths
33+
if folder_name in folder_names_and_paths:
34+
folder_names_and_paths[folder_name][0].append(full_folder_path)
3335

3436

3537
def recursive_search(directory):

main.py

+31
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import execution
3535
import server
36+
import folder_paths
37+
import yaml
3638

3739
def prompt_worker(q, server):
3840
e = execution.PromptExecutor(server)
@@ -59,6 +61,26 @@ def cleanup_temp():
5961
if os.path.exists(temp_dir):
6062
shutil.rmtree(temp_dir, ignore_errors=True)
6163

64+
def load_extra_path_config(yaml_path):
65+
with open(yaml_path, 'r') as stream:
66+
config = yaml.safe_load(stream)
67+
for c in config:
68+
conf = config[c]
69+
if conf is None:
70+
continue
71+
base_path = None
72+
if "base_path" in conf:
73+
base_path = conf.pop("base_path")
74+
for x in conf:
75+
for y in conf[x].split("\n"):
76+
if len(y) == 0:
77+
continue
78+
full_path = y
79+
if base_path is not None:
80+
full_path = os.path.join(base_path, full_path)
81+
print("Adding extra search path", x, full_path)
82+
folder_paths.add_model_folder_path(x, full_path)
83+
6284
if __name__ == "__main__":
6385
cleanup_temp()
6486

@@ -79,6 +101,15 @@ def cleanup_temp():
79101
if '--dont-print-server' in sys.argv:
80102
dont_print = True
81103

104+
extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml")
105+
if os.path.isfile(extra_model_paths_config_path):
106+
load_extra_path_config(extra_model_paths_config_path)
107+
108+
if '--extra-model-paths-config' in sys.argv:
109+
indices = [(i + 1) for i in range(len(sys.argv) - 1) if sys.argv[i] == '--extra-model-paths-config']
110+
for i in indices:
111+
load_extra_path_config(sys.argv[i])
112+
82113
port = 8188
83114
try:
84115
p_index = sys.argv.index('--port')

0 commit comments

Comments
 (0)