From 0db3c10c604930001a07208b612a589e0b7c958f Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Thu, 2 May 2024 22:20:18 +0200 Subject: [PATCH 1/3] feat: add random style --- modules/async_worker.py | 11 ++++++++--- modules/sdxl_styles.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index d8a1e072d..8d4f07373 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -43,7 +43,7 @@ def worker(): import fooocus_version 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 extras.expansion import safe_str from modules.util import remove_empty_str, HWC3, resize_image, get_image_shape_ceil, set_image_shape_ceil, \ @@ -449,8 +449,12 @@ def handler(async_task): positive_basic_workloads = [] negative_basic_workloads = [] + task_styles = style_selections.copy() 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) positive_basic_workloads = positive_basic_workloads + p negative_basic_workloads = negative_basic_workloads + n @@ -478,6 +482,7 @@ def handler(async_task): negative_top_k=len(negative_basic_workloads), log_positive_prompt='\n'.join([task_prompt] + task_extra_positive_prompts), log_negative_prompt='\n'.join([task_negative_prompt] + task_extra_negative_prompts), + styles=task_styles )) if use_expansion: @@ -842,7 +847,7 @@ def callback(step, x0, x, total_steps, y): d = [('Prompt', 'prompt', task['log_positive_prompt']), ('Negative Prompt', 'negative_prompt', task['log_negative_prompt']), ('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)] if performance_selection.steps() != steps: diff --git a/modules/sdxl_styles.py b/modules/sdxl_styles.py index 77ad6b574..135f4c64a 100644 --- a/modules/sdxl_styles.py +++ b/modules/sdxl_styles.py @@ -5,6 +5,7 @@ import modules.config from modules.util import get_files_from_folder +from random import Random # cannot use modules.config - validators causing circular imports styles_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../sdxl_styles/')) @@ -50,8 +51,13 @@ def normalize_key(k): print(f'Failed to load style file {styles_file}') style_keys = list(styles.keys()) -fooocus_expansion = "Fooocus V2" -legal_style_names = [fooocus_expansion] + style_keys +fooocus_expansion = 'Fooocus V2' +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): From 3027fafee3ae199c8ba478f09423ec712433f858 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Thu, 2 May 2024 22:32:18 +0200 Subject: [PATCH 2/3] feat: rename random to random style, add translation --- language/en.json | 1 + modules/sdxl_styles.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/language/en.json b/language/en.json index fefc79c47..5d19b8c1b 100644 --- a/language/en.json +++ b/language/en.json @@ -57,6 +57,7 @@ "\ud83d\udcda History Log": "\uD83D\uDCDA History Log", "Image Style": "Image Style", "Fooocus V2": "Fooocus V2", + "Random Style": "Random Style", "Default (Slightly Cinematic)": "Default (Slightly Cinematic)", "Fooocus Masterpiece": "Fooocus Masterpiece", "Fooocus Photograph": "Fooocus Photograph", diff --git a/modules/sdxl_styles.py b/modules/sdxl_styles.py index 135f4c64a..5b6afb590 100644 --- a/modules/sdxl_styles.py +++ b/modules/sdxl_styles.py @@ -52,7 +52,7 @@ def normalize_key(k): style_keys = list(styles.keys()) fooocus_expansion = 'Fooocus V2' -random_style_name = 'Random' +random_style_name = 'Random Style' legal_style_names = [fooocus_expansion, random_style_name] + style_keys From c64c7c3b91c7fe4fea43e1ff0322ac8a7093b7e3 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Thu, 2 May 2024 22:39:41 +0200 Subject: [PATCH 3/3] feat: add preview image for random style --- sdxl_styles/samples/random_style.jpg | Bin 0 -> 1454 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 sdxl_styles/samples/random_style.jpg diff --git a/sdxl_styles/samples/random_style.jpg b/sdxl_styles/samples/random_style.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9f685108fdcf78409e488d79cc2c245fec3ad06e GIT binary patch literal 1454 zcmex=ma3|jiIItm zOAI4iKMQ#V{6EAX$idLS(7?>7#K0uT$SlbC{|JLD$RAA1j3D1Y0V4+|6B|1#Gt2*5 z3>*;g^Do3AxHTA*=9V*ky#3T}oy+sk*U|b%zddvNE zjs=&Z%SwbAm^4hL-Cdy6?3sIuNrOSPVbg*AKu3xoxen?`u-ljfU~UG|c+@eYsWTH` zU}R=uW@TexVTYK&%*e#T%ErJh$RQx45GbsuWN1_<;^5fmRI=%^sH#D5V)7PfXfWC{ zJi9LSIQG`#nC#y2^(XXI?^Z;Avz7RIyRSOgMZUH3nbY2yHnV@~>-68Qc%R*KyfZ7) zap|iSSJV1uxP7e@zxd`%$m*@TPR3;IO)7b0SsH$7g0p4a`_TKo>#n^xnz>T6^Mc3K ztMX!wOizAq3>M?NQoeOZg3GQi>w~_!6zzBOk*?a%`TAR(&gnz<_Gv6wcf0tunx=T` z%O?(dZH~FsiK}b9pKm3r#&c_~!&@GY2E}vXzak8`#ytJ4lx+H0Z{^JEF0-~w-&1nH z^3bxwq3;;%3;*TE)vP$PYgxoy!BrRMIR*1Q>srbyzT?5)W0e~V{pRwmWD@n8S2jy# z1J46(TYX9CBiGe;=_|dzwdlF7xSq3n*Vn}C;+vBH8K!e-#_!fK`c;=2yJ78)lz`?| ze{t=l z^L=YTQN$6Mh5BKF!Xd}fpMLqXb$8nBVvc3(TyipVP2N5hzVyE2V&Ls<;k$ezPEQVe zvNtYE<@+)Dr)TD_wiK_snYC6fhEx2&>ah5q-*a*p*7O{n@l9!p(=tx+#azom|H|x6 zsZsxE&EM?b{Uh`5`ndBQHPYKm-dgh<`FCAb+rO57ul>^U``=1iIVS5>-B8}U=21#W zk)3Ci!jXBZ$1g_pebA?)`tFHA<+OT!! z`3ZKb7?n6@U*NcJ!mve9i6MdG=ACOixo%rmzUka+u;+JJTHvgTpV{tK z8+;Rk|$3d_P;TUH576 z^`5UqXIFY^hcCGLswaPQ^rE~Idp0gh{kqg|PDW4Z;ovSy;U#-*lAV@IG47Q*SNi<( z`#T-IE-t=;!Y+O(KUpB~{xXweGcK3SxGbe_56aGhh(ZaHO%ov5o)MS{L4_AC1;FAA Hq~In1cXT