Skip to content

Commit f2989b3

Browse files
committed
fix typos, add comment
1 parent 624fbad commit f2989b3

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

gen_img_diffusers.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -2180,12 +2180,14 @@ def handle_dynamic_prompt_variants(prompt, repeat_count):
21802180
enumerating = False
21812181
replacers = []
21822182
for found in founds:
2183+
# if "e$$" is found, enumerate all variants
21832184
found_enumerating = found.group(2) is not None
21842185
enumerating = enumerating or found_enumerating
21852186

2186-
separater = ", " if found.group(6) is None else found.group(6)
2187+
separator = ", " if found.group(6) is None else found.group(6)
21872188
variants = found.group(7).split("|")
21882189

2190+
# parse count range
21892191
count_range = found.group(4)
21902192
if count_range is None:
21912193
count_range = [1, 1]
@@ -2206,7 +2208,7 @@ def handle_dynamic_prompt_variants(prompt, repeat_count):
22062208
count_range[1] = len(variants)
22072209

22082210
if found_enumerating:
2209-
# make all combinations
2211+
# make function to enumerate all combinations
22102212
def make_replacer_enum(vari, cr, sep):
22112213
def replacer():
22122214
values = []
@@ -2217,9 +2219,9 @@ def replacer():
22172219

22182220
return replacer
22192221

2220-
replacers.append(make_replacer_enum(variants, count_range, separater))
2222+
replacers.append(make_replacer_enum(variants, count_range, separator))
22212223
else:
2222-
# make random combinations
2224+
# make function to choose random combinations
22232225
def make_replacer_single(vari, cr, sep):
22242226
def replacer():
22252227
count = random.randint(cr[0], cr[1])
@@ -2228,27 +2230,33 @@ def replacer():
22282230

22292231
return replacer
22302232

2231-
replacers.append(make_replacer_single(variants, count_range, separater))
2233+
replacers.append(make_replacer_single(variants, count_range, separator))
22322234

22332235
# make each prompt
2234-
if not enumerating:
2236+
if not enumerating:
2237+
# if not enumerating, repeat the prompt, replace each variant randomly
22352238
prompts = []
22362239
for _ in range(repeat_count):
22372240
current = prompt
22382241
for found, replacer in zip(founds, replacers):
22392242
current = current.replace(found.group(0), replacer()[0])
22402243
prompts.append(current)
22412244
else:
2245+
# if enumerating, iterate all combinations for previous prompts
22422246
prompts = [prompt]
2247+
22432248
for found, replacer in zip(founds, replacers):
2244-
if found.group(2) is not None: # enumerating
2249+
if found.group(2) is not None:
2250+
# make all combinations for existing prompts
22452251
new_prompts = []
22462252
for current in prompts:
22472253
replecements = replacer()
22482254
for replecement in replecements:
22492255
new_prompts.append(current.replace(found.group(0), replecement))
22502256
prompts = new_prompts
2257+
22512258
for found, replacer in zip(founds, replacers):
2259+
# make random selection for existing prompts
22522260
if found.group(2) is None:
22532261
for i in range(len(prompts)):
22542262
prompts[i] = prompts[i].replace(found.group(0), replacer()[0])
@@ -3166,7 +3174,8 @@ def process_batch(batch: List[BatchData], highres_fix, highres_1st=False):
31663174
else:
31673175
raw_prompt = prompt_list[prompt_index]
31683176

3169-
# sd-dynamic-prompts like variants: count is 1 or images_per_prompt or arbitrary
3177+
# sd-dynamic-prompts like variants:
3178+
# count is 1 (not dynamic) or images_per_prompt (no enumeration) or arbitrary (enumeration)
31703179
raw_prompts = handle_dynamic_prompt_variants(raw_prompt, args.images_per_prompt)
31713180

31723181
# repeat prompt

0 commit comments

Comments
 (0)