From 4d5a366f00de906b8ff5b124f7f7b6e771fee155 Mon Sep 17 00:00:00 2001 From: fuzzytent Date: Wed, 7 Sep 2022 21:58:11 +0200 Subject: [PATCH 1/3] Allow copy-pasting images into file inputs --- script.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/script.js b/script.js index 51ace27f..f2cd8877 100644 --- a/script.js +++ b/script.js @@ -172,3 +172,19 @@ function submit(){ } return res } + +window.addEventListener('paste', e => { + const files = e.clipboardData.files; + if (!files || files.length !== 1) { + return; + } + if (!['image/png', 'image/gif', 'image/jpeg'].includes(files[0].type)) { + return; + } + [...gradioApp().querySelectorAll('input[type=file][accept="image/x-png,image/gif,image/jpeg"]')] + .filter(input => !input.matches('.\\!hidden input[type=file]')) + .forEach(input => { + input.files = files; + input.dispatchEvent(new Event('change')) + }); +}); From 7045c846435cf5c9547729c60e85c386e78c90ed Mon Sep 17 00:00:00 2001 From: fuzzytent Date: Wed, 7 Sep 2022 22:37:54 +0200 Subject: [PATCH 2/3] Also use alpha channel from img2img input image as mask --- modules/img2img.py | 6 ++++-- modules/ui.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/img2img.py b/modules/img2img.py index 3129798d..1e734ac8 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -1,5 +1,5 @@ import math -from PIL import Image +from PIL import Image, ImageOps, ImageChops from modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images from modules.shared import opts, state @@ -16,7 +16,9 @@ def img2img(prompt: str, init_img, init_img_with_mask, steps: int, sampler_index if is_inpaint: image = init_img_with_mask['image'] - mask = init_img_with_mask['mask'] + alpha_mask = ImageOps.invert(image.split()[-1]).convert('L').point(lambda x: 255 if x > 0 else 0, mode='1') + mask = ImageChops.lighter(alpha_mask, init_img_with_mask['mask'].convert('L')).convert('RGBA') + image = image.convert('RGB') else: image = init_img mask = None diff --git a/modules/ui.py b/modules/ui.py index f5564d0e..b1a8c776 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -323,7 +323,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): with gr.Group(): switch_mode = gr.Radio(label='Mode', elem_id="img2img_mode", choices=['Redraw whole image', 'Inpaint a part of image', 'Loopback', 'SD upscale'], value='Redraw whole image', type="index", show_label=False) init_img = gr.Image(label="Image for img2img", source="upload", interactive=True, type="pil") - init_img_with_mask = gr.Image(label="Image for inpainting with mask", elem_id="img2maskimg", source="upload", interactive=True, type="pil", tool="sketch", visible=False) + init_img_with_mask = gr.Image(label="Image for inpainting with mask", elem_id="img2maskimg", source="upload", interactive=True, type="pil", tool="sketch", visible=False, image_mode="RGBA") resize_mode = gr.Radio(label="Resize mode", show_label=False, choices=["Just resize", "Crop and resize", "Resize and fill"], type="index", value="Just resize") steps = gr.Slider(minimum=1, maximum=150, step=1, label="Sampling Steps", value=20) From d03e9502b1815e2262eff09e0a0f6b21e18e8609 Mon Sep 17 00:00:00 2001 From: Christian <59421913+Cikmo@users.noreply.github.com> Date: Thu, 8 Sep 2022 00:31:25 +0200 Subject: [PATCH 3/3] Fix not being able to have spaces directory Adds quotes around the PYTHON path so that there can be spaces in parent folders. --- webui.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.bat b/webui.bat index 055a19b0..0de2ab88 100644 --- a/webui.bat +++ b/webui.bat @@ -35,7 +35,7 @@ echo Unable to create venv in directory %VENV_DIR% goto :show_stdout_stderr :activate_venv -set PYTHON=%~dp0%VENV_DIR%\Scripts\Python.exe +set PYTHON="%~dp0%VENV_DIR%\Scripts\Python.exe" %PYTHON% --version echo venv %PYTHON% goto :install_torch