Added support for wildcards
This commit is contained in:
parent
0823b741a3
commit
eb72b16da0
@ -1 +1 @@
|
|||||||
version = '2.1.686'
|
version = '2.1.687'
|
||||||
|
@ -26,7 +26,7 @@ def worker():
|
|||||||
import modules.advanced_parameters as advanced_parameters
|
import modules.advanced_parameters as advanced_parameters
|
||||||
import fooocus_extras.ip_adapter as ip_adapter
|
import fooocus_extras.ip_adapter as ip_adapter
|
||||||
|
|
||||||
from modules.sdxl_styles import apply_style, aspect_ratios, fooocus_expansion
|
from modules.sdxl_styles import apply_style, apply_wildcards, aspect_ratios, fooocus_expansion
|
||||||
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, remove_empty_str, HWC3, resize_image, image_is_generated_in_current_ui, make_sure_that_image_is_not_too_large
|
from modules.util import join_prompts, remove_empty_str, HWC3, resize_image, image_is_generated_in_current_ui, make_sure_that_image_is_not_too_large
|
||||||
@ -227,44 +227,50 @@ def worker():
|
|||||||
pipeline.refresh_everything(refiner_model_name=refiner_model_name, base_model_name=base_model_name, loras=loras)
|
pipeline.refresh_everything(refiner_model_name=refiner_model_name, base_model_name=base_model_name, loras=loras)
|
||||||
|
|
||||||
progressbar(3, 'Processing prompts ...')
|
progressbar(3, 'Processing prompts ...')
|
||||||
positive_basic_workloads = []
|
tasks = []
|
||||||
negative_basic_workloads = []
|
for i in range(image_number):
|
||||||
|
task_seed = seed + i
|
||||||
|
task_prompt = apply_wildcards(prompt, task_seed)
|
||||||
|
|
||||||
if use_style:
|
positive_basic_workloads = []
|
||||||
for s in style_selections:
|
negative_basic_workloads = []
|
||||||
p, n = apply_style(s, positive=prompt)
|
|
||||||
positive_basic_workloads.append(p)
|
|
||||||
negative_basic_workloads.append(n)
|
|
||||||
else:
|
|
||||||
positive_basic_workloads.append(prompt)
|
|
||||||
|
|
||||||
negative_basic_workloads.append(negative_prompt) # Always use independent workload for negative.
|
if use_style:
|
||||||
|
for s in style_selections:
|
||||||
|
p, n = apply_style(s, positive=task_prompt)
|
||||||
|
positive_basic_workloads.append(p)
|
||||||
|
negative_basic_workloads.append(n)
|
||||||
|
else:
|
||||||
|
positive_basic_workloads.append(task_prompt)
|
||||||
|
|
||||||
positive_basic_workloads = positive_basic_workloads + extra_positive_prompts
|
negative_basic_workloads.append(negative_prompt) # Always use independent workload for negative.
|
||||||
negative_basic_workloads = negative_basic_workloads + extra_negative_prompts
|
|
||||||
|
|
||||||
positive_basic_workloads = remove_empty_str(positive_basic_workloads, default=prompt)
|
positive_basic_workloads = positive_basic_workloads + extra_positive_prompts
|
||||||
negative_basic_workloads = remove_empty_str(negative_basic_workloads, default=negative_prompt)
|
negative_basic_workloads = negative_basic_workloads + extra_negative_prompts
|
||||||
|
|
||||||
positive_top_k = len(positive_basic_workloads)
|
positive_basic_workloads = remove_empty_str(positive_basic_workloads, default=task_prompt)
|
||||||
negative_top_k = len(negative_basic_workloads)
|
negative_basic_workloads = remove_empty_str(negative_basic_workloads, default=negative_prompt)
|
||||||
|
|
||||||
tasks = [dict(
|
positive_top_k = len(positive_basic_workloads)
|
||||||
task_seed=seed + i,
|
negative_top_k = len(negative_basic_workloads)
|
||||||
positive=positive_basic_workloads,
|
|
||||||
negative=negative_basic_workloads,
|
tasks.append(dict(
|
||||||
expansion='',
|
task_seed=task_seed,
|
||||||
c=None,
|
task_prompt=task_prompt,
|
||||||
uc=None,
|
positive=positive_basic_workloads,
|
||||||
) for i in range(image_number)]
|
negative=negative_basic_workloads,
|
||||||
|
expansion='',
|
||||||
|
c=None,
|
||||||
|
uc=None
|
||||||
|
))
|
||||||
|
|
||||||
if use_expansion:
|
if use_expansion:
|
||||||
for i, t in enumerate(tasks):
|
for i, t in enumerate(tasks):
|
||||||
progressbar(5, f'Preparing Fooocus text #{i + 1} ...')
|
progressbar(5, f'Preparing Fooocus text #{i + 1} ...')
|
||||||
expansion = pipeline.final_expansion(prompt, t['task_seed'])
|
expansion = pipeline.final_expansion(t['task_prompt'], t['task_seed'])
|
||||||
print(f'[Prompt Expansion] New suffix: {expansion}')
|
print(f'[Prompt Expansion] New suffix: {expansion}')
|
||||||
t['expansion'] = expansion
|
t['expansion'] = expansion
|
||||||
t['positive'] = copy.deepcopy(t['positive']) + [join_prompts(prompt, expansion)] # Deep copy.
|
t['positive'] = copy.deepcopy(t['positive']) + [join_prompts(t['task_prompt'], expansion)] # Deep copy.
|
||||||
|
|
||||||
for i, t in enumerate(tasks):
|
for i, t in enumerate(tasks):
|
||||||
progressbar(7, f'Encoding positive #{i + 1} ...')
|
progressbar(7, f'Encoding positive #{i + 1} ...')
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
from modules.util import get_files_from_folder
|
from modules.util import get_files_from_folder
|
||||||
|
|
||||||
|
|
||||||
# cannot use modules.path - validators causing circular imports
|
# cannot use modules.path - validators causing circular imports
|
||||||
styles_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../sdxl_styles/'))
|
styles_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../sdxl_styles/'))
|
||||||
|
wildcards_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../wildcards/'))
|
||||||
|
|
||||||
|
|
||||||
default_styles_files = ['sdxl_styles_fooocus.json', 'sdxl_styles_sai.json', 'sdxl_styles_mre.json', 'sdxl_styles_twri.json', 'sdxl_styles_diva.json']
|
default_styles_files = ['sdxl_styles_fooocus.json', 'sdxl_styles_sai.json', 'sdxl_styles_mre.json', 'sdxl_styles_twri.json', 'sdxl_styles_diva.json']
|
||||||
@ -111,3 +115,18 @@ for k, (w, h) in SD_XL_BASE_RATIOS.items():
|
|||||||
def apply_style(style, positive):
|
def apply_style(style, positive):
|
||||||
p, n = styles[style]
|
p, n = styles[style]
|
||||||
return p.replace('{prompt}', positive), n
|
return p.replace('{prompt}', positive), n
|
||||||
|
|
||||||
|
|
||||||
|
def apply_wildcards(wildcard_text, seed=None, directory=wildcards_path):
|
||||||
|
placeholders = re.findall(r'__(\w+)__', wildcard_text)
|
||||||
|
for placeholder in placeholders:
|
||||||
|
try:
|
||||||
|
with open(os.path.join(directory, f'{placeholder}.txt')) as f:
|
||||||
|
words = f.read().splitlines()
|
||||||
|
f.close()
|
||||||
|
rng = random.Random(seed)
|
||||||
|
wildcard_text = re.sub(rf'__{placeholder}__', rng.choice(words), wildcard_text)
|
||||||
|
except IOError:
|
||||||
|
print(f'Error: could not open wildcard file {placeholder}.txt, using as normal word.')
|
||||||
|
wildcard_text = wildcard_text.replace(f'__{placeholder}__', placeholder)
|
||||||
|
return wildcard_text
|
||||||
|
@ -1,3 +1,17 @@
|
|||||||
|
# 2.1.687
|
||||||
|
|
||||||
|
* Added support for wildcards (using files from wildcards folder - try prompts like `__color__ sports car` with different seeds).
|
||||||
|
|
||||||
|
# 2.1.682
|
||||||
|
|
||||||
|
* Added support for custom styles (loaded from JSON files placed in sdxl_styles folder).
|
||||||
|
|
||||||
|
# 2.1.681
|
||||||
|
|
||||||
|
* Added support for generate hotkey (CTRL+ENTER).
|
||||||
|
* Added support for generate forever (RMB on Generate button).
|
||||||
|
* Added support for playing sound when generation is finished ('notification.ogg' or 'notification.mp3').
|
||||||
|
|
||||||
# 2.1.62
|
# 2.1.62
|
||||||
|
|
||||||
* Preset system. Added anime and realistic support.
|
* Preset system. Added anime and realistic support.
|
||||||
|
17
wildcards/color.txt
Normal file
17
wildcards/color.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
aqua
|
||||||
|
black
|
||||||
|
blue
|
||||||
|
fuchsia
|
||||||
|
gray
|
||||||
|
green
|
||||||
|
lime
|
||||||
|
maroon
|
||||||
|
navy
|
||||||
|
olive
|
||||||
|
orange
|
||||||
|
purple
|
||||||
|
red
|
||||||
|
silver
|
||||||
|
teal
|
||||||
|
white
|
||||||
|
yellow
|
Loading…
Reference in New Issue
Block a user