Skip to content

Commit

Permalink
img2img resolution preview should use currently selected tab's image
Browse files Browse the repository at this point in the history
  • Loading branch information
space-nuko committed Mar 23, 2023
1 parent aceced6 commit dbee0a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
13 changes: 10 additions & 3 deletions javascript/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,14 @@ function create_tab_index_args(tabId, args){

function get_img2img_tab_index() {
let res = args_to_array(arguments)
res.splice(-2)
res.splice(-2) // gradio also sends outputs to the arguments, pop them off
res[0] = get_tab_index('mode_img2img')
return res
}

function get_img2img_tab_index_for_res_preview() {
let res = args_to_array(arguments)
res.splice(-1) // gradio also sends outputs to the arguments, pop them off
res[0] = get_tab_index('mode_img2img')
return res
}
Expand Down Expand Up @@ -338,7 +345,7 @@ function selectCheckpoint(name){
}


function onCalcResolutionImg2Img(init_img, scale, width, height, resize_mode){
function onCalcResolutionImg2Img(mode, scale, width, height, resize_mode, init_img, sketch, init_img_with_mask, inpaint_color_sketch, init_img_inpaint){
i2iScale = gradioApp().getElementById('img2img_scale')
i2iWidth = gradioApp().getElementById('img2img_width')
i2iHeight = gradioApp().getElementById('img2img_height')
Expand All @@ -347,5 +354,5 @@ function onCalcResolutionImg2Img(init_img, scale, width, height, resize_mode){
setInactive(i2iWidth, scale > 1)
setInactive(i2iHeight, scale > 1)

return [init_img, width, height, scale, resize_mode]
return [];
}
13 changes: 11 additions & 2 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ def calc_resolution_hires(enable, width, height, hr_scale, hr_resize_x, hr_resiz
return f"resize: from <span class='resolution'>{p.width}x{p.height}</span> to <span class='resolution'>{p.hr_resize_x or p.hr_upscale_to_x}x{p.hr_resize_y or p.hr_upscale_to_y}</span>"


def calc_resolution_img2img(init_img, scale, resize_x, resize_y, resize_mode):
def calc_resolution_img2img(mode, scale, resize_x, resize_y, resize_mode, *i2i_images):
init_img = None
if mode in {0, 1, 3, 4}:
init_img = i2i_images[mode]
elif mode == 2:
init_img = i2i_images[mode]["image"]

if not init_img:
return ""

Expand Down Expand Up @@ -842,10 +848,13 @@ def select_img2img_tab(tab):
outputs=[inpaint_controls, mask_alpha],
)

img2img_resolution_preview_inputs = [init_img, scale, width, height, resize_mode]
img2img_resolution_preview_inputs = [dummy_component, # filled in by selected img2img tab index in _js
scale, width, height, resize_mode,
init_img, sketch, init_img_with_mask, inpaint_color_sketch, init_img_inpaint]
for input in img2img_resolution_preview_inputs:
input.change(
fn=calc_resolution_img2img,
_js="get_img2img_tab_index_for_res_preview",
inputs=img2img_resolution_preview_inputs,
outputs=[final_resolution],
show_progress=False,
Expand Down

0 comments on commit dbee0a3

Please sign in to comment.