diff --git a/javascript/main.js b/javascript/main.js
index 1e029d7..71de5ca 100644
--- a/javascript/main.js
+++ b/javascript/main.js
@@ -117,7 +117,21 @@ function depth_removeBackground() {
depth_lib_canvas.setBackgroundImage(0, depth_lib_canvas.renderAll.bind(depth_lib_canvas));
}
-function depth_sendImage() {
+function depth_sendImageTxt2Img() {
+ depth_sendImage(
+ '#txt2img_controlnet',
+ switch_to_txt2img,
+ );
+}
+
+function depth_sendImageImg2Img() {
+ depth_sendImage(
+ '#img2img_controlnet',
+ switch_to_img2img,
+ );
+}
+
+function depth_sendImage(controlNetDivId, switchFn) {
if (depth_lib_canvas.backgroundImage) depth_lib_canvas.backgroundImage.opacity = 0;
depth_lib_canvas.discardActiveObject();
depth_lib_canvas.renderAll();
@@ -127,9 +141,9 @@ function depth_sendImage() {
dt.items.add(file);
const list = dt.files;
- const divControlNet = depth_gradioApp().querySelector("#txt2img_controlnet");
+ const divControlNet = depth_gradioApp().querySelector(controlNetDivId);
if (divControlNet) {
- switch_to_txt2img();
+ switchFn();
// open the ControlNet accordion if it's not already open
// but give up if it takes longer than 5 secs
@@ -139,10 +153,10 @@ function depth_sendImage() {
let waitUntilHasClassOpenCount = 0;
const waitUntilHasClassOpen = async () => {
waitUntilHasClassOpenCount++;
- if (waitUntilHasClassOpenCount > 50) {
- return false;
- } else if (labelControlNet.classList.contains("open")) {
+ if (labelControlNet.classList.contains("open")) {
return true;
+ } else if (waitUntilHasClassOpenCount > 50) {
+ return false;
} else {
setTimeout(() => waitUntilHasClassOpen(), 100)
}
@@ -158,9 +172,10 @@ function depth_sendImage() {
const event = new Event('change', { 'bubbles': true, "composed": true });
input.dispatchEvent(event);
}
+
+ if (depth_lib_canvas.backgroundImage) depth_lib_canvas.backgroundImage.opacity = 0.5
+ depth_lib_canvas.renderAll()
});
- if (depth_lib_canvas.backgroundImage) depth_lib_canvas.backgroundImage.opacity = 0.5
- depth_lib_canvas.renderAll()
}
function depth_setBrightness(br) {
diff --git a/scripts/main.py b/scripts/main.py
index 9a53519..3b7cd00 100644
--- a/scripts/main.py
+++ b/scripts/main.py
@@ -50,11 +50,11 @@ def on_ui_tabs():
opacity = gr.Slider(label="Opacity", minimum=0.01, maximum=1, value=1, step=0.01, interactive=True)
with gr.Column():
- # gradioooooo...
canvas = gr.HTML('')
with gr.Row():
png_output = gr.Button(value="Save PNG")
- send_output = gr.Button(value="Send to ControlNet")
+ send_output_txt2img = gr.Button(value="Send to Txt2Img")
+ send_output_img2img = gr.Button(value="Send to Img2Img")
width.change(None, [width, height], None, _js="(w, h) => {depth_resizeCanvas(w, h)}")
@@ -66,7 +66,8 @@ def on_ui_tabs():
bg_remove.click(None, [], None, _js="depth_removeBackground")
add.click(None, [png_input_area], None, _js="(path) => {depth_addImg(path)}")
remove.click(None, [], None, _js="depth_removeSelection")
- send_output.click(None, [], None, _js="depth_sendImage")
+ send_output_txt2img.click(None, [], None, _js="() => depth_sendImageTxt2Img()")
+ send_output_img2img.click(None, [], None, _js="() => depth_sendImageImg2Img()")
reset_btn.click(None, [], None, _js="depth_resetCanvas")
return [(depth_lib, "Depth Library", "depth_lib")]