From c0a7438fd880aee655df9e383e4b39f9b9e555b6 Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Tue, 8 Oct 2024 19:13:32 +0900 Subject: [PATCH] partial revert to fix compatible issue (#1892) * partial revert to fix A1111 compatible issue * fix for submit_extras() --- javascript/ui.js | 31 +++++++++++++++++++++++-------- modules/ui.py | 6 +++--- modules/ui_postprocessing.py | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/javascript/ui.js b/javascript/ui.js index d4b3dbf3..e46ccfdb 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -113,6 +113,21 @@ function get_img2img_tab_index() { function create_submit_args(args) { var 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 + res = res.slice(0, res.length - 4); + } else if (Array.isArray(res[res.length - 3])) { + // for submit_extras() + //res[res.length - 3] = null; + res = res.slice(0, res.length - 3); + } + return res; } @@ -136,7 +151,7 @@ function showRestoreProgressButton(tabname, show) { button.style.setProperty('display', show ? 'flex' : 'none', 'important'); } -function submit(args) { +function submit() { showSubmitButtons('txt2img', false); var id = randomId(); @@ -148,22 +163,22 @@ function submit(args) { showRestoreProgressButton('txt2img', false); }); - var res = create_submit_args(args); + var res = create_submit_args(arguments); res[0] = id; return res; } -function submit_txt2img_upscale(args) { - var res = submit(args); +function submit_txt2img_upscale() { + var res = submit(...arguments); res[2] = selected_gallery_index(); return res; } -function submit_img2img(args) { +function submit_img2img() { showSubmitButtons('img2img', false); var id = randomId(); @@ -175,14 +190,14 @@ function submit_img2img(args) { showRestoreProgressButton('img2img', false); }); - var res = create_submit_args(args); + var res = create_submit_args(arguments); res[0] = id; return res; } -function submit_extras(args) { +function submit_extras() { showSubmitButtons('extras', false); var id = randomId(); @@ -191,7 +206,7 @@ function submit_extras(args) { showSubmitButtons('extras', true); }); - var res = create_submit_args(args); + var res = create_submit_args(arguments); res[0] = id; diff --git a/modules/ui.py b/modules/ui.py index 4f6b5807..00299779 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -440,7 +440,7 @@ def create_ui(): txt2img_args = dict( fn=wrap_gradio_gpu_call(modules.txt2img.txt2img, extra_outputs=[None, '', '']), - js=f"(...args) => {{ return submit(args.slice(0, {len(txt2img_inputs)})); }}", + _js="submit", inputs=txt2img_inputs, outputs=txt2img_outputs, show_progress=False, @@ -452,7 +452,7 @@ 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, '', '']), - js=f"(...args) => {{ return submit_txt2img_upscale(args.slice(0, {len(txt2img_upscale_inputs)})); }}", + _js="submit_txt2img_upscale", inputs=txt2img_upscale_inputs, outputs=txt2img_outputs, show_progress=False, @@ -790,7 +790,7 @@ def create_ui(): img2img_args = dict( fn=wrap_gradio_gpu_call(modules.img2img.img2img, extra_outputs=[None, '', '']), - js=f"(...args) => {{ return submit_img2img(args.slice(0, {len(submit_img2img_inputs)})); }}", + _js="submit_img2img", inputs=submit_img2img_inputs, outputs=[ output_panel.gallery, diff --git a/modules/ui_postprocessing.py b/modules/ui_postprocessing.py index 7a33ca8f..f1b1803c 100644 --- a/modules/ui_postprocessing.py +++ b/modules/ui_postprocessing.py @@ -49,7 +49,7 @@ def create_ui(): submit.click( fn=call_queue.wrap_gradio_gpu_call(postprocessing.run_postprocessing_webui, extra_outputs=[None, '']), - js=f"(...args) => {{ return submit_extras(args.slice(0, {len(submit_click_inputs)})); }}", + _js=f"submit_extras", inputs=submit_click_inputs, outputs=[ output_panel.gallery,