@@ -2180,12 +2180,14 @@ def handle_dynamic_prompt_variants(prompt, repeat_count):
2180
2180
enumerating = False
2181
2181
replacers = []
2182
2182
for found in founds :
2183
+ # if "e$$" is found, enumerate all variants
2183
2184
found_enumerating = found .group (2 ) is not None
2184
2185
enumerating = enumerating or found_enumerating
2185
2186
2186
- separater = ", " if found .group (6 ) is None else found .group (6 )
2187
+ separator = ", " if found .group (6 ) is None else found .group (6 )
2187
2188
variants = found .group (7 ).split ("|" )
2188
2189
2190
+ # parse count range
2189
2191
count_range = found .group (4 )
2190
2192
if count_range is None :
2191
2193
count_range = [1 , 1 ]
@@ -2206,7 +2208,7 @@ def handle_dynamic_prompt_variants(prompt, repeat_count):
2206
2208
count_range [1 ] = len (variants )
2207
2209
2208
2210
if found_enumerating :
2209
- # make all combinations
2211
+ # make function to enumerate all combinations
2210
2212
def make_replacer_enum (vari , cr , sep ):
2211
2213
def replacer ():
2212
2214
values = []
@@ -2217,9 +2219,9 @@ def replacer():
2217
2219
2218
2220
return replacer
2219
2221
2220
- replacers .append (make_replacer_enum (variants , count_range , separater ))
2222
+ replacers .append (make_replacer_enum (variants , count_range , separator ))
2221
2223
else :
2222
- # make random combinations
2224
+ # make function to choose random combinations
2223
2225
def make_replacer_single (vari , cr , sep ):
2224
2226
def replacer ():
2225
2227
count = random .randint (cr [0 ], cr [1 ])
@@ -2228,27 +2230,33 @@ def replacer():
2228
2230
2229
2231
return replacer
2230
2232
2231
- replacers .append (make_replacer_single (variants , count_range , separater ))
2233
+ replacers .append (make_replacer_single (variants , count_range , separator ))
2232
2234
2233
2235
# make each prompt
2234
- if not enumerating :
2236
+ if not enumerating :
2237
+ # if not enumerating, repeat the prompt, replace each variant randomly
2235
2238
prompts = []
2236
2239
for _ in range (repeat_count ):
2237
2240
current = prompt
2238
2241
for found , replacer in zip (founds , replacers ):
2239
2242
current = current .replace (found .group (0 ), replacer ()[0 ])
2240
2243
prompts .append (current )
2241
2244
else :
2245
+ # if enumerating, iterate all combinations for previous prompts
2242
2246
prompts = [prompt ]
2247
+
2243
2248
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
2245
2251
new_prompts = []
2246
2252
for current in prompts :
2247
2253
replecements = replacer ()
2248
2254
for replecement in replecements :
2249
2255
new_prompts .append (current .replace (found .group (0 ), replecement ))
2250
2256
prompts = new_prompts
2257
+
2251
2258
for found , replacer in zip (founds , replacers ):
2259
+ # make random selection for existing prompts
2252
2260
if found .group (2 ) is None :
2253
2261
for i in range (len (prompts )):
2254
2262
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):
3166
3174
else :
3167
3175
raw_prompt = prompt_list [prompt_index ]
3168
3176
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)
3170
3179
raw_prompts = handle_dynamic_prompt_variants (raw_prompt , args .images_per_prompt )
3171
3180
3172
3181
# repeat prompt
0 commit comments