Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask #1

Merged
merged 6 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
合并通配符顺序读取2.1.861 (lllyasviel#15)
* 通配符增强,切换顺序读取

通配符增强,通过勾选切换通配符读取方法,默认不勾选为随机读取一行,勾选后为按顺序读取,并使用相同的种子。

* 代码来自刁璐璐

* update

* Update async_worker.py
  • Loading branch information
xhoxye authored Jan 8, 2024
commit 8c05b81afca3fbad12aa51b82ca13ee938bc4b4c
22 changes: 16 additions & 6 deletions modules/async_worker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import threading
import re


class AsyncTask:
Expand Down Expand Up @@ -126,6 +127,7 @@ def handler(async_task):
aspect_ratios_selection = args.pop()
image_number = args.pop()
image_seed = args.pop()
read_wildcard_in_order_checkbox = args.pop()
sharpness = args.pop()
guidance_scale = args.pop()
base_model_name = args.pop()
Expand Down Expand Up @@ -377,13 +379,21 @@ def handler(async_task):
progressbar(async_task, 3, 'Processing prompts ...')
tasks = []
for i in range(image_number):
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

# determines that if prompt includes wildcard, this seed will not be increased automatically
placeholders = re.findall(r'__([\w-]+)__', prompt)
random_seed = (seed + i) % (constants.MAX_SEED + 1) # randint is inclusive, % is not
# Determine whether there is a wildcard and the value of the checkbox is True
if len(placeholders) > 0 and read_wildcard_in_order_checkbox:
task_seed = seed % (constants.MAX_SEED + 1) # If there are wildcard characters in the prompt and the value of the check box is True, the seed will not increase automatically.
else:
task_seed = random_seed
task_rng = random.Random(random_seed) # may bind to inpaint noise in the future
task_prompt = apply_wildcards(prompt, task_rng,i,read_wildcard_in_order_checkbox)
task_negative_prompt = apply_wildcards(negative_prompt, task_rng,i,read_wildcard_in_order_checkbox)
task_extra_positive_prompts = [apply_wildcards(pmt, task_rng,i,read_wildcard_in_order_checkbox) for pmt in extra_positive_prompts]
task_extra_negative_prompts = [apply_wildcards(pmt, task_rng,i,read_wildcard_in_order_checkbox) for pmt in extra_negative_prompts]

task_prompt = apply_wildcards(prompt, task_rng)
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]

positive_basic_workloads = []
negative_basic_workloads = []
Expand Down
12 changes: 10 additions & 2 deletions modules/sdxl_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def apply_style(style, positive):
return p.replace('{prompt}', positive).splitlines(), n.splitlines()


def apply_wildcards(wildcard_text, rng, directory=wildcards_path):
def apply_wildcards(wildcard_text, rng, i, read_wildcard_in_order_checkbox, directory=wildcards_path):
for _ in range(wildcards_max_bfs_depth):
placeholders = re.findall(r'__([\w-]+)__', wildcard_text)
if len(placeholders) == 0:
Expand All @@ -71,7 +71,15 @@ def apply_wildcards(wildcard_text, rng, directory=wildcards_path):
words = open(os.path.join(directory, f'{placeholder}.txt'), 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)
#wildcard_text = wildcard_text.replace(f'__{placeholder}__', rng.choice(words), 1)
# if checked, read in order, if not checked, read randomly
if len(words) > i and read_wildcard_in_order_checkbox:
wildcard_text = wildcard_text.replace(f'__{placeholder}__', words[i % len(words)], 1)
elif len(words) <= i and read_wildcard_in_order_checkbox:
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.')
Expand Down
4 changes: 3 additions & 1 deletion webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def refresh_seed(r, seed_string):
seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed],
queue=False, show_progress=False)

read_wildcard_in_order_checkbox = gr.Checkbox(label="Read wildcard in order with same seed", value=False)

if not args_manager.args.disable_image_log:
gr.HTML(f'<a href="/file={get_current_html_path()}" target="_blank">\U0001F4DA History Log</a>')

Expand Down Expand Up @@ -579,7 +581,7 @@ def inpaint_mode_change(mode):

ctrls = [
prompt, negative_prompt, style_selections,
performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
performance_selection, aspect_ratios_selection, image_number, image_seed, read_wildcard_in_order_checkbox, sharpness, guidance_scale
]

ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls
Expand Down