@@ -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+
652723NODE_CLASS_MAPPINGS = {
653724 "LocalLoraGallery" : LocalLoraGallery ,
654- "LocalLoraGalleryModelOnly" : LocalLoraGalleryModelOnly
725+ "LocalLoraGalleryModelOnly" : LocalLoraGalleryModelOnly ,
726+ "LocalLoraGalleryStacker" : LocalLoraGalleryStacker ,
655727}
656728NODE_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+ }
0 commit comments