mirror of
https://github.com/idrirap/ComfyUI-Lora-Auto-Trigger-Words.git
synced 2026-03-21 21:22:12 -03:00
fix: wrong value in clamping. feat: added an optional lora name append if empty result + updated readme
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
This project is a fork of https://github.com/Extraltodeus/LoadLoraWithTags
|
||||
The aim of these custom nodes is to get an _easy_ access to the tags used to trigger a lora.
|
||||
This project is compatible with Stacked Loras from https://github.com/LucianoCirino/efficiency-nodes-comfyui/releases
|
||||
I talk about **lora**, but works with **lycoris** too.
|
||||
|
||||
## Install
|
||||
Some of this project nodes depends on https://github.com/pythongosssss/ComfyUI-Custom-Scripts :
|
||||
@@ -27,6 +28,10 @@ These loaders have two custom outputs:
|
||||
This outputs needs to be filtered by two othere nodes:
|
||||
- TagsFormater: Helper to show the available tag and their indexes
|
||||
- tagsSelector: allow to filter tags and apply a weight to it.
|
||||
- TagSelector contains four parameters. First the selector (see Filtering next)
|
||||
- The weight `(tag:weight)`
|
||||
- The boolean `ensure_comma`. To properly append comma if a prefix or suffix is added.
|
||||
- The boolean `append_loraname_if_empty` which will add the name of the lora in the list of outputs if they are empty.
|
||||
#### Filtering
|
||||
The format is simple. It's the same as python list index, but can select multiple index or ranges of indexes separated by comas.
|
||||
`Ex: 0, 3, 5:8, -8:`
|
||||
|
||||
@@ -19,6 +19,7 @@ class LoraLoaderVanilla:
|
||||
"strength_model": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 2.0, "step": 0.1}),
|
||||
"strength_clip": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 2.0, "step": 0.1}),
|
||||
"force_fetch": ("BOOLEAN", {"default": False}),
|
||||
"append_loraname_if_empty": ("BOOLEAN", {"default": False}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +28,13 @@ class LoraLoaderVanilla:
|
||||
FUNCTION = "load_lora"
|
||||
CATEGORY = "autotrigger"
|
||||
|
||||
def load_lora(self, model, clip, lora_name, strength_model, strength_clip, force_fetch):
|
||||
def load_lora(self, model, clip, lora_name, strength_model, strength_clip, force_fetch, append_loraname_if_empty):
|
||||
meta_tags_list = sort_tags_by_frequency(get_metadata(lora_name, "loras"))
|
||||
output_tags_list = load_and_save_tags(lora_name, force_fetch)
|
||||
civitai_tags_list = load_and_save_tags(lora_name, force_fetch)
|
||||
|
||||
meta_tags_list = append_lora_name_if_empty(meta_tags_list, lora_name, append_loraname_if_empty)
|
||||
civitai_tags_list = append_lora_name_if_empty(civitai_tags_list, lora_name, append_loraname_if_empty)
|
||||
|
||||
lora_path = folder_paths.get_full_path("loras", lora_name)
|
||||
lora = None
|
||||
if self.loaded_lora is not None:
|
||||
@@ -46,7 +51,7 @@ class LoraLoaderVanilla:
|
||||
|
||||
model_lora, clip_lora = load_lora_for_models(model, clip, lora, strength_model, strength_clip)
|
||||
|
||||
return (model_lora, clip_lora, output_tags_list, meta_tags_list)
|
||||
return (model_lora, clip_lora, civitai_tags_list, meta_tags_list)
|
||||
|
||||
class LoraLoaderStackedVanilla:
|
||||
@classmethod
|
||||
@@ -57,6 +62,7 @@ class LoraLoaderStackedVanilla:
|
||||
"lora_name": (LORA_LIST,),
|
||||
"lora_weight": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01}),
|
||||
"force_fetch": ("BOOLEAN", {"default": False}),
|
||||
"append_loraname_if_empty": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
"optional": {
|
||||
"lora_stack": ("LORA_STACK", ),
|
||||
@@ -69,12 +75,15 @@ class LoraLoaderStackedVanilla:
|
||||
#OUTPUT_NODE = False
|
||||
CATEGORY = "autotrigger"
|
||||
|
||||
def set_stack(self, lora_name, lora_weight, force_fetch, lora_stack=None):
|
||||
def set_stack(self, lora_name, lora_weight, force_fetch, append_loraname_if_empty, lora_stack=None):
|
||||
civitai_tags_list = load_and_save_tags(lora_name, force_fetch)
|
||||
|
||||
meta_tags = get_metadata(lora_name, "loras")
|
||||
meta_tags_list = sort_tags_by_frequency(meta_tags)
|
||||
|
||||
civitai_tags_list = append_lora_name_if_empty(civitai_tags_list, lora_name, append_loraname_if_empty)
|
||||
meta_tags_list = append_lora_name_if_empty(meta_tags_list, lora_name, append_loraname_if_empty)
|
||||
|
||||
if lora_stack is not None:
|
||||
lora_stack.append((lora_name,lora_weight,lora_weight,))
|
||||
else:
|
||||
@@ -99,6 +108,7 @@ class LoraLoaderAdvanced:
|
||||
"strength_clip": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 2.0, "step": 0.1}),
|
||||
"force_fetch": ("BOOLEAN", {"default": False}),
|
||||
"enable_preview": ("BOOLEAN", {"default": False}),
|
||||
"append_loraname_if_empty": ("BOOLEAN", {"default": False}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +117,13 @@ class LoraLoaderAdvanced:
|
||||
FUNCTION = "load_lora"
|
||||
CATEGORY = "autotrigger"
|
||||
|
||||
def load_lora(self, model, clip, lora_name, strength_model, strength_clip, force_fetch, enable_preview):
|
||||
def load_lora(self, model, clip, lora_name, strength_model, strength_clip, force_fetch, enable_preview, append_loraname_if_empty):
|
||||
meta_tags_list = sort_tags_by_frequency(get_metadata(lora_name["content"], "loras"))
|
||||
output_tags_list = load_and_save_tags(lora_name["content"], force_fetch)
|
||||
civitai_tags_list = load_and_save_tags(lora_name["content"], force_fetch)
|
||||
|
||||
civitai_tags_list = append_lora_name_if_empty(civitai_tags_list, lora_name["content"], append_loraname_if_empty)
|
||||
meta_tags_list = append_lora_name_if_empty(meta_tags_list, lora_name["content"], append_loraname_if_empty)
|
||||
|
||||
lora_path = folder_paths.get_full_path("loras", lora_name["content"])
|
||||
lora = None
|
||||
if self.loaded_lora is not None:
|
||||
@@ -133,10 +147,10 @@ class LoraLoaderAdvanced:
|
||||
"subfolder": "lora_preview",
|
||||
"type": "temp"
|
||||
}
|
||||
return {"ui": {"images": [preview_output]}, "result": (model_lora, clip_lora, output_tags_list, meta_tags_list)}
|
||||
return {"ui": {"images": [preview_output]}, "result": (model_lora, clip_lora, civitai_tags_list, meta_tags_list)}
|
||||
|
||||
|
||||
return (model_lora, clip_lora, output_tags_list, meta_tags_list)
|
||||
return (model_lora, clip_lora, civitai_tags_list, meta_tags_list)
|
||||
|
||||
class LoraLoaderStackedAdvanced:
|
||||
@classmethod
|
||||
@@ -149,6 +163,7 @@ class LoraLoaderStackedAdvanced:
|
||||
"lora_weight": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01}),
|
||||
"force_fetch": ("BOOLEAN", {"default": False}),
|
||||
"enable_preview": ("BOOLEAN", {"default": False}),
|
||||
"append_loraname_if_empty": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
"optional": {
|
||||
"lora_stack": ("LORA_STACK", ),
|
||||
@@ -161,12 +176,15 @@ class LoraLoaderStackedAdvanced:
|
||||
#OUTPUT_NODE = False
|
||||
CATEGORY = "autotrigger"
|
||||
|
||||
def set_stack(self, lora_name, lora_weight, force_fetch, enable_preview, lora_stack=None):
|
||||
def set_stack(self, lora_name, lora_weight, force_fetch, enable_preview, append_loraname_if_empty, lora_stack=None):
|
||||
civitai_tags_list = load_and_save_tags(lora_name["content"], force_fetch)
|
||||
|
||||
meta_tags = get_metadata(lora_name["content"], "loras")
|
||||
meta_tags_list = sort_tags_by_frequency(meta_tags)
|
||||
|
||||
civitai_tags_list = append_lora_name_if_empty(civitai_tags_list, lora_name["content"], append_loraname_if_empty)
|
||||
meta_tags_list = append_lora_name_if_empty(meta_tags_list, lora_name["content"], append_loraname_if_empty)
|
||||
|
||||
if lora_stack is not None:
|
||||
lora_stack.append((lora_name["content"],lora_weight,lora_weight,))
|
||||
else:
|
||||
|
||||
@@ -74,7 +74,7 @@ class TagsSelector:
|
||||
"tags_list": ("LIST", {"default": []}),
|
||||
"selector": ("STRING", {"default": ":"}),
|
||||
"weight": ("FLOAT", {"default": 1.0, "min": -10.0, "max": 10.0, "step": 0.01}),
|
||||
"ensure_coma": ("BOOLEAN", {"default": True})
|
||||
"ensure_comma": ("BOOLEAN", {"default": True})
|
||||
},
|
||||
"optional": {
|
||||
"prefix":("STRING", {"default":"", "forceInput": True}),
|
||||
@@ -86,11 +86,11 @@ class TagsSelector:
|
||||
FUNCTION = "select_tags"
|
||||
CATEGORY = "autotrigger"
|
||||
|
||||
def select_tags(self, tags_list, selector, weight, ensure_coma, prefix="", suffix=""):
|
||||
def select_tags(self, tags_list, selector, weight, ensure_comma, prefix="", suffix=""):
|
||||
if weight != 1.0:
|
||||
tags_list = [f"({tag}:{weight})" for tag in tags_list]
|
||||
output = parse_selector(selector, tags_list)
|
||||
if ensure_coma:
|
||||
if ensure_comma:
|
||||
striped_prefix = prefix.strip()
|
||||
striped_suffix = suffix.strip()
|
||||
if striped_prefix != "" and not striped_prefix.endswith(",") and output != "" and not output.startswith(","):
|
||||
|
||||
13
utils.py
13
utils.py
@@ -205,9 +205,20 @@ def parse_selector(selector, tags_list):
|
||||
if end < 0:
|
||||
end = len(tags_list) + end
|
||||
# clamp start and end values within list boundaries
|
||||
start, end = min(start, len(tags_list)-1), min(end, len(tags_list)-1)
|
||||
start, end = min(start, len(tags_list)), min(end, len(tags_list))
|
||||
start, end = max(start, 0), max(end, 0)
|
||||
# merge all
|
||||
for i in range(start, end):
|
||||
output[i] = tags_list[i]
|
||||
return ", ".join(list(output.values()))
|
||||
|
||||
def append_lora_name_if_empty(tags_list, lora_path, enabled):
|
||||
if not enabled or len(tags_list) > 0:
|
||||
return tags_list
|
||||
print("AAA : " + lora_path)
|
||||
filename = os.path.splitext(lora_path)[0]
|
||||
filename = os.path.basename(filename)
|
||||
print("BBB : " + filename)
|
||||
|
||||
tags_list.append(filename)
|
||||
return tags_list
|
||||
Reference in New Issue
Block a user