From c1c0450c950e68f8a62ea76f3a5c2ed31dbce805 Mon Sep 17 00:00:00 2001 From: sn0w12 Date: Tue, 20 Feb 2024 19:45:59 +0100 Subject: [PATCH] prompt combine simplifier no longer removes tags in parentheses --- src/prompt_combine.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/prompt_combine.py b/src/prompt_combine.py index 8c11edb..23343b2 100644 --- a/src/prompt_combine.py +++ b/src/prompt_combine.py @@ -1,3 +1,5 @@ +import re + class CombineStringNode: @classmethod def INPUT_TYPES(cls): @@ -23,24 +25,35 @@ class CombineStringNode: # Configuration for special phrases special_phrases = { 'eye': { - 'remove': ['covering eyes', 'over eyes', 'covered eyes', 'covering face', 'covering own eyes', 'from behind', 'facing away'], + 'remove': ['covering eyes', 'over eyes', 'covered eyes', 'covering face', 'covering own eyes', 'facing away'], 'keep': ['looking at viewer'] }, 'sclera': { - 'remove': ['covering eyes', 'over eyes', 'covered eyes', 'covering face', 'covering own eyes', 'from behind', 'facing away'], + 'remove': ['covering eyes', 'over eyes', 'covered eyes', 'covering face', 'covering own eyes', 'facing away'], 'keep': ['looking at viewer'] }, 'mouth': { - 'remove': ['from behind', 'facing away'], + 'remove': ['facing away'], 'keep': ['looking at viewer'] }, 'teeth': { - 'remove': ['from behind', 'facing away'], + 'remove': ['facing away'], 'keep': ['looking at viewer'] }, } - tags = [tag.strip() for tag in tags_string.split(',')] + # Regular expression to match parenthesized parts + parenthesized_pattern = re.compile(r'\([^()]*\)') + parenthesized_parts = [] + + # Extract and temporarily remove parenthesized parts, storing their positions + def extract_parenthesized(match): + parenthesized_parts.append(match.group(0)) + return "\0" # Use a unique placeholder to mark the position + + modified_tags_string = re.sub(parenthesized_pattern, extract_parenthesized, tags_string) + + tags = [tag.strip() for tag in modified_tags_string.split(',')] final_tags = [] removed_tags = [] tag_map = {} @@ -93,8 +106,15 @@ class CombineStringNode: # Remove duplicates in the removed_tags list by converting it to a set and back to a list removed_tags = list(set(removed_tags)) - # Join the final list of tags back into a string - simplified_tags_string = ', '.join(final_tags) + # Reinsert parenthesized parts back into their original positions + final_tags_list = modified_tags_string.split(',') + final_tags_with_parentheses = [] + for tag in final_tags_list: + if "\0" in tag: # If placeholder is found, replace it with the original parenthesized part + tag = tag.replace("\0", parenthesized_parts.pop(0), 1) + final_tags_with_parentheses.append(tag.strip()) + + simplified_tags_string = ', '.join(final_tags_with_parentheses) return simplified_tags_string, removed_tags