File size: 5,506 Bytes
e699279 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | import os
import yaml
from functools import lru_cache
@lru_cache(maxsize=1)
def load_controlnet_config():
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'controlnet_models.yaml')
try:
print("--- Loading controlnet_models.yaml ---")
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
print("--- ✅ controlnet_models.yaml loaded successfully ---")
return config.get("ControlNet", {})
except Exception as e:
print(f"Error loading controlnet_models.yaml: {e}")
return {}
def get_cn_defaults(arch_val):
cn_full_config = load_controlnet_config()
cn_config = cn_full_config.get(arch_val, [])
if not cn_config:
return [], None, [], None, "None"
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
default_type = all_types[0] if all_types else None
series_choices = []
if default_type:
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
default_series = series_choices[0] if series_choices else None
filepath = "None"
if default_series and default_type:
for model in cn_config:
if model.get("Series") == default_series and default_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return all_types, default_type, series_choices, default_series, filepath
@lru_cache(maxsize=1)
def load_anima_controlnet_lllite_config():
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'anima_controlnet_lllite_models.yaml')
try:
print("--- Loading anima_controlnet_lllite_models.yaml ---")
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
print("--- ✅ anima_controlnet_lllite_models.yaml loaded successfully ---")
return config.get("Anima_ControlNet_Lllite", [])
except Exception as e:
print(f"Error loading anima_controlnet_lllite_models.yaml: {e}")
return []
def get_anima_cn_defaults():
cn_config = load_anima_controlnet_lllite_config()
if not cn_config:
return [], None, [], None, "None"
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
default_type = all_types[0] if all_types else None
series_choices = []
if default_type:
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
default_series = series_choices[0] if series_choices else None
filepath = "None"
if default_series and default_type:
for model in cn_config:
if model.get("Series") == default_series and default_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return all_types, default_type, series_choices, default_series, filepath
@lru_cache(maxsize=1)
def load_diffsynth_controlnet_config():
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
_CN_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'diffsynth_controlnet_models.yaml')
try:
print("--- Loading diffsynth_controlnet_models.yaml ---")
with open(_CN_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
print("--- ✅ diffsynth_controlnet_models.yaml loaded successfully ---")
return config.get("DiffSynth_ControlNet", {})
except Exception as e:
print(f"Error loading diffsynth_controlnet_models.yaml: {e}")
return {}
def get_diffsynth_cn_defaults(arch_val):
cn_full_config = load_diffsynth_controlnet_config()
cn_config = cn_full_config.get(arch_val, [])
if not cn_config:
return [], None, [], None, "None"
all_types = sorted(list(set(t for model in cn_config for t in model.get("Type", []))))
default_type = all_types[0] if all_types else None
series_choices = []
if default_type:
series_choices = sorted(list(set(model.get("Series", "Default") for model in cn_config if default_type in model.get("Type", []))))
default_series = series_choices[0] if series_choices else None
filepath = "None"
if default_series and default_type:
for model in cn_config:
if model.get("Series") == default_series and default_type in model.get("Type", []):
filepath = model.get("Filepath")
break
return all_types, default_type, series_choices, default_series, filepath
@lru_cache(maxsize=1)
def load_ipadapter_config():
_PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
_IPA_MODEL_LIST_PATH = os.path.join(_PROJECT_ROOT, 'yaml', 'ipadapter.yaml')
try:
print("--- Loading ipadapter.yaml ---")
with open(_IPA_MODEL_LIST_PATH, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
print("--- ✅ ipadapter.yaml loaded successfully ---")
return config
except Exception as e:
print(f"Error loading ipadapter.yaml: {e}")
return {}
|