From ddecb8f240e67a8462c3c581ff9f5f2f9d3338a3 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 20 Jan 2024 08:12:31 -0500 Subject: [PATCH] control implement image measure --- javascript/ui.js | 7 ++++++- modules/ui.py | 2 +- modules/ui_sections.py | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/javascript/ui.js b/javascript/ui.js index 107879b07..424803e0b 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -419,11 +419,16 @@ function selectReference(name) { gradioApp().getElementById('change_reference').click(); } -function currentImg2imgSourceResolution(_a, _b, scaleBy) { +function currentImageResolutionimg2img(_a, _b, scaleBy) { const img = gradioApp().querySelector('#mode_img2img > div[style="display: block;"] img'); return img ? [img.naturalWidth, img.naturalHeight, scaleBy] : [0, 0, scaleBy]; } +function currentImageResolutioncontrol(_a, _b, scaleBy) { + const img = gradioApp().querySelector('#control-tab-input > div[style="display: block;"] img'); + return img ? [img.naturalWidth, img.naturalHeight, scaleBy] : [0, 0, scaleBy]; +} + function updateImg2imgResizeToTextAfterChangingImage() { setTimeout(() => gradioApp().getElementById('img2img_update_resize_to').click(), 500); return []; diff --git a/modules/ui.py b/modules/ui.py index cffc534ee..9d54285ae 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -102,7 +102,7 @@ def get_value_for_setting(key): value = getattr(opts, key) info = opts.data_labels[key] args = info.component_args() if callable(info.component_args) else info.component_args or {} - args = {k: v for k, v in args.items() if k not in {'precision'}} + args = {k: v for k, v in args.items() if k not in {'precision', 'multiselect'}} return gr.update(value=value, **args) diff --git a/modules/ui_sections.py b/modules/ui_sections.py index c1aac6d92..5c1a9ef5c 100644 --- a/modules/ui_sections.py +++ b/modules/ui_sections.py @@ -234,7 +234,8 @@ def create_resize_inputs(tab, images, scale_visible=True, mode=None, accordion=T res_switch_btn = ToolButton(value=ui_symbols.switch, elem_id=f"{tab}_res_switch_btn") res_switch_btn.click(lambda w, h: (h, w), inputs=[width, height], outputs=[width, height], show_progress=False) detect_image_size_btn = ToolButton(value=ui_symbols.detect, elem_id=f"{tab}_detect_image_size_btn") - detect_image_size_btn.click(fn=lambda w, h, _: (w or gr.update(), h or gr.update()), _js="currentImg2imgSourceResolution", inputs=[dummy_component, dummy_component, dummy_component], outputs=[width, height], show_progress=False) + print('HERE', tab) + detect_image_size_btn.click(fn=lambda w, h, _: (w or gr.update(), h or gr.update()), _js=f'currentImageResolution{tab}', inputs=[dummy_component, dummy_component, dummy_component], outputs=[width, height], show_progress=False) with gr.Tab(label="Scale") as tab_scale_by: scale_by = gr.Slider(minimum=0.05, maximum=8.0, step=0.05, label="Scale", value=1.0, elem_id=f"{tab}_scale") @@ -243,8 +244,7 @@ def create_resize_inputs(tab, images, scale_visible=True, mode=None, accordion=T scale_by_html = gr.HTML(resize_from_to_html(0, 0, 0.0), elem_id=f"{tab}_scale_resolution_preview") gr.Slider(label="Unused", elem_id=f"{tab}_unused_scale_by_slider") button_update_resize_to = gr.Button(visible=False, elem_id=f"{tab}_update_resize_to") - - on_change_args = dict(fn=resize_from_to_html, _js="currentImg2imgSourceResolution", inputs=[dummy_component, dummy_component, scale_by], outputs=scale_by_html, show_progress=False) + on_change_args = dict(fn=resize_from_to_html, _js=f'currentImageResolution{tab}', inputs=[dummy_component, dummy_component, scale_by], outputs=scale_by_html, show_progress=False) scale_by.release(**on_change_args) button_update_resize_to.click(**on_change_args)