File size: 2,287 Bytes
2d31d6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06d0fb4
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
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_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 {}