prompt expansion v2

This commit is contained in:
lvmin
2023-09-11 02:48:36 -07:00
parent e6557a4ded
commit 0f658a97f7
6 changed files with 28 additions and 13 deletions
+1 -1
View File
@@ -1 +1 @@
version = '1.0.66' version = '1.0.67'
+8 -3
View File
@@ -18,6 +18,7 @@ def worker():
from modules.sdxl_styles import apply_style_negative, apply_style_positive, aspect_ratios from modules.sdxl_styles import apply_style_negative, apply_style_positive, aspect_ratios
from modules.private_logger import log from modules.private_logger import log
from modules.expansion import safe_str from modules.expansion import safe_str
from modules.util import join_prompts
try: try:
async_gradio_app = shared.gradio_root async_gradio_app = shared.gradio_root
@@ -81,12 +82,16 @@ def worker():
outputs.append(['preview', (5, f'Preparing positive text #{i + 1} ...', None)]) outputs.append(['preview', (5, f'Preparing positive text #{i + 1} ...', None)])
current_seed = seed + i current_seed = seed + i
p_txt = apply_style_positive(style_selction, prompt) expansion_weight = 0.35
suffix = pipeline.expansion(p_txt, current_seed) suffix = pipeline.expansion(prompt, current_seed)
suffix = f'({suffix}:{expansion_weight})'
print(f'[Prompt Expansion] New suffix: {suffix}') print(f'[Prompt Expansion] New suffix: {suffix}')
p_txt = safe_str(p_txt) + suffix p_txt = apply_style_positive(style_selction, prompt)
p_txt = safe_str(p_txt)
p_txt = join_prompts(p_txt, suffix)
tasks.append(dict( tasks.append(dict(
prompt=prompt, prompt=prompt,
+2 -3
View File
@@ -6,8 +6,7 @@ from modules.path import fooocus_expansion_path
fooocus_magic_split = [ fooocus_magic_split = [
', extremely', ', extremely',
', trending', ', trending',
', intricate', ', intricate,',
# '. The',
] ]
dangrous_patterns = '[]【】()()|:' dangrous_patterns = '[]【】()()|:'
@@ -16,7 +15,7 @@ def safe_str(x):
x = str(x) x = str(x)
for _ in range(16): for _ in range(16):
x = x.replace(' ', ' ') x = x.replace(' ', ' ')
return x.rstrip(",. \r\n") return x.strip(",. \r\n")
def remove_pattern(x, pattern): def remove_pattern(x, pattern):
+4 -6
View File
@@ -1,3 +1,6 @@
from modules.util import join_prompts
# https://github.com/twri/sdxl_prompt_styler/blob/main/sdxl_styles.json # https://github.com/twri/sdxl_prompt_styler/blob/main/sdxl_styles.json
styles = [ styles = [
@@ -966,9 +969,4 @@ def apply_style_positive(style, txt):
def apply_style_negative(style, txt): def apply_style_negative(style, txt):
p, n = styles.get(style, default_style) p, n = styles.get(style, default_style)
if n == '': return join_prompts(n, txt)
return txt
elif txt == '':
return n
else:
return n + ', ' + txt
+9
View File
@@ -3,6 +3,15 @@ import random
import os import os
def join_prompts(*args, **kwargs):
prompts = [str(x) for x in args if str(x) != ""]
if len(prompts) == 0:
return ""
if len(prompts) == 1:
return prompts[0]
return ', '.join(prompts)
def generate_temp_filename(folder='./outputs/', extension='png'): def generate_temp_filename(folder='./outputs/', extension='png'):
current_time = datetime.datetime.now() current_time = datetime.datetime.now()
date_string = current_time.strftime("%Y-%m-%d") date_string = current_time.strftime("%Y-%m-%d")
+4
View File
@@ -1,3 +1,7 @@
### 1.0.67
* Use dynamic weighting and lower weights for prompt expansion.
### 1.0.64 ### 1.0.64
* Fixed a small OOM problem. * Fixed a small OOM problem.