From c704a64c1e5886971086c28cbc7791d1e4ea4dff Mon Sep 17 00:00:00 2001 From: nkchocoai Date: Wed, 31 Jul 2024 13:55:13 +0900 Subject: [PATCH] #25 Support Power Lora Loader (rgthree) --- py/capture.py | 12 ++++++++++++ py/defs/ext/rgthree.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 py/defs/ext/rgthree.py diff --git a/py/capture.py b/py/capture.py index 795420b..fb01d30 100644 --- a/py/capture.py +++ b/py/capture.py @@ -41,6 +41,18 @@ class Capture: inputs[meta].append((node_id, value)) continue + selector = field_data.get("selector") + if selector is not None: + v = selector( + node_id, obj, prompt, extra_data, outputs, input_data + ) + if isinstance(v, list): + for x in v: + inputs[meta].append((node_id, x)) + elif v is not None: + inputs[meta].append((node_id, v)) + continue + field_name = field_data["field_name"] value = input_data.get(field_name) if value is not None: diff --git a/py/defs/ext/rgthree.py b/py/defs/ext/rgthree.py new file mode 100644 index 0000000..b3f1b0d --- /dev/null +++ b/py/defs/ext/rgthree.py @@ -0,0 +1,37 @@ +# https://github.com/rgthree/rgthree-comfy +from ..meta import MetaField +from ..formatters import calc_lora_hash + + +def get_lora_model_name(node_id, obj, prompt, extra_data, outputs, input_data): + return get_lora_data(input_data, "lora") + + +def get_lora_model_hash(node_id, obj, prompt, extra_data, outputs, input_data): + return [ + calc_lora_hash(model_name, input_data) + for model_name in get_lora_data(input_data, "lora") + ] + + +def get_lora_strength(node_id, obj, prompt, extra_data, outputs, input_data): + return get_lora_data(input_data, "strength") + + +def get_lora_data(input_data, attribute): + print(input_data) + return [ + v[0][attribute] + for k, v in input_data.items() + if k.startswith("lora_") and v[0]["on"] + ] + + +CAPTURE_FIELD_LIST = { + "Power Lora Loader (rgthree)": { + MetaField.LORA_MODEL_NAME: {"selector": get_lora_model_name}, + MetaField.LORA_MODEL_HASH: {"selector": get_lora_model_hash}, + MetaField.LORA_STRENGTH_MODEL: {"selector": get_lora_strength}, + MetaField.LORA_STRENGTH_CLIP: {"selector": get_lora_strength}, + }, +}