Hermes Bot commited on
Commit
6ec371b
·
1 Parent(s): 2b442eb

Fix yaml import conflict in settings.py

Browse files
comfy_integration/__pycache__/setup.cpython-311.pyc CHANGED
Binary files a/comfy_integration/__pycache__/setup.cpython-311.pyc and b/comfy_integration/__pycache__/setup.cpython-311.pyc differ
 
core/settings.py CHANGED
@@ -1,207 +1,231 @@
1
- import yaml
2
- import os
3
- from collections import OrderedDict
4
-
5
- CHECKPOINT_DIR = "models/checkpoints"
6
- LORA_DIR = "models/loras"
7
- EMBEDDING_DIR = "models/embeddings"
8
- CONTROLNET_DIR = "models/controlnet"
9
- MODEL_PATCHES_DIR = "models/model_patches"
10
- DIFFUSION_MODELS_DIR = "models/diffusion_models"
11
- VAE_DIR = "models/vae"
12
- TEXT_ENCODERS_DIR = "models/text_encoders"
13
- STYLE_MODELS_DIR = "models/style_models"
14
- CLIP_VISION_DIR = "models/clip_vision"
15
- IPADAPTER_DIR = "models/ipadapter"
16
- IPADAPTER_FLUX_DIR = "models/ipadapter-flux"
17
- INPUT_DIR = "input"
18
- OUTPUT_DIR = "output"
19
-
20
- CATEGORY_TO_DIR_MAP = {
21
- "diffusion_models": DIFFUSION_MODELS_DIR,
22
- "text_encoders": TEXT_ENCODERS_DIR,
23
- "vae": VAE_DIR,
24
- "checkpoints": CHECKPOINT_DIR,
25
- "loras": LORA_DIR,
26
- "controlnet": CONTROLNET_DIR,
27
- "model_patches": MODEL_PATCHES_DIR,
28
- "embeddings": EMBEDDING_DIR,
29
- "style_models": STYLE_MODELS_DIR,
30
- "clip_vision": CLIP_VISION_DIR,
31
- "ipadapter": IPADAPTER_DIR,
32
- "ipadapter-flux": IPADAPTER_FLUX_DIR
33
- }
34
-
35
- _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
36
- _MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_list.yaml')
37
- _FILE_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'file_list.yaml')
38
- _IPADAPTER_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml')
39
- _CONSTANTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'constants.yaml')
40
- _MODEL_ARCHITECTURES_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_architectures.yaml')
41
- _IMAGE_GEN_FEATURES_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'image_gen_features.yaml')
42
- _MODEL_DEFAULTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_defaults.yaml')
43
-
44
- def load_constants_from_yaml(filepath=_CONSTANTS_PATH):
45
- if not os.path.exists(filepath):
46
- print(f"Warning: Constants file not found at {filepath}. Using fallback values.")
47
- return {}
48
- with open(filepath, 'r', encoding='utf-8') as f:
49
- return yaml.safe_load(f)
50
-
51
- def load_architectures_config(filepath=_MODEL_ARCHITECTURES_PATH):
52
- if not os.path.exists(filepath):
53
- print(f"Warning: Architectures file not found at {filepath}.")
54
- return {}
55
- with open(filepath, 'r', encoding='utf-8') as f:
56
- return yaml.safe_load(f)
57
-
58
- def load_features_config(filepath=_IMAGE_GEN_FEATURES_PATH):
59
- if not os.path.exists(filepath):
60
- print(f"Warning: Features file not found at {filepath}.")
61
- return {}
62
- with open(filepath, 'r', encoding='utf-8') as f:
63
- return yaml.safe_load(f)
64
-
65
- def load_model_defaults(filepath=_MODEL_DEFAULTS_PATH):
66
- if not os.path.exists(filepath):
67
- print(f"Warning: Model defaults file not found at {filepath}.")
68
- return {}
69
- with open(filepath, 'r', encoding='utf-8') as f:
70
- return yaml.safe_load(f)
71
-
72
- def load_file_download_map(filepath=_FILE_LIST_PATH):
73
- if not os.path.exists(filepath):
74
- raise FileNotFoundError(f"The file list (for downloads) was not found at: {filepath}")
75
-
76
- with open(filepath, 'r', encoding='utf-8') as f:
77
- file_list_data = yaml.safe_load(f)
78
-
79
- download_info_map = {}
80
- for category, files in file_list_data.get('file', {}).items():
81
- if isinstance(files, list):
82
- for file_info in files:
83
- if 'filename' in file_info:
84
- file_info['category'] = category
85
- download_info_map[file_info['filename']] = file_info
86
- return download_info_map
87
-
88
-
89
- def load_models_from_yaml(model_list_filepath=_MODEL_LIST_PATH, download_map=None):
90
- if not os.path.exists(model_list_filepath):
91
- raise FileNotFoundError(f"The model list file was not found at: {model_list_filepath}")
92
- if download_map is None:
93
- raise ValueError("download_map must be provided to load_models_from_yaml")
94
-
95
- with open(model_list_filepath, 'r', encoding='utf-8') as f:
96
- model_data = yaml.safe_load(f)
97
-
98
- model_maps = {
99
- "MODEL_MAP_CHECKPOINT": OrderedDict(),
100
- "ALL_MODEL_MAP": OrderedDict(),
101
- }
102
- category_map_names = {
103
- "Checkpoint": "MODEL_MAP_CHECKPOINT",
104
- "Checkpoints": "MODEL_MAP_CHECKPOINT"
105
- }
106
-
107
- for category, architectures in model_data.items():
108
- if category in category_map_names:
109
- map_name = category_map_names[category]
110
- if not isinstance(architectures, dict): continue
111
-
112
- for arch, arch_data in architectures.items():
113
- if not isinstance(arch_data, dict): continue
114
-
115
- latent_type = arch_data.get('latent_type', 'latent')
116
- models = arch_data.get('models', [])
117
- if not isinstance(models, list): continue
118
-
119
- for model in models:
120
- display_name = model['display_name']
121
- path_or_components = model.get('path') or model.get('components')
122
- mod_category = model.get('category', None)
123
-
124
- repo_id = ''
125
- if isinstance(path_or_components, str):
126
- download_info = download_map.get(path_or_components, {})
127
- repo_id = download_info.get('repo_id', '')
128
-
129
- model_tuple = (
130
- repo_id,
131
- path_or_components,
132
- arch,
133
- latent_type,
134
- mod_category
135
- )
136
- model_maps[map_name][display_name] = model_tuple
137
- model_maps["ALL_MODEL_MAP"][display_name] = model_tuple
138
-
139
- return model_maps
140
-
141
- try:
142
- ALL_FILE_DOWNLOAD_MAP = load_file_download_map()
143
- loaded_maps = load_models_from_yaml(download_map=ALL_FILE_DOWNLOAD_MAP)
144
- MODEL_MAP_CHECKPOINT = loaded_maps["MODEL_MAP_CHECKPOINT"]
145
- ALL_MODEL_MAP = loaded_maps["ALL_MODEL_MAP"]
146
-
147
- category_to_model_type = {
148
- "diffusion_models": "UNET",
149
- "text_encoders": "TEXT_ENCODER",
150
- "vae": "VAE",
151
- "checkpoints": "SDXL",
152
- "loras": "LORA",
153
- "controlnet": "CONTROLNET",
154
- "model_patches": "MODEL_PATCH",
155
- "style_models": "STYLE",
156
- "clip_vision": "CLIP_VISION",
157
- "ipadapter": "IPADAPTER",
158
- "ipadapter-flux": "IPADAPTER_FLUX"
159
- }
160
- for filename, file_info in ALL_FILE_DOWNLOAD_MAP.items():
161
- if filename not in ALL_MODEL_MAP:
162
- category = file_info.get('category')
163
- model_type = category_to_model_type.get(category, 'UNKNOWN')
164
- repo_id = file_info.get('repo_id', '')
165
- ALL_MODEL_MAP[filename] = (repo_id, filename, model_type, None, None)
166
-
167
- MODEL_TYPE_MAP = {k: v[2] for k, v in ALL_MODEL_MAP.items()}
168
-
169
- ARCH_CATEGORIES_MAP = {}
170
- for display_name, info in MODEL_MAP_CHECKPOINT.items():
171
- arch = info[2]
172
- cat = info[4] if len(info) > 4 else None
173
- if arch not in ARCH_CATEGORIES_MAP:
174
- ARCH_CATEGORIES_MAP[arch] = []
175
- if cat and cat not in ARCH_CATEGORIES_MAP[arch]:
176
- ARCH_CATEGORIES_MAP[arch].append(cat)
177
-
178
- except Exception as e:
179
- print(f"FATAL: Could not load model configuration from YAML. Error: {e}")
180
- ALL_FILE_DOWNLOAD_MAP = {}
181
- MODEL_MAP_CHECKPOINT, ALL_MODEL_MAP = {}, {}
182
- MODEL_TYPE_MAP = {}
183
- ARCH_CATEGORIES_MAP = {}
184
-
185
-
186
- try:
187
- _constants = load_constants_from_yaml()
188
- MAX_LORAS = _constants.get('MAX_LORAS', 5)
189
- MAX_EMBEDDINGS = _constants.get('MAX_EMBEDDINGS', 5)
190
- MAX_CONDITIONINGS = _constants.get('MAX_CONDITIONINGS', 10)
191
- MAX_CONTROLNETS = _constants.get('MAX_CONTROLNETS', 5)
192
- MAX_IPADAPTERS = _constants.get('MAX_IPADAPTERS', 5)
193
- LORA_SOURCE_CHOICES = _constants.get('LORA_SOURCE_CHOICES', ["Civitai", "File"])
194
- RESOLUTION_MAP = _constants.get('RESOLUTION_MAP', {})
195
- MULTIPLIERS_MAP = _constants.get('MULTIPLIERS_MAP', {})
196
- ARCHITECTURES_CONFIG = load_architectures_config()
197
- FEATURES_CONFIG = load_features_config()
198
- MODEL_DEFAULTS_CONFIG = load_model_defaults()
199
- except Exception as e:
200
- print(f"FATAL: Could not load constants from YAML. Error: {e}")
201
- MAX_LORAS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_CONTROLNETS, MAX_IPADAPTERS = 5, 5, 10, 5, 5
202
- LORA_SOURCE_CHOICES = ["Civitai", "File"]
203
- RESOLUTION_MAP = {}
204
- MULTIPLIERS_MAP = {}
205
- ARCHITECTURES_CONFIG = {}
206
- FEATURES_CONFIG = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  MODEL_DEFAULTS_CONFIG = {}
 
1
+ """Settings module for the ImageGen Space.
2
+
3
+ The repository contains a directory named ``yaml`` that stores configuration
4
+ files (``model_list.yaml``, ``constants.yaml`` …). Unfortunately this directory
5
+ shadows the external **PyYAML** package when ``import yaml`` is performed, leading
6
+ to ``AttributeError: module 'yaml' has no attribute 'safe_load'`` at runtime.
7
+
8
+ To resolve the naming clash we temporarily remove the project root from
9
+ ``sys.path`` while importing the real PyYAML library, then restore the original
10
+ search path. This ensures ``yaml.safe_load`` and related helpers are available
11
+ throughout the module without renaming the data directory.
12
+ """
13
+
14
+ import sys
15
+ # Preserve the original search path.
16
+ _original_sys_path = sys.path[:]
17
+ # Exclude the ``ImageGen`` project root (which contains the conflicting ``yaml``
18
+ # directory) from the import search. Paths that end with ``ImageGen`` or contain
19
+ # ``/ImageGen/`` are filtered out.
20
+ sys.path = [p for p in sys.path if not (p.endswith('ImageGen') or '/ImageGen/' in p)]
21
+ import yaml as _yaml_lib
22
+ yaml = _yaml_lib
23
+ # Restore the original path for all subsequent imports.
24
+ sys.path = _original_sys_path
25
+
26
+ import os
27
+ from collections import OrderedDict
28
+
29
+ CHECKPOINT_DIR = "models/checkpoints"
30
+ LORA_DIR = "models/loras"
31
+ EMBEDDING_DIR = "models/embeddings"
32
+ CONTROLNET_DIR = "models/controlnet"
33
+ MODEL_PATCHES_DIR = "models/model_patches"
34
+ DIFFUSION_MODELS_DIR = "models/diffusion_models"
35
+ VAE_DIR = "models/vae"
36
+ TEXT_ENCODERS_DIR = "models/text_encoders"
37
+ STYLE_MODELS_DIR = "models/style_models"
38
+ CLIP_VISION_DIR = "models/clip_vision"
39
+ IPADAPTER_DIR = "models/ipadapter"
40
+ IPADAPTER_FLUX_DIR = "models/ipadapter-flux"
41
+ INPUT_DIR = "input"
42
+ OUTPUT_DIR = "output"
43
+
44
+ CATEGORY_TO_DIR_MAP = {
45
+ "diffusion_models": DIFFUSION_MODELS_DIR,
46
+ "text_encoders": TEXT_ENCODERS_DIR,
47
+ "vae": VAE_DIR,
48
+ "checkpoints": CHECKPOINT_DIR,
49
+ "loras": LORA_DIR,
50
+ "controlnet": CONTROLNET_DIR,
51
+ "model_patches": MODEL_PATCHES_DIR,
52
+ "embeddings": EMBEDDING_DIR,
53
+ "style_models": STYLE_MODELS_DIR,
54
+ "clip_vision": CLIP_VISION_DIR,
55
+ "ipadapter": IPADAPTER_DIR,
56
+ "ipadapter-flux": IPADAPTER_FLUX_DIR
57
+ }
58
+
59
+ _PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
60
+ _MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_list.yaml')
61
+ _FILE_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'file_list.yaml')
62
+ _IPADAPTER_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml')
63
+ _CONSTANTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'constants.yaml')
64
+ _MODEL_ARCHITECTURES_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_architectures.yaml')
65
+ _IMAGE_GEN_FEATURES_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'image_gen_features.yaml')
66
+ _MODEL_DEFAULTS_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'model_defaults.yaml')
67
+
68
+ def load_constants_from_yaml(filepath=_CONSTANTS_PATH):
69
+ if not os.path.exists(filepath):
70
+ print(f"Warning: Constants file not found at {filepath}. Using fallback values.")
71
+ return {}
72
+ with open(filepath, 'r', encoding='utf-8') as f:
73
+ return yaml.safe_load(f)
74
+
75
+ def load_architectures_config(filepath=_MODEL_ARCHITECTURES_PATH):
76
+ if not os.path.exists(filepath):
77
+ print(f"Warning: Architectures file not found at {filepath}.")
78
+ return {}
79
+ with open(filepath, 'r', encoding='utf-8') as f:
80
+ return yaml.safe_load(f)
81
+
82
+ def load_features_config(filepath=_IMAGE_GEN_FEATURES_PATH):
83
+ if not os.path.exists(filepath):
84
+ print(f"Warning: Features file not found at {filepath}.")
85
+ return {}
86
+ with open(filepath, 'r', encoding='utf-8') as f:
87
+ return yaml.safe_load(f)
88
+
89
+ def load_model_defaults(filepath=_MODEL_DEFAULTS_PATH):
90
+ if not os.path.exists(filepath):
91
+ print(f"Warning: Model defaults file not found at {filepath}.")
92
+ return {}
93
+ with open(filepath, 'r', encoding='utf-8') as f:
94
+ return yaml.safe_load(f)
95
+
96
+ def load_file_download_map(filepath=_FILE_LIST_PATH):
97
+ if not os.path.exists(filepath):
98
+ raise FileNotFoundError(f"The file list (for downloads) was not found at: {filepath}")
99
+
100
+ with open(filepath, 'r', encoding='utf-8') as f:
101
+ file_list_data = yaml.safe_load(f)
102
+
103
+ download_info_map = {}
104
+ for category, files in file_list_data.get('file', {}).items():
105
+ if isinstance(files, list):
106
+ for file_info in files:
107
+ if 'filename' in file_info:
108
+ file_info['category'] = category
109
+ download_info_map[file_info['filename']] = file_info
110
+ return download_info_map
111
+
112
+
113
+ def load_models_from_yaml(model_list_filepath=_MODEL_LIST_PATH, download_map=None):
114
+ if not os.path.exists(model_list_filepath):
115
+ raise FileNotFoundError(f"The model list file was not found at: {model_list_filepath}")
116
+ if download_map is None:
117
+ raise ValueError("download_map must be provided to load_models_from_yaml")
118
+
119
+ with open(model_list_filepath, 'r', encoding='utf-8') as f:
120
+ model_data = yaml.safe_load(f)
121
+
122
+ model_maps = {
123
+ "MODEL_MAP_CHECKPOINT": OrderedDict(),
124
+ "ALL_MODEL_MAP": OrderedDict(),
125
+ }
126
+ category_map_names = {
127
+ "Checkpoint": "MODEL_MAP_CHECKPOINT",
128
+ "Checkpoints": "MODEL_MAP_CHECKPOINT"
129
+ }
130
+
131
+ for category, architectures in model_data.items():
132
+ if category in category_map_names:
133
+ map_name = category_map_names[category]
134
+ if not isinstance(architectures, dict): continue
135
+
136
+ for arch, arch_data in architectures.items():
137
+ if not isinstance(arch_data, dict): continue
138
+
139
+ latent_type = arch_data.get('latent_type', 'latent')
140
+ models = arch_data.get('models', [])
141
+ if not isinstance(models, list): continue
142
+
143
+ for model in models:
144
+ display_name = model['display_name']
145
+ path_or_components = model.get('path') or model.get('components')
146
+ mod_category = model.get('category', None)
147
+
148
+ repo_id = ''
149
+ if isinstance(path_or_components, str):
150
+ download_info = download_map.get(path_or_components, {})
151
+ repo_id = download_info.get('repo_id', '')
152
+
153
+ model_tuple = (
154
+ repo_id,
155
+ path_or_components,
156
+ arch,
157
+ latent_type,
158
+ mod_category
159
+ )
160
+ model_maps[map_name][display_name] = model_tuple
161
+ model_maps["ALL_MODEL_MAP"][display_name] = model_tuple
162
+
163
+ return model_maps
164
+
165
+ try:
166
+ ALL_FILE_DOWNLOAD_MAP = load_file_download_map()
167
+ loaded_maps = load_models_from_yaml(download_map=ALL_FILE_DOWNLOAD_MAP)
168
+ MODEL_MAP_CHECKPOINT = loaded_maps["MODEL_MAP_CHECKPOINT"]
169
+ ALL_MODEL_MAP = loaded_maps["ALL_MODEL_MAP"]
170
+
171
+ category_to_model_type = {
172
+ "diffusion_models": "UNET",
173
+ "text_encoders": "TEXT_ENCODER",
174
+ "vae": "VAE",
175
+ "checkpoints": "SDXL",
176
+ "loras": "LORA",
177
+ "controlnet": "CONTROLNET",
178
+ "model_patches": "MODEL_PATCH",
179
+ "style_models": "STYLE",
180
+ "clip_vision": "CLIP_VISION",
181
+ "ipadapter": "IPADAPTER",
182
+ "ipadapter-flux": "IPADAPTER_FLUX"
183
+ }
184
+ for filename, file_info in ALL_FILE_DOWNLOAD_MAP.items():
185
+ if filename not in ALL_MODEL_MAP:
186
+ category = file_info.get('category')
187
+ model_type = category_to_model_type.get(category, 'UNKNOWN')
188
+ repo_id = file_info.get('repo_id', '')
189
+ ALL_MODEL_MAP[filename] = (repo_id, filename, model_type, None, None)
190
+
191
+ MODEL_TYPE_MAP = {k: v[2] for k, v in ALL_MODEL_MAP.items()}
192
+
193
+ ARCH_CATEGORIES_MAP = {}
194
+ for display_name, info in MODEL_MAP_CHECKPOINT.items():
195
+ arch = info[2]
196
+ cat = info[4] if len(info) > 4 else None
197
+ if arch not in ARCH_CATEGORIES_MAP:
198
+ ARCH_CATEGORIES_MAP[arch] = []
199
+ if cat and cat not in ARCH_CATEGORIES_MAP[arch]:
200
+ ARCH_CATEGORIES_MAP[arch].append(cat)
201
+
202
+ except Exception as e:
203
+ print(f"FATAL: Could not load model configuration from YAML. Error: {e}")
204
+ ALL_FILE_DOWNLOAD_MAP = {}
205
+ MODEL_MAP_CHECKPOINT, ALL_MODEL_MAP = {}, {}
206
+ MODEL_TYPE_MAP = {}
207
+ ARCH_CATEGORIES_MAP = {}
208
+
209
+
210
+ try:
211
+ _constants = load_constants_from_yaml()
212
+ MAX_LORAS = _constants.get('MAX_LORAS', 5)
213
+ MAX_EMBEDDINGS = _constants.get('MAX_EMBEDDINGS', 5)
214
+ MAX_CONDITIONINGS = _constants.get('MAX_CONDITIONINGS', 10)
215
+ MAX_CONTROLNETS = _constants.get('MAX_CONTROLNETS', 5)
216
+ MAX_IPADAPTERS = _constants.get('MAX_IPADAPTERS', 5)
217
+ LORA_SOURCE_CHOICES = _constants.get('LORA_SOURCE_CHOICES', ["Civitai", "File"])
218
+ RESOLUTION_MAP = _constants.get('RESOLUTION_MAP', {})
219
+ MULTIPLIERS_MAP = _constants.get('MULTIPLIERS_MAP', {})
220
+ ARCHITECTURES_CONFIG = load_architectures_config()
221
+ FEATURES_CONFIG = load_features_config()
222
+ MODEL_DEFAULTS_CONFIG = load_model_defaults()
223
+ except Exception as e:
224
+ print(f"FATAL: Could not load constants from YAML. Error: {e}")
225
+ MAX_LORAS, MAX_EMBEDDINGS, MAX_CONDITIONINGS, MAX_CONTROLNETS, MAX_IPADAPTERS = 5, 5, 10, 5, 5
226
+ LORA_SOURCE_CHOICES = ["Civitai", "File"]
227
+ RESOLUTION_MAP = {}
228
+ MULTIPLIERS_MAP = {}
229
+ ARCHITECTURES_CONFIG = {}
230
+ FEATURES_CONFIG = {}
231
  MODEL_DEFAULTS_CONFIG = {}