Update negative_wildcard_processor.py with custom token processor node

This commit is contained in:
GrvBdgr
2024-11-15 20:32:06 +01:00
committed by GitHub
parent f562bbd6d6
commit c92ec030ec
+36 -3
View File
@@ -5,8 +5,8 @@ class NegativeWildcardProcessor:
def INPUT_TYPES(cls):
return {
"required": {
"positive" : ("STRING", {"default": "", "multiline": True}),
"negative" : ("STRING", {"default": "", "multiline": True})
"positive" : ("STRING", {"forceInput":True, "default": "", "multiline": True}),
"negative" : ("STRING", {"forceInput":True, "default": "", "multiline": True})
},
}
@@ -31,4 +31,37 @@ class NegativeWildcardProcessor:
for match in matches:
text_negative += " " + match
return (text_positive, text_negative,)
return (text_positive, text_negative,)
class CustomTokenPreprocessor:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"token" : ("STRING", {"default": "", "multiline": False}),
"source" : ("STRING", {"forceInput":True, "default": "", "multiline": True}),
"target" : ("STRING", {"forceInput":True, "default": "", "multiline": True})
},
}
RETURN_TYPES = ('STRING','STRING',)
RETURN_NAMES = ('processed_source','processed_target',)
FUNCTION = "process_custom_token"
CATEGORY = "Dynamic Prompts"
def process_custom_token(self, token, source, target):
# Pattern to match <! anything !>
pattern = r"<" + token + "(.*?)" + token + ">"
# Find all matches of the pattern in the positive string
matches = re.findall(pattern, source)
# Remove all occurrences of the pattern from the positive string
processed_source = re.sub(r"<" + token + ".*?" + token + ">", "", source)
# Append all matches to the end of the negative string
processed_target = target
for match in matches:
processed_target += " " + match
return (processed_source, processed_target,)