Skip to content

Commit 8206ab4

Browse files
authored
Merge pull request #17 from cleissonalves/add-stacker-node
Add LocalLoraGalleryStacker node.
2 parents 6685414 + d0e8dcd commit 8206ab4

File tree

2 files changed

+89
-11
lines changed

2 files changed

+89
-11
lines changed

Local_Lora_Gallery.py

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,84 @@ def load_loras(self, model, unique_id, selection_data="[]", **kwargs):
649649
trigger_words_string = ", ".join(trigger_words_list)
650650
return (current_model, trigger_words_string)
651651

652+
class LocalLoraGalleryStacker(BaseLoraGallery):
653+
@classmethod
654+
def INPUT_TYPES(cls):
655+
return {
656+
"required": {},
657+
"hidden": {
658+
"selection_data": (
659+
"STRING",
660+
{"default": "[]", "multiline": True, "forceInput": True},
661+
),
662+
},
663+
}
664+
665+
RETURN_TYPES = ("LORA_STACK", "STRING", "STRING")
666+
RETURN_NAMES = ("lora_stack", "active_loras", "trigger_words")
667+
668+
FUNCTION = "load_loras"
669+
CATEGORY = "📜Asset Gallery/Loras"
670+
671+
def load_loras(self, selection_data="[]", **kwargs):
672+
try:
673+
lora_configs = json.loads(selection_data)
674+
except:
675+
lora_configs = []
676+
677+
all_metadata = load_metadata()
678+
trigger_words_list = []
679+
active_loras_list = []
680+
lora_stack_list = []
681+
682+
for config in lora_configs:
683+
if not config.get("on", True) or not config.get("lora"):
684+
continue
685+
686+
lora_name = config["lora"]
687+
688+
# TRIGGER_WORDS
689+
if config.get("use_trigger", True):
690+
lora_meta = all_metadata.get(lora_name, {})
691+
triggers = lora_meta.get("trigger_words", "").strip()
692+
if triggers:
693+
trigger_words_list.append(triggers)
694+
695+
try:
696+
strength = float(config.get("strength", 1.0))
697+
if strength == 0:
698+
continue
699+
700+
lora_path = lora_name.replace("/", os.sep)
701+
702+
# LORA_STACK
703+
lora_stack_list.append((lora_path, strength, strength))
704+
705+
# ACTIVE_LORAS
706+
start = lora_path.rfind("/") + 1
707+
end = lora_path.rfind(".")
708+
lora_name_only = lora_path[start:end] if end > start else ""
709+
active_loras_list.append(
710+
f"<lora:{lora_name_only}:{str(strength).strip()}>"
711+
)
712+
713+
except Exception as e:
714+
print(
715+
f"LocalLoraGalleryStacker: Failed to load LoRA '{lora_name}': {e}"
716+
)
717+
718+
trigger_words_string = ", ".join(trigger_words_list)
719+
active_loras_string = " ".join(active_loras_list)
720+
return (lora_stack_list, active_loras_string, trigger_words_string)
721+
722+
652723
NODE_CLASS_MAPPINGS = {
653724
"LocalLoraGallery": LocalLoraGallery,
654-
"LocalLoraGalleryModelOnly": LocalLoraGalleryModelOnly
725+
"LocalLoraGalleryModelOnly": LocalLoraGalleryModelOnly,
726+
"LocalLoraGalleryStacker": LocalLoraGalleryStacker,
655727
}
656728
NODE_DISPLAY_NAME_MAPPINGS = {
657729
"LocalLoraGallery": "Local Lora Gallery",
658-
"LocalLoraGalleryModelOnly": "Local Lora Gallery (Model Only)"
659-
}
730+
"LocalLoraGalleryModelOnly": "Local Lora Gallery (Model Only)",
731+
"LocalLoraGalleryStacker": "Local Lora Gallery Stacker",
732+
}

js/Local_Lora_Gallery.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const LocalLoraGalleryNode = {
9595
this.size = [700, 600];
9696
this.loraData = [];
9797
this.availableLoras = [];
98-
this.isModelOnly = nodeData.name.includes("ModelOnly");
98+
this.isModelOnly = nodeData.name.includes("ModelOnly") || nodeData.name.includes("Stacker");
9999
this.selectedCardsForEditing = new Set();
100100

101101
const node_instance = this;
@@ -1202,10 +1202,15 @@ const LocalLoraGalleryNode = {
12021202
};
12031203

12041204
app.registerExtension({
1205-
name: "LocalLoraGallery.GalleryUI",
1206-
async beforeRegisterNodeDef(nodeType, nodeData) {
1207-
if (nodeData.name === "LocalLoraGallery" || nodeData.name === "LocalLoraGalleryModelOnly") {
1208-
LocalLoraGalleryNode.setup(nodeType, nodeData);
1209-
}
1210-
},
1211-
});
1205+
name: "LocalLoraGallery.GalleryUI",
1206+
async beforeRegisterNodeDef(nodeType, nodeData) {
1207+
if (
1208+
nodeData.name === "LocalLoraGallery" ||
1209+
nodeData.name === "LocalLoraGalleryModelOnly" ||
1210+
nodeData.name === "LocalLoraGalleryStacker"
1211+
) {
1212+
LocalLoraGalleryNode.setup(nodeType, nodeData);
1213+
}
1214+
},
1215+
});
1216+

0 commit comments

Comments
 (0)