aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnum <connum@gmail.com>2022-09-21 00:28:03 +0200
committerAUTOMATIC1111 <16777216c@gmail.com>2022-09-21 09:13:13 +0300
commite9ba2d42d6c13bc3f8763c6ccd00fff2519b3152 (patch)
treeb5acc16e1b9dbcaaf4f3ff6358be3a9453d3c690
parent29d6084f47918a1ae46bea1ef9bf0cd37836e03e (diff)
fix image replacement via clipboard paste or drag and drop on PNG Info tab
-rw-r--r--javascript/dragdrop.js25
-rw-r--r--modules/ui.py2
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(),