-
Notifications
You must be signed in to change notification settings - Fork 5
/
LoraStackLoaders_PoP.py
131 lines (107 loc) · 5.93 KB
/
LoraStackLoaders_PoP.py
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
import folder_paths
import os
import sys
import comfy.utils
# Add the path to the comfy directory to sys.path
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy"))
class LoraStackLoader_PoP:
loras = ["None"] + folder_paths.get_filename_list("loras")
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("MODEL",),
"clip": ("CLIP",),
"switch_1": (["Off", "On"],),
"lora_name_1": (cls.loras,),
"strength_model_1": ("FLOAT", {"default": 0.0, "min": -10.0, "max": 10.0, "step": 0.01}),
"strength_clip_1": ("FLOAT", {"default": 0.0, "min": -10.0, "max": 10.0, "step": 0.01}),
"switch_2": (["Off", "On"],),
"lora_name_2": (cls.loras,),
"strength_model_2": ("FLOAT", {"default": 0.0, "min": -10.0, "max": 10.0, "step": 0.01}),
"strength_clip_2": ("FLOAT", {"default": 0.0, "min": -10.0, "max": 10.0, "step": 0.01}),
"switch_3": (["Off", "On"],),
"lora_name_3": (cls.loras,),
"strength_model_3": ("FLOAT", {"default": 0.0, "min": -10.0, "max": 10.0, "step": 0.01}),
"strength_clip_3": ("FLOAT", {"default": 0.0, "min": -10.0, "max": 10.0, "step": 0.01}),
}
}
RETURN_TYPES = ("MODEL", "CLIP")
FUNCTION = "apply_loras"
CATEGORY = "loaders"
def apply_loras(self, model, clip, switch_1, lora_name_1, strength_model_1, strength_clip_1, switch_2, lora_name_2,
strength_model_2, strength_clip_2, switch_3, lora_name_3, strength_model_3, strength_clip_3):
loras = [
(switch_1, lora_name_1, strength_model_1, strength_clip_1),
(switch_2, lora_name_2, strength_model_2, strength_clip_2),
(switch_3, lora_name_3, strength_model_3, strength_clip_3)
]
loras = [l for l in loras if l[0] != 'None']
for switch, lora_name, strength_model, strength_clip in loras:
if switch == 'Off' or lora_name is None:
continue
lora_path = folder_paths.get_full_path("loras", lora_name)
if lora_path is None:
continue
lora = comfy.utils.load_torch_file(lora_path, safe_load=True)
model, clip = comfy.sd.load_lora_for_models(model, clip, lora, strength_model, strength_clip)
return (model, clip)
class LoraStackLoader10_PoP:
loras = ["None"] + folder_paths.get_filename_list("loras")
@classmethod
def INPUT_TYPES(cls):
input_types = {"required": {"model": ("MODEL",), "clip": ("CLIP",)}}
for i in range(1, 11):
input_types["required"].update({
f"switch_{i}": (["Off", "On"],),
f"lora_name_{i}": (cls.loras,),
f"strength_model_{i}": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01}),
f"strength_clip_{i}": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01}),
})
return input_types
RETURN_TYPES = ("MODEL", "CLIP")
FUNCTION = "apply_loras"
CATEGORY = "loaders"
def apply_loras(self, model, clip,
switch_1=None, lora_name_1=None, strength_model_1=None, strength_clip_1=None,
switch_2=None, lora_name_2=None, strength_model_2=None, strength_clip_2=None,
switch_3=None, lora_name_3=None, strength_model_3=None, strength_clip_3=None,
switch_4=None, lora_name_4=None, strength_model_4=None, strength_clip_4=None,
switch_5=None, lora_name_5=None, strength_model_5=None, strength_clip_5=None,
switch_6=None, lora_name_6=None, strength_model_6=None, strength_clip_6=None,
switch_7=None, lora_name_7=None, strength_model_7=None, strength_clip_7=None,
switch_8=None, lora_name_8=None, strength_model_8=None, strength_clip_8=None,
switch_9=None, lora_name_9=None, strength_model_9=None, strength_clip_9=None,
switch_10=None, lora_name_10=None, strength_model_10=None, strength_clip_10=None):
loras = [
(switch_1, lora_name_1, strength_model_1, strength_clip_1),
(switch_2, lora_name_2, strength_model_2, strength_clip_2),
(switch_3, lora_name_3, strength_model_3, strength_clip_3),
(switch_4, lora_name_4, strength_model_4, strength_clip_4),
(switch_5, lora_name_5, strength_model_5, strength_clip_5),
(switch_6, lora_name_6, strength_model_6, strength_clip_6),
(switch_7, lora_name_7, strength_model_7, strength_clip_7),
(switch_8, lora_name_8, strength_model_8, strength_clip_8),
(switch_9, lora_name_9, strength_model_9, strength_clip_9),
(switch_10, lora_name_10, strength_model_10, strength_clip_10)
]
# More code, everyone
for switch, lora_name, strength_model, strength_clip in loras:
if switch == 'Off' or lora_name is None:
continue
lora_path = folder_paths.get_full_path("loras", lora_name)
if lora_path is None:
continue
lora = comfy.utils.load_torch_file(lora_path, safe_load=True)
model, clip = comfy.sd.load_lora_for_models(model, clip, lora, strength_model, strength_clip)
return (model, clip)
# Dictionary that contains all nodes to export with their names
NODE_CLASS_MAPPINGS = {
"LoraStackLoader_PoP": LoraStackLoader_PoP,
"LoraStackLoader10_PoP": LoraStackLoader10_PoP,
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
"LoraStackLoader_PoP": "LoraStackLoader_PoP",
"LoraStackLoader10": "LoraStackLoader10_PoP"
}