mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
Fix trigger word toggle node
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import re
|
||||||
from server import PromptServer # type: ignore
|
from server import PromptServer # type: ignore
|
||||||
from .utils import FlexibleOptionalInputType, any_type
|
from .utils import FlexibleOptionalInputType, any_type
|
||||||
|
|
||||||
@@ -23,7 +24,8 @@ class TriggerWordToggle:
|
|||||||
RETURN_NAMES = ("filtered_trigger_words",)
|
RETURN_NAMES = ("filtered_trigger_words",)
|
||||||
FUNCTION = "process_trigger_words"
|
FUNCTION = "process_trigger_words"
|
||||||
|
|
||||||
def process_trigger_words(self, id, **kwargs):
|
def process_trigger_words(self, id, group_mode, **kwargs):
|
||||||
|
print("process_trigger_words kwargs: ", kwargs)
|
||||||
trigger_words = kwargs.get("trigger_words", "")
|
trigger_words = kwargs.get("trigger_words", "")
|
||||||
# Send trigger words to frontend
|
# Send trigger words to frontend
|
||||||
PromptServer.instance.send_sync("trigger_word_update", {
|
PromptServer.instance.send_sync("trigger_word_update", {
|
||||||
@@ -42,20 +44,33 @@ class TriggerWordToggle:
|
|||||||
if isinstance(trigger_data, str):
|
if isinstance(trigger_data, str):
|
||||||
trigger_data = json.loads(trigger_data)
|
trigger_data = json.loads(trigger_data)
|
||||||
|
|
||||||
# Create dictionaries to track active state of words
|
# Create dictionaries to track active state of words or groups
|
||||||
active_state = {item['text']: item.get('active', False) for item in trigger_data}
|
active_state = {item['text']: item.get('active', False) for item in trigger_data}
|
||||||
|
|
||||||
# Split original trigger words
|
if group_mode:
|
||||||
original_words = [word.strip() for word in trigger_words.split(',')]
|
# Split by two or more consecutive commas to get groups
|
||||||
|
groups = re.split(r',{2,}', trigger_words)
|
||||||
# Filter words: keep those not in toggle_trigger_words or those that are active
|
# Remove leading/trailing whitespace from each group
|
||||||
filtered_words = [word for word in original_words if word not in active_state or active_state[word]]
|
groups = [group.strip() for group in groups]
|
||||||
|
|
||||||
# Join them in the same format as input
|
# Filter groups: keep those not in toggle_trigger_words or those that are active
|
||||||
if filtered_words:
|
filtered_groups = [group for group in groups if group not in active_state or active_state[group]]
|
||||||
filtered_triggers = ', '.join(filtered_words)
|
|
||||||
|
if filtered_groups:
|
||||||
|
filtered_triggers = ', '.join(filtered_groups)
|
||||||
|
else:
|
||||||
|
filtered_triggers = ""
|
||||||
else:
|
else:
|
||||||
filtered_triggers = ""
|
# Original behavior for individual words mode
|
||||||
|
original_words = [word.strip() for word in trigger_words.split(',')]
|
||||||
|
# Filter out empty strings
|
||||||
|
original_words = [word for word in original_words if word]
|
||||||
|
filtered_words = [word for word in original_words if word not in active_state or active_state[word]]
|
||||||
|
|
||||||
|
if filtered_words:
|
||||||
|
filtered_triggers = ', '.join(filtered_words)
|
||||||
|
else:
|
||||||
|
filtered_triggers = ""
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing trigger words: {e}")
|
print(f"Error processing trigger words: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user