control implement image measure

This commit is contained in:
Vladimir Mandic
2024-01-20 08:12:31 -05:00
parent 71654cee9c
commit ddecb8f240
3 changed files with 10 additions and 5 deletions
+6 -1
View File
@@ -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 [];
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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)