Skip to content

Commit

Permalink
preprocess is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
alpertunga-bile committed Aug 28, 2024
1 parent 3d359f5 commit 4ace504
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"[^()\[\]{}]*")

Expand All @@ -20,15 +20,15 @@ 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:
tempPrompt = remove_nonprompts_regex.sub(
"", prompt
).lstrip() # from -> ((masterpiece:1.2)) | to -> ((masterpiece))

if tempPrompt == "":
if len(tempPrompt) == 0:
continue

tempPrompt = remove_nonweighters_regex.sub(
Expand All @@ -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("(")
Expand All @@ -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()

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 4ace504

Please sign in to comment.