Skip to content

Commit 5f36f6a

Browse files
Merge pull request AUTOMATIC1111#14009 from AUTOMATIC1111/Option-to-show-batch-img2img-results-in-UI
Option to show batch img2img results in UI
2 parents 1463cea + dea5e43 commit 5f36f6a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

modules/img2img.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
4444
steps = p.steps
4545
override_settings = p.override_settings
4646
sd_model_checkpoint_override = get_closet_checkpoint_match(override_settings.get("sd_model_checkpoint", None))
47+
batch_results = None
48+
discard_further_results = False
4749
for i, image in enumerate(images):
4850
state.job = f"{i+1} out of {len(images)}"
4951
if state.skipped:
@@ -127,7 +129,21 @@ def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args, to_scale=Fal
127129

128130
if proc is None:
129131
p.override_settings.pop('save_images_replace_action', None)
130-
process_images(p)
132+
proc = process_images(p)
133+
134+
if not discard_further_results and proc:
135+
if batch_results:
136+
batch_results.images.extend(proc.images)
137+
batch_results.infotexts.extend(proc.infotexts)
138+
else:
139+
batch_results = proc
140+
141+
if 0 <= shared.opts.img2img_batch_show_results_limit < len(batch_results.images):
142+
discard_further_results = True
143+
batch_results.images = batch_results.images[:int(shared.opts.img2img_batch_show_results_limit)]
144+
batch_results.infotexts = batch_results.infotexts[:int(shared.opts.img2img_batch_show_results_limit)]
145+
146+
return batch_results
131147

132148

133149
def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_styles, init_img, sketch, init_img_with_mask, inpaint_color_sketch, inpaint_color_sketch_orig, init_img_inpaint, init_mask_inpaint, steps: int, sampler_name: str, mask_blur: int, mask_alpha: float, inpainting_fill: int, n_iter: int, batch_size: int, cfg_scale: float, image_cfg_scale: float, denoising_strength: float, selected_scale_tab: int, height: int, width: int, scale_by: float, resize_mode: int, inpaint_full_res: bool, inpaint_full_res_padding: int, inpainting_mask_invert: int, img2img_batch_input_dir: str, img2img_batch_output_dir: str, img2img_batch_inpaint_mask_dir: str, override_settings_texts, img2img_batch_use_png_info: bool, img2img_batch_png_info_props: list, img2img_batch_png_info_dir: str, request: gr.Request, *args):
@@ -212,10 +228,10 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s
212228
with closing(p):
213229
if is_batch:
214230
assert not shared.cmd_opts.hide_ui_dir_config, "Launched with --hide-ui-dir-config, batch img2img disabled"
231+
processed = process_batch(p, img2img_batch_input_dir, img2img_batch_output_dir, img2img_batch_inpaint_mask_dir, args, to_scale=selected_scale_tab == 1, scale_by=scale_by, use_png_info=img2img_batch_use_png_info, png_info_props=img2img_batch_png_info_props, png_info_dir=img2img_batch_png_info_dir)
215232

216-
process_batch(p, img2img_batch_input_dir, img2img_batch_output_dir, img2img_batch_inpaint_mask_dir, args, to_scale=selected_scale_tab == 1, scale_by=scale_by, use_png_info=img2img_batch_use_png_info, png_info_props=img2img_batch_png_info_props, png_info_dir=img2img_batch_png_info_dir)
217-
218-
processed = Processed(p, [], p.seed, "")
233+
if processed is None:
234+
processed = Processed(p, [], p.seed, "")
219235
else:
220236
processed = modules.scripts.scripts_img2img.run(p, *args)
221237
if processed is None:

modules/shared_options.py

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
"img2img_inpaint_sketch_default_brush_color": OptionInfo("#ffffff", "Inpaint sketch initial brush color", ui_components.FormColorPicker, {}).info("default brush color of img2img inpaint sketch").needs_reload_ui(),
190190
"return_mask": OptionInfo(False, "For inpainting, include the greyscale mask in results for web"),
191191
"return_mask_composite": OptionInfo(False, "For inpainting, include masked composite in results for web"),
192+
"img2img_batch_show_results_limit": OptionInfo(32, "Show the first N batch img2img results in UI", gr.Slider, {"minimum": -1, "maximum": 1000, "step": 1}).info('0: disable, -1: show all images. Too many images can cause lag'),
192193
}))
193194

194195
options_templates.update(options_section(('optimizations', "Optimizations"), {

0 commit comments

Comments
 (0)