Skip to content

Commit 2913b9f

Browse files
Merge pull request #4178 from HeyImKyu/PreviewOnBatchCompletion
Added option to preview Created images on batch completion.
2 parents 17f9e55 + f1b6ac6 commit 2913b9f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

modules/shared.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def interrupt(self):
147147
self.interrupted = True
148148

149149
def nextjob(self):
150+
if opts.show_progress_every_n_steps == -1:
151+
self.do_set_current_image()
152+
150153
self.job_no += 1
151154
self.sampling_step = 0
152155
self.current_image_sampling_step = 0
@@ -187,17 +190,21 @@ def end(self):
187190

188191
"""sets self.current_image from self.current_latent if enough sampling steps have been made after the last call to this"""
189192
def set_current_image(self):
193+
if self.sampling_step - self.current_image_sampling_step >= opts.show_progress_every_n_steps and opts.show_progress_every_n_steps > 0:
194+
self.do_set_current_image()
195+
196+
def do_set_current_image(self):
190197
if not parallel_processing_allowed:
191198
return
199+
if self.current_latent is None:
200+
return
201+
202+
if opts.show_progress_grid:
203+
self.current_image = sd_samplers.samples_to_image_grid(self.current_latent)
204+
else:
205+
self.current_image = sd_samplers.sample_to_image(self.current_latent)
192206

193-
if self.sampling_step - self.current_image_sampling_step >= opts.show_progress_every_n_steps and self.current_latent is not None:
194-
if opts.show_progress_grid:
195-
self.current_image = sd_samplers.samples_to_image_grid(self.current_latent)
196-
else:
197-
self.current_image = sd_samplers.sample_to_image(self.current_latent)
198-
199-
self.current_image_sampling_step = self.sampling_step
200-
207+
self.current_image_sampling_step = self.sampling_step
201208

202209
state = State()
203210

@@ -352,7 +359,7 @@ def options_section(section_identifier, options_dict):
352359

353360
options_templates.update(options_section(('ui', "User interface"), {
354361
"show_progressbar": OptionInfo(True, "Show progressbar"),
355-
"show_progress_every_n_steps": OptionInfo(0, "Show image creation progress every N sampling steps. Set 0 to disable.", gr.Slider, {"minimum": 0, "maximum": 32, "step": 1}),
362+
"show_progress_every_n_steps": OptionInfo(0, "Show image creation progress every N sampling steps. Set to 0 to disable. Set to -1 to show after completion of batch.", gr.Slider, {"minimum": -1, "maximum": 32, "step": 1}),
356363
"show_progress_grid": OptionInfo(True, "Show previews of all images generated in a batch as a grid"),
357364
"return_grid": OptionInfo(True, "Show grid in results for web"),
358365
"do_not_show_images": OptionInfo(False, "Do not show any images in results for web"),

modules/ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def check_progress_call(id_part):
276276
image = gr_show(False)
277277
preview_visibility = gr_show(False)
278278

279-
if opts.show_progress_every_n_steps > 0:
279+
if opts.show_progress_every_n_steps != 0:
280280
shared.state.set_current_image()
281281
image = shared.state.current_image
282282

0 commit comments

Comments
 (0)