Skip to content

Commit 4a8cf01

Browse files
committed
remove duplicate code from #3970
1 parent e526f6b commit 4a8cf01

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

modules/api/api.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,7 @@ def progressapi(self, req: ProgressRequest = Depends()):
178178

179179
progress = min(progress, 1)
180180

181-
# copy from check_progress_call of ui.py
182-
183-
if shared.parallel_processing_allowed:
184-
if shared.state.sampling_step - shared.state.current_image_sampling_step >= shared.opts.show_progress_every_n_steps and shared.state.current_latent is not None:
185-
if shared.opts.show_progress_grid:
186-
shared.state.current_image = samples_to_image_grid(shared.state.current_latent)
187-
else:
188-
shared.state.current_image = sample_to_image(shared.state.current_latent)
189-
shared.state.current_image_sampling_step = shared.state.sampling_step
181+
shared.state.set_current_image()
190182

191183
current_image = None
192184
if shared.state.current_image and not req.skip_current_image:

modules/shared.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ def end(self):
184184

185185
devices.torch_gc()
186186

187+
"""sets self.current_image from self.current_latent if enough sampling steps have been made after the last call to this"""
188+
def set_current_image(self):
189+
if not parallel_processing_allowed:
190+
return
191+
192+
if self.sampling_step - self.current_image_sampling_step >= opts.show_progress_every_n_steps and self.current_latent is not None:
193+
if opts.show_progress_grid:
194+
self.current_image = sd_samplers.samples_to_image_grid(self.current_latent)
195+
else:
196+
self.current_image = sd_samplers.sample_to_image(self.current_latent)
197+
198+
self.current_image_sampling_step = self.sampling_step
199+
200+
187201
state = State()
188202

189203
artist_db = modules.artists.ArtistsDatabase(os.path.join(script_path, 'artists.csv'))

modules/ui.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,7 @@ def check_progress_call(id_part):
277277
preview_visibility = gr_show(False)
278278

279279
if opts.show_progress_every_n_steps > 0:
280-
if shared.parallel_processing_allowed:
281-
282-
if shared.state.sampling_step - shared.state.current_image_sampling_step >= opts.show_progress_every_n_steps and shared.state.current_latent is not None:
283-
if opts.show_progress_grid:
284-
shared.state.current_image = modules.sd_samplers.samples_to_image_grid(shared.state.current_latent)
285-
else:
286-
shared.state.current_image = modules.sd_samplers.sample_to_image(shared.state.current_latent)
287-
shared.state.current_image_sampling_step = shared.state.sampling_step
288-
280+
shared.state.set_current_image()
289281
image = shared.state.current_image
290282

291283
if image is None:

0 commit comments

Comments
 (0)