|
from nodes import LoraLoader
|
|
from .constants import get_category, get_name
|
|
from .power_prompt_utils import get_lora_by_filename
|
|
from .utils import FlexibleOptionalInputType, any_type
|
|
|
|
|
|
class RgthreePowerLoraLoader:
|
|
""" The Power Lora Loader is a powerful, flexible node to add multiple loras to a model/clip."""
|
|
|
|
NAME = get_name('Power Lora Loader')
|
|
CATEGORY = get_category()
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"model": ("MODEL",),
|
|
"clip": ("CLIP",),
|
|
},
|
|
|
|
"optional": FlexibleOptionalInputType(any_type),
|
|
"hidden": {},
|
|
}
|
|
|
|
RETURN_TYPES = ("MODEL", "CLIP")
|
|
RETURN_NAMES = ("MODEL", "CLIP")
|
|
FUNCTION = "load_loras"
|
|
|
|
def load_loras(self, model, clip, **kwargs):
|
|
"""Loops over the provided loras in kwargs and applies valid ones."""
|
|
for key, value in kwargs.items():
|
|
key = key.upper()
|
|
if key.startswith('LORA_') and 'on' in value and 'lora' in value and 'strength' in value:
|
|
strength_model = value['strength']
|
|
|
|
|
|
strength_clip = value['strengthTwo'] if 'strengthTwo' in value and value[
|
|
'strengthTwo'] is not None else strength_model
|
|
if value['on'] and (strength_model != 0 or strength_clip != 0):
|
|
lora = get_lora_by_filename(value['lora'], log_node=self.NAME)
|
|
if lora is not None:
|
|
model, clip = LoraLoader().load_lora(model, clip, lora, strength_model, strength_clip)
|
|
|
|
return (model, clip)
|
|
|