diff --git a/negative_wildcard_processor.py b/negative_wildcard_processor.py index 569ae21..9537cdf 100644 --- a/negative_wildcard_processor.py +++ b/negative_wildcard_processor.py @@ -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,) \ No newline at end of file + 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 + 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,)