fix send to tab and hires upscale button

This commit is contained in:
AUTOMATIC1111 2024-01-27 12:05:26 +03:00
parent 91d1034d8d
commit cee0bf8464
3 changed files with 23 additions and 16 deletions

View File

@ -30,9 +30,6 @@ function extract_image_from_gallery(gallery) {
if (gallery.length == 0) { if (gallery.length == 0) {
return [null]; return [null];
} }
if (gallery.length == 1) {
return [gallery[0]];
}
var index = selected_gallery_index(); var index = selected_gallery_index();
@ -41,7 +38,7 @@ function extract_image_from_gallery(gallery) {
index = 0; index = 0;
} }
return [gallery[index]]; return [[gallery[index]]];
} }
window.args_to_array = Array.from; // Compatibility with e.g. extensions that may expect this to be around window.args_to_array = Array.from; // Compatibility with e.g. extensions that may expect this to be around

View File

@ -74,29 +74,38 @@ def image_from_url_text(filedata):
if filedata is None: if filedata is None:
return None return None
if type(filedata) == list and filedata and type(filedata[0]) == dict and filedata[0].get("is_file", False): if isinstance(filedata, list):
if len(filedata) == 0:
return None
filedata = filedata[0] filedata = filedata[0]
if isinstance(filedata, dict) and filedata.get("is_file", False):
filedata = filedata
filename = None
if type(filedata) == dict and filedata.get("is_file", False): if type(filedata) == dict and filedata.get("is_file", False):
filename = filedata["name"] filename = filedata["name"]
elif isinstance(filedata, tuple) and len(filedata) == 2: # gradio 4.16 sends images from gallery as a list of tuples
filename = filedata[0]
if filename:
is_in_right_dir = ui_tempdir.check_tmp_file(shared.demo, filename) is_in_right_dir = ui_tempdir.check_tmp_file(shared.demo, filename)
assert is_in_right_dir, 'trying to open image file outside of allowed directories' assert is_in_right_dir, 'trying to open image file outside of allowed directories'
filename = filename.rsplit('?', 1)[0] filename = filename.rsplit('?', 1)[0]
return Image.open(filename) return Image.open(filename)
if type(filedata) == list: if isinstance(filedata, str):
if len(filedata) == 0: if filedata.startswith("data:image/png;base64,"):
return None filedata = filedata[len("data:image/png;base64,"):]
filedata = filedata[0] filedata = base64.decodebytes(filedata.encode('utf-8'))
image = Image.open(io.BytesIO(filedata))
return image
if filedata.startswith("data:image/png;base64,"): return None
filedata = filedata[len("data:image/png;base64,"):]
filedata = base64.decodebytes(filedata.encode('utf-8'))
image = Image.open(io.BytesIO(filedata))
return image
def add_paste_fields(tabname, init_img, fields, override_settings_component=None): def add_paste_fields(tabname, init_img, fields, override_settings_component=None):

View File

@ -266,6 +266,7 @@ def create_ui():
toprow = ui_toprow.Toprow(is_img2img=False, is_compact=shared.opts.compact_prompt_box) toprow = ui_toprow.Toprow(is_img2img=False, is_compact=shared.opts.compact_prompt_box)
dummy_component = gr.Textbox(visible=False) dummy_component = gr.Textbox(visible=False)
dummy_component_number = gr.Number(visible=False)
extra_tabs = gr.Tabs(elem_id="txt2img_extra_tabs", elem_classes=["extra-networks"]) extra_tabs = gr.Tabs(elem_id="txt2img_extra_tabs", elem_classes=["extra-networks"])
extra_tabs.__enter__() extra_tabs.__enter__()
@ -425,7 +426,7 @@ def create_ui():
output_panel.button_upscale.click( output_panel.button_upscale.click(
fn=wrap_gradio_gpu_call(modules.txt2img.txt2img_upscale, extra_outputs=[None, '', '']), fn=wrap_gradio_gpu_call(modules.txt2img.txt2img_upscale, extra_outputs=[None, '', '']),
_js="submit_txt2img_upscale", _js="submit_txt2img_upscale",
inputs=txt2img_inputs[0:1] + [output_panel.gallery, dummy_component, output_panel.generation_info] + txt2img_inputs[1:], inputs=txt2img_inputs[0:1] + [output_panel.gallery, dummy_component_number, output_panel.generation_info] + txt2img_inputs[1:],
outputs=txt2img_outputs, outputs=txt2img_outputs,
show_progress=False, show_progress=False,
) )