From cee0bf8464cf51acc93547205c88ccde79083d48 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Sat, 27 Jan 2024 12:05:26 +0300 Subject: [PATCH] fix send to tab and hires upscale button --- javascript/ui.js | 5 +---- modules/infotext_utils.py | 31 ++++++++++++++++++++----------- modules/ui.py | 3 ++- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/javascript/ui.js b/javascript/ui.js index 4710ba568..16807a6d7 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -30,9 +30,6 @@ function extract_image_from_gallery(gallery) { if (gallery.length == 0) { return [null]; } - if (gallery.length == 1) { - return [gallery[0]]; - } var index = selected_gallery_index(); @@ -41,7 +38,7 @@ function extract_image_from_gallery(gallery) { 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 diff --git a/modules/infotext_utils.py b/modules/infotext_utils.py index 1049c6c3c..e411a0268 100644 --- a/modules/infotext_utils.py +++ b/modules/infotext_utils.py @@ -74,29 +74,38 @@ def image_from_url_text(filedata): if filedata is 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] + if isinstance(filedata, dict) and filedata.get("is_file", False): + filedata = filedata + + filename = None if type(filedata) == dict and filedata.get("is_file", False): 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) assert is_in_right_dir, 'trying to open image file outside of allowed directories' filename = filename.rsplit('?', 1)[0] return Image.open(filename) - if type(filedata) == list: - if len(filedata) == 0: - return None + if isinstance(filedata, str): + if filedata.startswith("data:image/png;base64,"): + 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,"): - filedata = filedata[len("data:image/png;base64,"):] - - filedata = base64.decodebytes(filedata.encode('utf-8')) - image = Image.open(io.BytesIO(filedata)) - return image + return None def add_paste_fields(tabname, init_img, fields, override_settings_component=None): diff --git a/modules/ui.py b/modules/ui.py index 7f56654bd..a7f1832d5 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -266,6 +266,7 @@ def create_ui(): toprow = ui_toprow.Toprow(is_img2img=False, is_compact=shared.opts.compact_prompt_box) 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.__enter__() @@ -425,7 +426,7 @@ def create_ui(): output_panel.button_upscale.click( fn=wrap_gradio_gpu_call(modules.txt2img.txt2img_upscale, extra_outputs=[None, '', '']), _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, show_progress=False, )