mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: add random style
This commit is contained in:
@@ -43,7 +43,7 @@ def worker():
|
|||||||
import fooocus_version
|
import fooocus_version
|
||||||
import args_manager
|
import args_manager
|
||||||
|
|
||||||
from modules.sdxl_styles import apply_style, apply_wildcards, fooocus_expansion, apply_arrays
|
from modules.sdxl_styles import apply_style, get_random_style, apply_wildcards, fooocus_expansion, apply_arrays, random_style_name
|
||||||
from modules.private_logger import log
|
from modules.private_logger import log
|
||||||
from extras.expansion import safe_str
|
from extras.expansion import safe_str
|
||||||
from modules.util import remove_empty_str, HWC3, resize_image, get_image_shape_ceil, set_image_shape_ceil, \
|
from modules.util import remove_empty_str, HWC3, resize_image, get_image_shape_ceil, set_image_shape_ceil, \
|
||||||
@@ -449,8 +449,12 @@ def worker():
|
|||||||
positive_basic_workloads = []
|
positive_basic_workloads = []
|
||||||
negative_basic_workloads = []
|
negative_basic_workloads = []
|
||||||
|
|
||||||
|
task_styles = style_selections.copy()
|
||||||
if use_style:
|
if use_style:
|
||||||
for s in style_selections:
|
for i, s in enumerate(task_styles):
|
||||||
|
if s == random_style_name:
|
||||||
|
s = get_random_style(task_rng)
|
||||||
|
task_styles[i] = s
|
||||||
p, n = apply_style(s, positive=task_prompt)
|
p, n = apply_style(s, positive=task_prompt)
|
||||||
positive_basic_workloads = positive_basic_workloads + p
|
positive_basic_workloads = positive_basic_workloads + p
|
||||||
negative_basic_workloads = negative_basic_workloads + n
|
negative_basic_workloads = negative_basic_workloads + n
|
||||||
@@ -478,6 +482,7 @@ def worker():
|
|||||||
negative_top_k=len(negative_basic_workloads),
|
negative_top_k=len(negative_basic_workloads),
|
||||||
log_positive_prompt='\n'.join([task_prompt] + task_extra_positive_prompts),
|
log_positive_prompt='\n'.join([task_prompt] + task_extra_positive_prompts),
|
||||||
log_negative_prompt='\n'.join([task_negative_prompt] + task_extra_negative_prompts),
|
log_negative_prompt='\n'.join([task_negative_prompt] + task_extra_negative_prompts),
|
||||||
|
styles=task_styles
|
||||||
))
|
))
|
||||||
|
|
||||||
if use_expansion:
|
if use_expansion:
|
||||||
@@ -842,7 +847,7 @@ def worker():
|
|||||||
d = [('Prompt', 'prompt', task['log_positive_prompt']),
|
d = [('Prompt', 'prompt', task['log_positive_prompt']),
|
||||||
('Negative Prompt', 'negative_prompt', task['log_negative_prompt']),
|
('Negative Prompt', 'negative_prompt', task['log_negative_prompt']),
|
||||||
('Fooocus V2 Expansion', 'prompt_expansion', task['expansion']),
|
('Fooocus V2 Expansion', 'prompt_expansion', task['expansion']),
|
||||||
('Styles', 'styles', str(raw_style_selections)),
|
('Styles', 'styles', str(task['styles'] if not use_expansion else [fooocus_expansion] + task['styles'])),
|
||||||
('Performance', 'performance', performance_selection.value)]
|
('Performance', 'performance', performance_selection.value)]
|
||||||
|
|
||||||
if performance_selection.steps() != steps:
|
if performance_selection.steps() != steps:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import math
|
|||||||
import modules.config
|
import modules.config
|
||||||
|
|
||||||
from modules.util import get_files_from_folder
|
from modules.util import get_files_from_folder
|
||||||
|
from random import Random
|
||||||
|
|
||||||
# cannot use modules.config - validators causing circular imports
|
# cannot use modules.config - 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/'))
|
||||||
@@ -50,8 +51,13 @@ for styles_file in styles_files:
|
|||||||
print(f'Failed to load style file {styles_file}')
|
print(f'Failed to load style file {styles_file}')
|
||||||
|
|
||||||
style_keys = list(styles.keys())
|
style_keys = list(styles.keys())
|
||||||
fooocus_expansion = "Fooocus V2"
|
fooocus_expansion = 'Fooocus V2'
|
||||||
legal_style_names = [fooocus_expansion] + style_keys
|
random_style_name = 'Random'
|
||||||
|
legal_style_names = [fooocus_expansion, random_style_name] + style_keys
|
||||||
|
|
||||||
|
|
||||||
|
def get_random_style(rng: Random) -> str:
|
||||||
|
return rng.choice(list(styles.items()))[0]
|
||||||
|
|
||||||
|
|
||||||
def apply_style(style, positive):
|
def apply_style(style, positive):
|
||||||
|
|||||||
Reference in New Issue
Block a user