From 4ace50435248d3ad12c526234074464623862ee9 Mon Sep 17 00:00:00 2001 From: alpertunga-bile Date: Wed, 28 Aug 2024 10:08:33 +0300 Subject: [PATCH] preprocess is updated --- preprocess.py | 18 ++++++------------ pyproject.toml | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/preprocess.py b/preprocess.py index 57cb0f8..e2a0f67 100644 --- a/preprocess.py +++ b/preprocess.py @@ -4,7 +4,7 @@ def remove_exact_keywords(line: str) -> list[str]: find_empty_parantheses_regex = compile(r"\(\s*\)") - remove_nonprompts_regex = compile(r"[^a-zA-Z()\[\]{}]*") + remove_nonprompts_regex = compile(r"[^a-zA-Z()_\-\[\]{}]*") remove_nonweighters_regex = compile(r"[()\[\]{}]*") remove_inside_regex = compile(r"[^()\[\]{}]*") @@ -20,7 +20,7 @@ def get_unique_list(sequence: list[str]) -> list[str]: prompts = get_unique_list(line.split(",")) pure_prompts = OrderedDict() # order matters, it contains prompts' original forms - extracted_pure_prompts = {} # order isn't important, it contains prompt keywords + extracted_pure_prompts = set() # order isn't important, it contains prompt keywords # remove exact keyword for prompt in prompts: @@ -28,7 +28,7 @@ def get_unique_list(sequence: list[str]) -> list[str]: "", prompt ).lstrip() # from -> ((masterpiece:1.2)) | to -> ((masterpiece)) - if tempPrompt == "": + if len(tempPrompt) == 0: continue tempPrompt = remove_nonweighters_regex.sub( @@ -42,8 +42,7 @@ def get_unique_list(sequence: list[str]) -> list[str]: if ( len(find_empty_parantheses_regex.findall(tempPrompt)) - > 0 # find () count - or tempPrompt == "" + > 0 # find balanced parantheses count ): # check balanced parantheses inner_parant_count = tempPrompt.count("(") @@ -67,12 +66,8 @@ def get_unique_list(sequence: list[str]) -> list[str]: continue - if tempPrompt == "": - tempPrompt = remove_nonprompts_regex.sub("", prompt).lstrip() - pure_prompts[tempPrompt] = True - else: - extracted_pure_prompts[tempPrompt] = True - pure_prompts[prompt] = True + extracted_pure_prompts.add(tempPrompt) + pure_prompts[prompt] = True return pure_prompts.keys() @@ -126,7 +121,6 @@ def preprocess(line: str) -> str: temp_line = ", ".join(remove_exact_keywords(temp_line)) temp_line = fix_commas(temp_line) - temp_line = fix_artifacts(temp_line) temp_line = remove_emptyprompts_regex.sub( diff --git a/pyproject.toml b/pyproject.toml index 6860f88..a695ca2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "image-caption-comfyui" description = "Using image caption models to extract prompts in ComfyUI" -version = "1.0.8" +version = "1.0.9" license = { text = "MIT License" } dependencies = [ "transformers",