@@ -44,7 +44,7 @@ def worker():
44
44
import modules .virtual_memory as virtual_memory
45
45
46
46
from modules .resolutions import get_resolution_string , resolutions
47
- from modules .sdxl_styles import apply_style
47
+ from modules .sdxl_styles import apply_style , apply_wildcards
48
48
from modules .private_logger import log
49
49
from modules .expansion import safe_str
50
50
from modules .util import join_prompts , remove_empty_str
@@ -154,68 +154,72 @@ def handler(task):
154
154
155
155
156
156
progressbar (5 , 'Processing prompts ...' )
157
+ tasks = []
158
+ for i in range (image_number ):
159
+ positive_basic_workloads = []
160
+ negative_basic_workloads = []
161
+ task_seed = seed if same_seed_for_all else seed + i
162
+ task_prompt = apply_wildcards (prompt , task_seed )
163
+
164
+ if use_style :
165
+ for s in style_selections :
166
+ p , n = apply_style (s , positive = task_prompt )
167
+ positive_basic_workloads .append (p )
168
+ negative_basic_workloads .append (n )
169
+ else :
170
+ positive_basic_workloads .append (task_prompt )
171
+
172
+ negative_basic_workloads .append (negative_prompt ) # Always use independent workload for negative.
157
173
158
- positive_basic_workloads = []
159
- negative_basic_workloads = []
160
-
161
- if use_style :
162
- for s in style_selections :
163
- p , n = apply_style (s , positive = prompt )
164
- positive_basic_workloads .append (p )
165
- negative_basic_workloads .append (n )
166
- else :
167
- positive_basic_workloads .append (prompt )
168
-
169
- negative_basic_workloads .append (negative_prompt ) # Always use independent workload for negative.
170
-
171
- positive_basic_workloads = positive_basic_workloads + extra_positive_prompts
172
- negative_basic_workloads = negative_basic_workloads + extra_negative_prompts
174
+ positive_basic_workloads = positive_basic_workloads + extra_positive_prompts
175
+ negative_basic_workloads = negative_basic_workloads + extra_negative_prompts
173
176
174
- positive_basic_workloads = remove_empty_str (positive_basic_workloads , default = prompt )
175
- negative_basic_workloads = remove_empty_str (negative_basic_workloads , default = negative_prompt )
177
+ positive_basic_workloads = remove_empty_str (positive_basic_workloads , default = task_prompt )
178
+ negative_basic_workloads = remove_empty_str (negative_basic_workloads , default = negative_prompt )
176
179
177
- positive_top_k = len (positive_basic_workloads )
178
- negative_top_k = len (negative_basic_workloads )
180
+ tasks .append (dict (
181
+ task_seed = task_seed ,
182
+ prompt = task_prompt ,
183
+ positive = positive_basic_workloads ,
184
+ negative = negative_basic_workloads ,
185
+ positive_top_k = len (positive_basic_workloads ),
186
+ negative_top_k = len (negative_basic_workloads ),
187
+ expansion = '' ,
188
+ c = [None , None ],
189
+ uc = [None , None ]
190
+ ))
179
191
180
- tasks = [dict (
181
- task_seed = seed if same_seed_for_all else seed + i ,
182
- positive = positive_basic_workloads ,
183
- negative = negative_basic_workloads ,
184
- expansion = '' ,
185
- c = [None , None ],
186
- uc = [None , None ],
187
- ) for i in range (image_number )]
188
192
189
193
if use_expansion :
190
194
for i , t in enumerate (tasks ):
191
195
progressbar (5 , f'Preparing Fooocus text #{ i + 1 } ...' )
192
- expansion = pipeline .expansion (prompt , t ['task_seed' ])
196
+ expansion = pipeline .expansion (t [ ' prompt' ] , t ['task_seed' ])
193
197
print (f'[Prompt Expansion] New suffix: { expansion } ' )
194
198
t ['expansion' ] = expansion
195
- t ['positive' ] = copy .deepcopy (t ['positive' ]) + [join_prompts (prompt , expansion )] # Deep copy.
199
+ t ['positive' ] = copy .deepcopy (t ['positive' ]) + [join_prompts (t [ ' prompt' ] , expansion )] # Deep copy.
196
200
197
201
for i , t in enumerate (tasks ):
198
202
progressbar (7 , f'Encoding base positive #{ i + 1 } ...' )
199
203
t ['c' ][0 ] = pipeline .clip_encode (sd = pipeline .xl_base_patched , texts = t ['positive' ],
200
- pool_top_k = positive_top_k )
204
+ pool_top_k = t [ ' positive_top_k' ] )
201
205
202
206
for i , t in enumerate (tasks ):
203
207
progressbar (9 , f'Encoding base negative #{ i + 1 } ...' )
204
208
t ['uc' ][0 ] = pipeline .clip_encode (sd = pipeline .xl_base_patched , texts = t ['negative' ],
205
- pool_top_k = negative_top_k )
209
+ pool_top_k = t [ ' negative_top_k' ] )
206
210
207
211
if pipeline .xl_refiner is not None :
208
212
virtual_memory .load_from_virtual_memory (pipeline .xl_refiner .clip .cond_stage_model )
209
213
210
214
for i , t in enumerate (tasks ):
211
215
progressbar (11 , f'Encoding refiner positive #{ i + 1 } ...' )
212
216
t ['c' ][1 ] = pipeline .clip_encode (sd = pipeline .xl_refiner , texts = t ['positive' ],
213
- pool_top_k = positive_top_k )
217
+ pool_top_k = t [ ' positive_top_k' ] )
214
218
215
219
for i , t in enumerate (tasks ):
216
220
progressbar (13 , f'Encoding refiner negative #{ i + 1 } ...' )
217
221
t ['uc' ][1 ] = pipeline .clip_encode (sd = pipeline .xl_refiner , texts = t ['negative' ],
218
- pool_top_k = negative_top_k )
222
+ pool_top_k = t [ ' negative_top_k' ] )
219
223
220
224
virtual_memory .try_move_to_virtual_memory (pipeline .xl_refiner .clip .cond_stage_model )
221
225
@@ -307,6 +311,7 @@ def callback(step, x0, x, total_steps, y):
307
311
308
312
metadata = {
309
313
'prompt' : raw_prompt , 'negative_prompt' : raw_negative_prompt , 'styles' : raw_style_selections ,
314
+ 'real_prompt' : task ['positive' ], 'real_negative_prompt' : task ['negative' ],
310
315
'seed' : task ['task_seed' ], 'width' : width , 'height' : height ,
311
316
'sampler' : sampler_name , 'scheduler' : scheduler , 'performance' : performance ,
312
317
'steps' : steps , 'switch' : switch , 'sharpness' : sharpness , 'cfg' : cfg ,
@@ -348,6 +353,8 @@ def callback(step, x0, x, total_steps, y):
348
353
('Negative Prompt' , raw_negative_prompt ),
349
354
('Fooocus V2 (Prompt Expansion)' , task ['expansion' ]),
350
355
('Styles' , str (raw_style_selections )),
356
+ ('Real Prompt' , task ['positive' ]),
357
+ ('Real Negative Prompt' , task ['negative' ]),
351
358
('Seed' , task ['task_seed' ]),
352
359
('Resolution' , get_resolution_string (width , height )),
353
360
('Performance' , (performance , steps , switch )),
0 commit comments