diff --git a/language/en.json b/language/en.json index f61255c9..241c5d54 100644 --- a/language/en.json +++ b/language/en.json @@ -50,6 +50,7 @@ "Seed": "Seed", "Disable seed increment": "Disable seed increment", "Disable automatic seed increment when image number is > 1.": "Disable automatic seed increment when image number is > 1.", + "Read wildcards in order": "Read wildcards in order", "\ud83d\udcda History Log": "\uD83D\uDCDA History Log", "Image Style": "Image Style", "Fooocus V2": "Fooocus V2", diff --git a/modules/async_worker.py b/modules/async_worker.py index c7df14f5..c5953a58 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -1,4 +1,5 @@ import threading +import re from modules.patch import PatchSettings, patch_settings, patch_all patch_all() @@ -148,6 +149,7 @@ def worker(): image_number = args.pop() output_format = args.pop() image_seed = args.pop() + read_wildcards_in_order = args.pop() sharpness = args.pop() guidance_scale = args.pop() base_model_name = args.pop() @@ -441,16 +443,16 @@ def worker(): for i in range(image_number): if disable_seed_increment: - task_seed = seed + task_seed = seed % (constants.MAX_SEED + 1) else: task_seed = (seed + i) % (constants.MAX_SEED + 1) # randint is inclusive, % is not task_rng = random.Random(task_seed) # may bind to inpaint noise in the future - task_prompt = apply_wildcards(prompt, task_rng) + task_prompt = apply_wildcards(prompt, task_rng, i, read_wildcards_in_order) task_prompt = apply_arrays(task_prompt, i) - task_negative_prompt = apply_wildcards(negative_prompt, task_rng) - task_extra_positive_prompts = [apply_wildcards(pmt, task_rng) for pmt in extra_positive_prompts] - task_extra_negative_prompts = [apply_wildcards(pmt, task_rng) for pmt in extra_negative_prompts] + task_negative_prompt = apply_wildcards(negative_prompt, task_rng, i, read_wildcards_in_order) + task_extra_positive_prompts = [apply_wildcards(pmt, task_rng, i, read_wildcards_in_order) for pmt in extra_positive_prompts] + task_extra_negative_prompts = [apply_wildcards(pmt, task_rng, i, read_wildcards_in_order) for pmt in extra_negative_prompts] positive_basic_workloads = [] negative_basic_workloads = [] diff --git a/modules/sdxl_styles.py b/modules/sdxl_styles.py index 0b07339c..77ad6b57 100644 --- a/modules/sdxl_styles.py +++ b/modules/sdxl_styles.py @@ -59,7 +59,7 @@ def apply_style(style, positive): return p.replace('{prompt}', positive).splitlines(), n.splitlines() -def apply_wildcards(wildcard_text, rng): +def apply_wildcards(wildcard_text, rng, i, read_wildcards_in_order): for _ in range(wildcards_max_bfs_depth): placeholders = re.findall(r'__([\w-]+)__', wildcard_text) if len(placeholders) == 0: @@ -72,7 +72,10 @@ def apply_wildcards(wildcard_text, rng): words = open(os.path.join(modules.config.path_wildcards, matches[0]), encoding='utf-8').read().splitlines() words = [x for x in words if x != ''] assert len(words) > 0 - wildcard_text = wildcard_text.replace(f'__{placeholder}__', rng.choice(words), 1) + if read_wildcards_in_order: + wildcard_text = wildcard_text.replace(f'__{placeholder}__', words[i % len(words)], 1) + else: + wildcard_text = wildcard_text.replace(f'__{placeholder}__', rng.choice(words), 1) except: print(f'[Wildcards] Warning: {placeholder}.txt missing or empty. ' f'Using "{placeholder}" as a normal word.') diff --git a/webui.py b/webui.py index 808db72d..ee7edc2d 100644 --- a/webui.py +++ b/webui.py @@ -434,6 +434,7 @@ with shared.gradio_root: disable_seed_increment = gr.Checkbox(label='Disable seed increment', info='Disable automatic seed increment when image number is > 1.', value=False) + read_wildcards_in_order = gr.Checkbox(label="Read wildcards in order", value=False) if not args_manager.args.disable_metadata: save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images, @@ -578,7 +579,8 @@ with shared.gradio_root: ctrls = [currentTask, generate_image_grid] ctrls += [ prompt, negative_prompt, style_selections, - performance_selection, aspect_ratios_selection, image_number, output_format, image_seed, sharpness, guidance_scale + performance_selection, aspect_ratios_selection, image_number, output_format, image_seed, + read_wildcards_in_order, sharpness, guidance_scale ] ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls