From 403bb02948d6a4ae4bfa88e7b9287fefe27d04b4 Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Wed, 21 Sep 2022 01:02:26 +0300 Subject: [PATCH 1/5] breakout tile options --- modules/shared.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/shared.py b/modules/shared.py index d04147ad..9732317f 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -143,8 +143,10 @@ class Options: "enable_emphasis": OptionInfo(True, "Use (text) to make model pay more attention to text and [text] to make it pay less attention"), "enable_batch_seeds": OptionInfo(True, "Make K-diffusion samplers produce same images in a batch as when making a single image"), "save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."), - "GAN_tile": OptionInfo(192, "Tile size for all upscalers. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), - "GAN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for all upscalers. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), + "ESRGAN_tile": OptionInfo(192, "Tile size for ESRGAN upscalers. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), + "ESRGAN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for ESRGAN upscalers. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), + "SWIN_tile": OptionInfo(192, "Tile size for all SwinIR. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), + "SWIN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for SwinIR. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), "random_artist_categories": OptionInfo([], "Allowed categories for random artists selection when using the Roll button", gr.CheckboxGroup, {"choices": artist_db.categories()}), "upscale_at_full_resolution_padding": OptionInfo(16, "Inpainting at full resolution: padding, in pixels, for the masked region.", gr.Slider, {"minimum": 0, "maximum": 128, "step": 4}), "upscaler_for_hires_fix": OptionInfo(None, "Upscaler for highres. fix", gr.Radio, lambda: {"choices": [x.name for x in sd_upscalers]}), From a5313351b348016ca29b2135c650e05ba5781ccf Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Wed, 21 Sep 2022 01:02:56 +0300 Subject: [PATCH 2/5] Update swinir.py --- modules/swinir.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/swinir.py b/modules/swinir.py index 7e8fd5e3..8c534495 100644 --- a/modules/swinir.py +++ b/modules/swinir.py @@ -55,8 +55,8 @@ def load_models(dirname): def upscale( img, model, - tile=opts.GAN_tile, - tile_overlap=opts.GAN_tile_overlap, + tile=opts.SWIN_tile, + tile_overlap=opts.SWIN_tile_overlap, window_size=8, scale=4, ): From 29d6084f47918a1ae46bea1ef9bf0cd37836e03e Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Wed, 21 Sep 2022 01:07:06 +0300 Subject: [PATCH 3/5] disallow no tiling as we don't support it --- modules/shared.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/shared.py b/modules/shared.py index 9732317f..16675192 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -145,7 +145,7 @@ class Options: "save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."), "ESRGAN_tile": OptionInfo(192, "Tile size for ESRGAN upscalers. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), "ESRGAN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for ESRGAN upscalers. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), - "SWIN_tile": OptionInfo(192, "Tile size for all SwinIR. 0 = no tiling.", gr.Slider, {"minimum": 0, "maximum": 512, "step": 16}), + "SWIN_tile": OptionInfo(192, "Tile size for all SwinIR.", gr.Slider, {"minimum": 16, "maximum": 512, "step": 16}), "SWIN_tile_overlap": OptionInfo(8, "Tile overlap, in pixels for SwinIR. Low values = visible seam.", gr.Slider, {"minimum": 0, "maximum": 48, "step": 1}), "random_artist_categories": OptionInfo([], "Allowed categories for random artists selection when using the Roll button", gr.CheckboxGroup, {"choices": artist_db.categories()}), "upscale_at_full_resolution_padding": OptionInfo(16, "Inpainting at full resolution: padding, in pixels, for the masked region.", gr.Slider, {"minimum": 0, "maximum": 128, "step": 4}), From e9ba2d42d6c13bc3f8763c6ccd00fff2519b3152 Mon Sep 17 00:00:00 2001 From: Connum Date: Wed, 21 Sep 2022 00:28:03 +0200 Subject: [PATCH 4/5] fix image replacement via clipboard paste or drag and drop on PNG Info tab --- javascript/dragdrop.js | 25 +++++++++++++++++++++++-- modules/ui.py | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/javascript/dragdrop.js b/javascript/dragdrop.js index 29e26766..0fb74dba 100644 --- a/javascript/dragdrop.js +++ b/javascript/dragdrop.js @@ -10,13 +10,34 @@ function dropReplaceImage( imgWrap, files ) { } imgWrap.querySelector('.modify-upload button + button, .touch-none + div button + button')?.click(); - window.requestAnimationFrame( () => { + const callback = () => { const fileInput = imgWrap.querySelector('input[type="file"]'); if ( fileInput ) { fileInput.files = files; fileInput.dispatchEvent(new Event('change')); } - }); + }; + + if ( imgWrap.closest('#pnginfo_image') ) { + // special treatment for PNG Info tab, wait for fetch request to finish + const oldFetch = window.fetch; + window.fetch = async (input, options) => { + const response = await oldFetch(input, options); + if ( 'api/predict/' === input ) { + const content = await response.text(); + window.fetch = oldFetch; + window.requestAnimationFrame( () => callback() ); + return new Response(content, { + status: response.status, + statusText: response.statusText, + headers: response.headers + }) + } + return response; + }; + } else { + window.requestAnimationFrame( () => callback() ); + } } function pressClearBtn(hoverElems) { diff --git a/modules/ui.py b/modules/ui.py index 0d428b5b..e290b3eb 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -797,7 +797,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): pnginfo_interface = gr.Interface( wrap_gradio_call(run_pnginfo), inputs=[ - gr.Image(label="Source", source="upload", interactive=True, type="pil"), + gr.Image(elem_id="pnginfo_image", label="Source", source="upload", interactive=True, type="pil"), ], outputs=[ gr.HTML(), From b5693699b8460008ca92544b42f6bc394078ee4d Mon Sep 17 00:00:00 2001 From: Connum Date: Wed, 21 Sep 2022 01:57:11 +0200 Subject: [PATCH 5/5] Revert "Reset image input when dragover new image" This reverts commit 9035afbab5e1285cfc7ad39c1e17374973842ae9. --- javascript/dragdrop.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/javascript/dragdrop.js b/javascript/dragdrop.js index 0fb74dba..c01f66e2 100644 --- a/javascript/dragdrop.js +++ b/javascript/dragdrop.js @@ -40,15 +40,6 @@ function dropReplaceImage( imgWrap, files ) { } } -function pressClearBtn(hoverElems) { - //Find all buttons hovering over the image box - let btns = Array.from(hoverElems.querySelectorAll("button")) - - //Press the last btn which will be the X button - if (btns.length) - btns[btns.length-1].click() -} - window.document.addEventListener('dragover', e => { const target = e.composedPath()[0]; const imgWrap = target.closest('[data-testid="image"]'); @@ -57,13 +48,7 @@ window.document.addEventListener('dragover', e => { } e.stopPropagation(); e.preventDefault(); - - if (e.dataTransfer) - e.dataTransfer.dropEffect = 'copy'; - - //If is gr.Interface clear image on hover - if (target.previousElementSibling) - pressClearBtn(target.previousElementSibling) + e.dataTransfer.dropEffect = 'copy'; }); window.document.addEventListener('drop', e => {