Skip to content

Commit 7e1728e

Browse files
committed
Added Style Iterator
1 parent ab02cf3 commit 7e1728e

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

modules/async_worker.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def worker():
3030
from PIL import Image, ImageOps
3131
from modules.settings import default_settings
3232
from modules.resolutions import annotate_resolution_string, get_resolution_string, resolutions, string_to_dimensions
33-
from modules.sdxl_styles import apply_style, apply_wildcards
33+
from modules.sdxl_styles import apply_style, apply_wildcards, style_keys
3434
from modules.private_logger import log
3535
from modules.expansion import safe_str
3636
from modules.util import join_prompts, remove_empty_str, HWC3, resize_image, image_is_generated_in_current_ui
@@ -80,18 +80,20 @@ def handler(task):
8080
freeu, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \
8181
input_image_checkbox, current_tab, \
8282
uov_method, uov_input_image, outpaint_selections, inpaint_input_image, \
83-
input_gallery, revision_gallery, keep_input_names = task
83+
use_style_iterator, input_gallery, revision_gallery, keep_input_names = task
8484

8585
outpaint_selections = [o.lower() for o in outpaint_selections]
8686

8787
loras = [(l1, w1), (l2, w2), (l3, w3), (l4, w4), (l5, w5)]
8888
loras_user_raw_input = copy.deepcopy(loras)
8989

90-
raw_style_selections = copy.deepcopy(style_selections)
90+
if use_style_iterator:
91+
style_iterator_pool = style_keys.copy()
92+
for s in style_selections:
93+
style_iterator_pool.remove(s)
9194

9295
uov_method = uov_method.lower()
9396

94-
use_style = len(style_selections) > 0
9597
modules.patch.sharpness = sharpness
9698
modules.patch.negative_adm = True
9799
initial_latent = None
@@ -353,8 +355,15 @@ def handler(task):
353355
task_seed = seed if same_seed_for_all else seed + i
354356
task_prompt = apply_wildcards(prompt, task_seed)
355357

358+
if use_style_iterator and i > 0: # original styles selection goes as 0th image
359+
task_style_selections = style_selections + [style_iterator_pool[i - 1]]
360+
else:
361+
task_style_selections = style_selections
362+
363+
use_style = len(task_style_selections) > 0
364+
356365
if use_style:
357-
for s in style_selections:
366+
for s in task_style_selections:
358367
p, n = apply_style(s, positive=task_prompt)
359368
positive_basic_workloads.append(p)
360369
negative_basic_workloads.append(n)
@@ -372,6 +381,7 @@ def handler(task):
372381
tasks.append(dict(
373382
task_seed=task_seed,
374383
prompt=task_prompt,
384+
style_selections=task_style_selections,
375385
positive=positive_basic_workloads,
376386
negative=negative_basic_workloads,
377387
positive_top_k=len(positive_basic_workloads),
@@ -510,7 +520,7 @@ def callback(step, x0, x, total_steps, y):
510520
print(f'Diffusion time: {execution_time:.2f} seconds')
511521

512522
metadata = {
513-
'prompt': raw_prompt, 'negative_prompt': raw_negative_prompt, 'styles': raw_style_selections,
523+
'prompt': raw_prompt, 'negative_prompt': raw_negative_prompt, 'styles': task['style_selections'],
514524
'real_prompt': task['positive'], 'real_negative_prompt': task['negative'],
515525
'seed': task['task_seed'], 'width': width, 'height': height,
516526
'sampler': sampler_name, 'scheduler': scheduler, 'performance': performance,
@@ -557,7 +567,7 @@ def callback(step, x0, x, total_steps, y):
557567
('Prompt', raw_prompt),
558568
('Negative Prompt', raw_negative_prompt),
559569
('Fooocus V2 (Prompt Expansion)', task['expansion']),
560-
('Styles', str(raw_style_selections)),
570+
('Styles', str(task['style_selections'])),
561571
('Real Prompt', task['positive']),
562572
('Real Negative Prompt', task['negative']),
563573
('Seed', task['task_seed']),

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Below things are already inside the software, and **users do not need to do anyt
191191
26. Support for wildcards (ported from RuinedFooocus - put them in wildcards folder, then try prompts like `__color__ sports car` with different seeds).
192192
27. Support for [FreeU](https://chenyangsi.top/FreeU/).
193193
28. Limited support for non-SDXL models (no refiner, Control-LoRAs, Revision, inpainting, outpainting).
194+
29. Style Iterator (iterates over selected style(s) combined with remaining styles - S1, S1 + S2, S1 + S3, S1 + S4, and so on; for comparing styles pick no initial style, and use same seed for all images).
194195

195196
## Thanks
196197

update_log_mre.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 2.0.78.5 MRE
22

3+
* Added Style Iterator.
34
* Removed meta tensor usage.
45

56
### 2.0.78.4 MRE

webui.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,10 @@ def clear_default_image():
385385
custom_switch = gr.Slider(label='Custom Switch', minimum=0.2, maximum=1.0, step=0.01, value=settings['custom_switch'])
386386
resolution = gr.Dropdown(label='Resolution (width × height)', choices=list(resolutions.keys()), value=settings['resolution'], allow_custom_value=True)
387387
style_selections = gr.Dropdown(label='Image Style(s)', choices=style_keys, value=settings['styles'], multiselect=True, max_choices=8)
388-
prompt_expansion = gr.Checkbox(label=fooocus_expansion, value=settings['prompt_expansion'])
389-
image_number = gr.Slider(label='Image Number', minimum=1, maximum=128, step=1, value=settings['image_number'])
388+
with gr.Row():
389+
prompt_expansion = gr.Checkbox(label=fooocus_expansion, value=settings['prompt_expansion'])
390+
style_iterator = gr.Checkbox(label='Style Iterator', value=False)
391+
image_number = gr.Slider(label='Image Number', minimum=1, maximum=256, step=1, value=settings['image_number'])
390392
negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="What you don't want to see.", value=settings['negative_prompt'])
391393
with gr.Row():
392394
seed_random = gr.Checkbox(label='Random', value=settings['seed_random'])
@@ -425,6 +427,23 @@ def performance_changed(value):
425427

426428
performance.change(fn=performance_changed, inputs=[performance], outputs=[custom_row])
427429

430+
def style_iterator_changed(_style_iterator, _style_selections):
431+
if _style_iterator:
432+
combinations_count = 1 + len(style_keys) - len(_style_selections) # original style selection + all remaining style combinations
433+
return gr.update(interactive=False, value=combinations_count)
434+
else:
435+
return gr.update(interactive=True, value=settings['image_number'])
436+
437+
def style_selections_changed(_style_iterator, _style_selections):
438+
if _style_iterator:
439+
combinations_count = 1 + len(style_keys) - len(_style_selections) # original style selection + all remaining style combinations
440+
return gr.update(value=combinations_count)
441+
else:
442+
return gr.update()
443+
444+
style_iterator.change(style_iterator_changed, inputs=[style_iterator, style_selections], outputs=[image_number])
445+
style_selections.change(style_selections_changed, inputs=[style_iterator, style_selections], outputs=[image_number])
446+
428447
with gr.Tab(label='Image-2-Image'):
429448
revision_mode = gr.Checkbox(label='Revision (prompting with images)', value=settings['revision_mode'])
430449
revision_strength_1 = gr.Slider(label='Revision Strength for Image 1', minimum=-2, maximum=2, step=0.01,
@@ -611,6 +630,7 @@ def verify_input(img2img, canny, depth, gallery_in, gallery_rev, gallery_out):
611630
ctrls += [input_image_checkbox, current_tab]
612631
ctrls += [uov_method, uov_input_image]
613632
ctrls += [outpaint_selections, inpaint_input_image]
633+
ctrls += [style_iterator]
614634
generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, generate_button, output_gallery]) \
615635
.then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \
616636
.then(fn=verify_enhance_image, inputs=[input_image_checkbox, img2img_mode], outputs=[img2img_mode]) \

0 commit comments

Comments
 (0)