This commit is contained in:
Haoming 2025-09-01 15:22:22 +08:00
parent 4f736641c6
commit d26cf6b2d2
4 changed files with 28 additions and 22 deletions

View File

@ -91,6 +91,9 @@ function requestProgress(
let parentProgressbar = progressbarContainer.parentNode;
let wakeLock = null;
if (gallery && gallery.classList.contains("hidden"))
gallery = gallery.parentElement.querySelector(".gradio-video");
let requestWakeLock = async function () {
if (!opts.prevent_screen_sleep_during_generation || wakeLock) return;
try {

View File

@ -128,23 +128,17 @@ function get_img2img_tab_index() {
}
function create_submit_args(args) {
// Currently, txt2img and img2img also send the output args (gallery / player / generation_info / infotext / html_log) whenever you generate a new image.
let res = Array.from(args);
// As it is currently, txt2img and img2img send back the previous output args (txt2img_gallery, generation_info, html_info) whenever you generate a new image.
// This can lead to uploading a huge gallery of previously generated images, which leads to an unnecessary delay between submitting and beginning to generate.
// I don't know why gradio is sending outputs along with inputs, but we can prevent sending the image gallery here, which seems to be an issue for some.
// If gradio at some point stops sending outputs, this may break something
if (Array.isArray(res[res.length - 4])) {
//res[res.length - 4] = null;
// simply drop output args
if (Array.isArray(res[res.length - 5]))
res = res.slice(0, res.length - 5);
else if (Array.isArray(res[res.length - 4]))
res = res.slice(0, res.length - 4);
} else if (Array.isArray(res[res.length - 3])) {
// for submit_extras()
//res[res.length - 3] = null;
else if (Array.isArray(res[res.length - 3]))
res = res.slice(0, res.length - 3);
}
// NOTE: If gradio at some point stops sending outputs, this may break something
return res;
}

View File

@ -421,13 +421,14 @@ def create_ui():
txt2img_outputs = [
output_panel.gallery,
output_panel.player,
output_panel.generation_info,
output_panel.infotext,
output_panel.html_log,
]
txt2img_args = dict(
fn=wrap_gradio_gpu_call(modules.txt2img.txt2img, extra_outputs=[None, '', '']),
fn=wrap_gradio_gpu_call(modules.txt2img.txt2img, extra_outputs=[None, None, "", ""]),
_js="submit",
inputs=txt2img_inputs,
outputs=txt2img_outputs,
@ -445,10 +446,15 @@ def create_ui():
txt2img_upscale_inputs = txt2img_inputs[0:1] + [output_panel.gallery, dummy_component_number, output_panel.generation_info] + txt2img_inputs[1:]
output_panel.button_upscale.click(
fn=wrap_gradio_gpu_call(modules.txt2img.txt2img_upscale, extra_outputs=[None, '', '']),
fn=wrap_gradio_gpu_call(modules.txt2img.txt2img_upscale, extra_outputs=[None, "", ""]),
_js="submit_txt2img_upscale",
inputs=txt2img_upscale_inputs,
outputs=txt2img_outputs,
outputs=[
output_panel.gallery,
output_panel.generation_info,
output_panel.infotext,
output_panel.html_log,
],
show_progress=False,
).then(fn=select_gallery_image, js="selected_gallery_index", inputs=[dummy_component], outputs=[output_panel.gallery])
@ -788,11 +794,12 @@ def create_ui():
] + custom_inputs
img2img_args = dict(
fn=wrap_gradio_gpu_call(modules.img2img.img2img, extra_outputs=[None, '', '']),
fn=wrap_gradio_gpu_call(modules.img2img.img2img, extra_outputs=[None, None, "", ""]),
_js="submit_img2img",
inputs=submit_img2img_inputs,
outputs=[
output_panel.gallery,
output_panel.player,
output_panel.generation_info,
output_panel.infotext,
output_panel.html_log,

View File

@ -151,11 +151,12 @@ def save_files(js_data, images, do_make_zip, index):
@dataclasses.dataclass
class OutputPanel:
gallery = None
generation_info = None
infotext = None
html_log = None
button_upscale = None
gallery: gr.Gallery = None
player: gr.Video = None
generation_info: gr.HTML = None
infotext: gr.HTML = None
html_log: gr.HTML = None
button_upscale: gr.Button = None
def create_output_panel(tabname, outdir, toprow=None):
@ -181,7 +182,8 @@ def create_output_panel(tabname, outdir, toprow=None):
with gr.Column(variant='panel', elem_id=f"{tabname}_results_panel"):
with gr.Group(elem_id=f"{tabname}_gallery_container"):
res.gallery = gr.Gallery(label='Output', show_label=False, elem_id=f"{tabname}_gallery", columns=4, preview=True, height=shared.opts.gallery_height or None, interactive=False, type="pil", object_fit="contain")
res.gallery = gr.Gallery(label="Output", show_label=False, elem_id=f"{tabname}_gallery", columns=4, preview=True, height=shared.opts.gallery_height or None, interactive=False, type="pil", object_fit="contain")
res.player = gr.Video(label="Output", show_label=False, elem_id=f"{tabname}_player", height=shared.opts.gallery_height or None, interactive=False, autoplay=shared.opts.video_player_auto, loop=shared.opts.video_player_loop, include_audio=False, show_download_button=False, show_share_button=False, visible=False)
with gr.Row(elem_id=f"image_buttons_{tabname}", elem_classes="image-buttons"):
open_folder_button = ToolButton(folder_symbol, elem_id=f'{tabname}_open_folder', visible=not shared.cmd_opts.hide_ui_dir_config, tooltip="Open images output directory.")