-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLoraStackMango.py
More file actions
50 lines (45 loc) · 2.46 KB
/
Copy pathLoraStackMango.py
File metadata and controls
50 lines (45 loc) · 2.46 KB
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
import os
import folder_paths
import comfy.sd
import comfy.utils
def load_single_lora(model, clip, lora_name, weight):
lora_path = folder_paths.get_full_path("loras", lora_name)
if not lora_path or not os.path.exists(lora_path):
return model, clip
lora = comfy.utils.load_torch_file(lora_path, safe_load=True)
model, clip = comfy.sd.load_lora_for_models(model, clip, lora, weight, weight)
return model, clip
class LoraStackMango:
@classmethod
def INPUT_TYPES(cls):
loras = ["None"] + folder_paths.get_filename_list("loras")
return {
"required": {
"model": ("MODEL",),
"clip": ("CLIP",),
"lora_stack": ("LORA_STACK", {"default": []}),
"LoraName1": (loras, {"default": "None", "tooltip": "LoRA 1 filename"}),
"LoraWeight1": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.05, "tooltip": "LoRA 1 weight"}),
"LoraName2": (loras, {"default": "None", "tooltip": "LoRA 2 filename"}),
"LoraWeight2": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.05, "tooltip": "LoRA 2 weight"}),
"LoraName3": (loras, {"default": "None", "tooltip": "LoRA 3 filename"}),
"LoraWeight3": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.05, "tooltip": "LoRA 3 weight"}),
"LoraName4": (loras, {"default": "None", "tooltip": "LoRA 4 filename"}),
"LoraWeight4": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.05, "tooltip": "LoRA 4 weight"}),
"LoraName5": (loras, {"default": "None", "tooltip": "LoRA 5 filename"}),
"LoraWeight5": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.05, "tooltip": "LoRA 5 weight"}),
}
}
RETURN_TYPES = ("MODEL", "CLIP", "LORA_STACK")
RETURN_NAMES = ("model", "clip", "lora_stack")
FUNCTION = "apply_loras"
CATEGORY = "Mango Node Pack/Loaders"
def apply_loras(self, model, clip, lora_stack, **kwargs):
new_lora_stack = list(lora_stack) if lora_stack else []
for i in range(1, 6):
name = kwargs.get(f"LoraName{i}")
weight = kwargs.get(f"LoraWeight{i}", 1.0)
if name and name != "None":
model, clip = load_single_lora(model, clip, name, weight)
new_lora_stack.append((name, weight, weight))
return (model, clip, new_lora_stack)