From e097a5d2ca35a953d49344b706de2bf38a78c24b Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sun, 26 Nov 2023 15:02:22 +0100 Subject: [PATCH 1/6] add lcm realtime canvas painting --- modules/async_worker.py | 5 +++++ webui.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/modules/async_worker.py b/modules/async_worker.py index 70f00705e..d18a56c9d 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -138,6 +138,7 @@ def handler(async_task): outpaint_selections = args.pop() inpaint_input_image = args.pop() inpaint_additional_prompt = args.pop() + realtime_input_image = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -310,6 +311,10 @@ def handler(async_task): clip_vision_path, ip_negative_path, ip_adapter_face_path = modules.config.downloading_ip_adapters( 'face') progressbar(async_task, 1, 'Loading control models ...') + if current_tab == 'paint' and realtime_input_image is not None: + uov_input_image = HWC3(realtime_input_image) + goals.append('vary') + uov_method = 'strong' # Load or unload CNs pipeline.refresh_controlnets([controlnet_canny_path, controlnet_cpds_path]) diff --git a/webui.py b/webui.py index 479ac4aa7..4c1a8c131 100644 --- a/webui.py +++ b/webui.py @@ -192,6 +192,10 @@ def ip_advance_checked(x): example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False) gr.HTML('* Powered by Fooocus Inpaint Engine \U0001F4D4 Document') example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False) + with gr.TabItem(label='Realtime Canvas') as paint_tab: + with gr.Row(equal_height=True): + canvas_size = 512 + realtime_input_image = gr.Image(source="canvas", tool="color-sketch", shape=(canvas_size, canvas_size), width=canvas_size, height=canvas_size) switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}" down_js = "() => {viewer_to_bottom();}" @@ -204,6 +208,7 @@ def ip_advance_checked(x): uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False) inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False) ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False) + paint_tab.select(lambda: 'paint', outputs=current_tab, queue=False, _js=down_js, show_progress=False) with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column: with gr.Tab(label='Setting'): @@ -488,6 +493,8 @@ def inpaint_mode_change(mode): inpaint_strength, inpaint_respective_field ], show_progress=False, queue=False) + realtime_input_image.change(lambda: gr.update(value='Extreme Speed'), outputs=performance_selection, queue=False, show_progress=False, _js="() => {document.getElementById('generate_button').click();}") + ctrls = [ prompt, negative_prompt, style_selections, performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale @@ -497,6 +504,7 @@ def inpaint_mode_change(mode): ctrls += [input_image_checkbox, current_tab] ctrls += [uov_method, uov_input_image] ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt] + ctrls += [realtime_input_image] ctrls += ip_ctrls generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ From bed48beb272b6f60fbe414fd1d7e5db2058947ed Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sun, 26 Nov 2023 16:43:00 +0100 Subject: [PATCH 2/6] adjust shape and size of canvas on aspect_ratios_selection change requires fix of https://github.com/gradio-app/gradio/issues/5019, which is available from 3.45.0, but 3.50.2 is also compatible --- requirements_versions.txt | 2 +- webui.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/requirements_versions.txt b/requirements_versions.txt index 5d5af5d63..ac737b4be 100644 --- a/requirements_versions.txt +++ b/requirements_versions.txt @@ -11,7 +11,7 @@ psutil==5.9.5 numpy==1.23.5 pytorch_lightning==1.9.4 omegaconf==2.2.3 -gradio==3.41.2 +gradio==3.50.2 pygit2==1.12.2 opencv-contrib-python==4.8.0.74 httpx==0.24.1 diff --git a/webui.py b/webui.py index 4c1a8c131..b4932b391 100644 --- a/webui.py +++ b/webui.py @@ -194,8 +194,12 @@ def ip_advance_checked(x): example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False) with gr.TabItem(label='Realtime Canvas') as paint_tab: with gr.Row(equal_height=True): - canvas_size = 512 - realtime_input_image = gr.Image(source="canvas", tool="color-sketch", shape=(canvas_size, canvas_size), width=canvas_size, height=canvas_size) + def aspect_ratios_selection_change(aspect_ratios_selection): + width, height = aspect_ratios_selection.replace('×', ' ').split(' ')[:2] + width, height = int(int(width)/2), int(int(height)/2) + return gr.Paint(shape=(width, height), width=width, height=height) + + realtime_input_image = aspect_ratios_selection_change(modules.config.default_aspect_ratio) switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}" down_js = "() => {viewer_to_bottom();}" @@ -493,7 +497,8 @@ def inpaint_mode_change(mode): inpaint_strength, inpaint_respective_field ], show_progress=False, queue=False) - realtime_input_image.change(lambda: gr.update(value='Extreme Speed'), outputs=performance_selection, queue=False, show_progress=False, _js="() => {document.getElementById('generate_button').click();}") + realtime_input_image.change(lambda: (gr.update(value='Extreme Speed'), gr.update(value=False)), outputs=[performance_selection, seed_random], queue=False, show_progress=False, _js="() => {document.getElementById('generate_button').click();}") + aspect_ratios_selection.change(aspect_ratios_selection_change, inputs=aspect_ratios_selection, outputs=realtime_input_image, queue=False, show_progress=False) ctrls = [ prompt, negative_prompt, style_selections, From 088e99448b8d240e9670c9fde29a5f9df7708b64 Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sun, 26 Nov 2023 17:08:11 +0100 Subject: [PATCH 3/6] make generate button non-interactive while rendering prevents queue spam for too many updates --- webui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index b4932b391..7534f3130 100644 --- a/webui.py +++ b/webui.py @@ -512,11 +512,11 @@ def inpaint_mode_change(mode): ctrls += [realtime_input_image] ctrls += ip_ctrls - generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ + generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), []), outputs=[stop_button, skip_button, generate_button, gallery]) \ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \ .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ - .then(lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)), outputs=[generate_button, stop_button, skip_button]) \ + .then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False), gr.update(visible=False)), outputs=[generate_button, stop_button, skip_button]) \ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') for notification_file in ['notification.ogg', 'notification.mp3']: From b3c0aeb8a4c31b511e97836e5bfdebec4024dcb1 Mon Sep 17 00:00:00 2001 From: Manuel Schmid <9307310+mashb1t@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:14:51 +0100 Subject: [PATCH 4/6] change image_number to 1 when using lcm realtime input --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 7534f3130..c71b2da4d 100644 --- a/webui.py +++ b/webui.py @@ -497,7 +497,7 @@ def inpaint_mode_change(mode): inpaint_strength, inpaint_respective_field ], show_progress=False, queue=False) - realtime_input_image.change(lambda: (gr.update(value='Extreme Speed'), gr.update(value=False)), outputs=[performance_selection, seed_random], queue=False, show_progress=False, _js="() => {document.getElementById('generate_button').click();}") + realtime_input_image.change(lambda: (gr.update(value='Extreme Speed'), gr.update(value=1), gr.update(value=False)), outputs=[performance_selection, image_number, seed_random], queue=False, show_progress=False, _js="() => {document.getElementById('generate_button').click();}") aspect_ratios_selection.change(aspect_ratios_selection_change, inputs=aspect_ratios_selection, outputs=realtime_input_image, queue=False, show_progress=False) ctrls = [ From 1b4ce0688dc9a26518c817459e3dbfa6a17f63bc Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Thu, 30 Nov 2023 00:43:39 +0100 Subject: [PATCH 5/6] fix hardcoded js class after gradio update --- javascript/zoom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/zoom.js b/javascript/zoom.js index e3fdcfb70..44b911d16 100644 --- a/javascript/zoom.js +++ b/javascript/zoom.js @@ -357,7 +357,7 @@ onUiLoaded(async() => { // Reset zoom when uploading a new image const fileInput = gradioApp().querySelector( - `${elemId} input[type="file"][accept="image/*"].svelte-116rqfv` + `${elemId} input[type="file"][accept="image/*"].svelte-izfbkb` ); fileInput.addEventListener("click", resetZoom); From 5c34394cb00b28d3a9589f7d6095f1b55e8c94dd Mon Sep 17 00:00:00 2001 From: Manuel Schmid <9307310+mashb1t@users.noreply.github.com> Date: Thu, 30 Nov 2023 09:25:03 +0100 Subject: [PATCH 6/6] downgrade gradio to 3.45.0 --- requirements_versions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_versions.txt b/requirements_versions.txt index ac737b4be..c40e09d4d 100644 --- a/requirements_versions.txt +++ b/requirements_versions.txt @@ -11,7 +11,7 @@ psutil==5.9.5 numpy==1.23.5 pytorch_lightning==1.9.4 omegaconf==2.2.3 -gradio==3.50.2 +gradio==3.45.0 pygit2==1.12.2 opencv-contrib-python==4.8.0.74 httpx==0.24.1