add eager generate feature
This commit is contained in:
parent
987f29739a
commit
fd34dfff67
1 changed files with 80 additions and 2 deletions
|
@ -3,6 +3,7 @@ let generationQueue = [];
|
||||||
let generationAreas = new Set();
|
let generationAreas = new Set();
|
||||||
let generating = false;
|
let generating = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts progress monitoring bar
|
* Starts progress monitoring bar
|
||||||
*
|
*
|
||||||
|
@ -375,12 +376,16 @@ const _generate = async (endpoint, request, bb, options = {}) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sendInterrupt = () => {
|
||||||
|
fetch(`${host}${config.api.path}interrupt`, {method: "POST"});
|
||||||
|
}
|
||||||
|
|
||||||
// Add Interrupt Button
|
// Add Interrupt Button
|
||||||
const interruptButton = makeElement("button", bb.x + bb.w - 100, bb.y + bb.h);
|
const interruptButton = makeElement("button", bb.x + bb.w - 100, bb.y + bb.h);
|
||||||
interruptButton.classList.add("dream-stop-btn");
|
interruptButton.classList.add("dream-stop-btn");
|
||||||
interruptButton.textContent = "Interrupt";
|
interruptButton.textContent = "Interrupt";
|
||||||
interruptButton.addEventListener("click", () => {
|
interruptButton.addEventListener("click", () => {
|
||||||
fetch(`${host}${config.api.path}interrupt`, {method: "POST"});
|
sendInterrupt();
|
||||||
interruptButton.disabled = true;
|
interruptButton.disabled = true;
|
||||||
});
|
});
|
||||||
const marchingOptions = {};
|
const marchingOptions = {};
|
||||||
|
@ -390,6 +395,10 @@ const _generate = async (endpoint, request, bb, options = {}) => {
|
||||||
console.info(`[dream] Generating images for prompt '${request.prompt}'`);
|
console.info(`[dream] Generating images for prompt '${request.prompt}'`);
|
||||||
console.debug(request);
|
console.debug(request);
|
||||||
|
|
||||||
|
|
||||||
|
eagerGenerateCount = toolbar._current_tool.state.eagerGenerateCount;
|
||||||
|
isDreamComplete = false;
|
||||||
|
|
||||||
let stopProgress = null;
|
let stopProgress = null;
|
||||||
try {
|
try {
|
||||||
let stopDrawingStatus = false;
|
let stopDrawingStatus = false;
|
||||||
|
@ -428,6 +437,17 @@ const _generate = async (endpoint, request, bb, options = {}) => {
|
||||||
imageCollection.inputElement.removeChild(interruptButton);
|
imageCollection.inputElement.removeChild(interruptButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const needMoreGenerations = () => {
|
||||||
|
return (eagerGenerateCount > 0) &&
|
||||||
|
(images.length - highestNavigatedImageIndex <= eagerGenerateCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isGenerationPending = () => {
|
||||||
|
return generationQueue.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let highestNavigatedImageIndex = 0;
|
||||||
|
|
||||||
// Image navigation
|
// Image navigation
|
||||||
const prevImg = () => {
|
const prevImg = () => {
|
||||||
at--;
|
at--;
|
||||||
|
@ -443,10 +463,16 @@ const _generate = async (endpoint, request, bb, options = {}) => {
|
||||||
at++;
|
at++;
|
||||||
if (at >= images.length) at = 0;
|
if (at >= images.length) at = 0;
|
||||||
|
|
||||||
|
highestNavigatedImageIndex = Math.max(at, highestNavigatedImageIndex);
|
||||||
|
|
||||||
imageindextxt.textContent = `${at}/${images.length - 1}`;
|
imageindextxt.textContent = `${at}/${images.length - 1}`;
|
||||||
var seed = seeds[at];
|
var seed = seeds[at];
|
||||||
seedbtn.title = "Use seed " + seed;
|
seedbtn.title = "Use seed " + seed;
|
||||||
redraw();
|
redraw();
|
||||||
|
|
||||||
|
if (needMoreGenerations() && !isGenerationPending()) {
|
||||||
|
makeMore();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const applyImg = async () => {
|
const applyImg = async () => {
|
||||||
|
@ -504,6 +530,12 @@ const _generate = async (endpoint, request, bb, options = {}) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
nextQueue(moreQ);
|
nextQueue(moreQ);
|
||||||
|
|
||||||
|
//Start the next batch if we're eager-generating
|
||||||
|
if (needMoreGenerations() && !isGenerationPending() && !isDreamComplete) {
|
||||||
|
makeMore();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const discardImg = async () => {
|
const discardImg = async () => {
|
||||||
|
@ -657,6 +689,10 @@ const _generate = async (endpoint, request, bb, options = {}) => {
|
||||||
mouse.listen.world.btn.right.onclick.clear(oncancelhandler);
|
mouse.listen.world.btn.right.onclick.clear(oncancelhandler);
|
||||||
mouse.listen.world.btn.middle.onclick.clear(onmorehandler);
|
mouse.listen.world.btn.middle.onclick.clear(onmorehandler);
|
||||||
mouse.listen.world.onwheel.clear(onwheelhandler);
|
mouse.listen.world.onwheel.clear(onwheelhandler);
|
||||||
|
isDreamComplete = true;
|
||||||
|
if (generating) {
|
||||||
|
sendInterrupt();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
|
@ -740,6 +776,12 @@ const _generate = async (endpoint, request, bb, options = {}) => {
|
||||||
imageSelectMenu.appendChild(seedbtn);
|
imageSelectMenu.appendChild(seedbtn);
|
||||||
|
|
||||||
nextQueue(initialQ);
|
nextQueue(initialQ);
|
||||||
|
|
||||||
|
//Start the next batch after the initial generation
|
||||||
|
if (needMoreGenerations()) {
|
||||||
|
makeMore();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1186,6 +1228,7 @@ const dreamTool = () =>
|
||||||
state.keepUnmaskedBlur = 8;
|
state.keepUnmaskedBlur = 8;
|
||||||
state.overMaskPx = 20;
|
state.overMaskPx = 20;
|
||||||
state.preserveMasks = false;
|
state.preserveMasks = false;
|
||||||
|
state.eagerGenerateCount = 0;
|
||||||
|
|
||||||
state.erasePrevCursor = () =>
|
state.erasePrevCursor = () =>
|
||||||
uiCtx.clearRect(0, 0, uiCanvas.width, uiCanvas.height);
|
uiCtx.clearRect(0, 0, uiCanvas.width, uiCanvas.height);
|
||||||
|
@ -1465,6 +1508,7 @@ const dreamTool = () =>
|
||||||
"Preserve Brushed Masks"
|
"Preserve Brushed Masks"
|
||||||
).label;
|
).label;
|
||||||
|
|
||||||
|
|
||||||
// Overmasking Slider
|
// Overmasking Slider
|
||||||
state.ctxmenu.overMaskPxLabel = _toolbar_input.slider(
|
state.ctxmenu.overMaskPxLabel = _toolbar_input.slider(
|
||||||
state,
|
state,
|
||||||
|
@ -1477,6 +1521,22 @@ const dreamTool = () =>
|
||||||
textStep: 1,
|
textStep: 1,
|
||||||
}
|
}
|
||||||
).slider;
|
).slider;
|
||||||
|
|
||||||
|
|
||||||
|
// Eager generation Slider
|
||||||
|
state.ctxmenu.eagerGenerateCountLabel = _toolbar_input.slider(
|
||||||
|
state,
|
||||||
|
"eagerGenerateCount",
|
||||||
|
"Generate-ahead count",
|
||||||
|
{
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
step: 2,
|
||||||
|
textStep: 1,
|
||||||
|
}
|
||||||
|
).slider;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.appendChild(state.ctxmenu.cursorSizeSlider);
|
menu.appendChild(state.ctxmenu.cursorSizeSlider);
|
||||||
|
@ -1489,6 +1549,8 @@ const dreamTool = () =>
|
||||||
menu.appendChild(state.ctxmenu.preserveMasksLabel);
|
menu.appendChild(state.ctxmenu.preserveMasksLabel);
|
||||||
menu.appendChild(document.createElement("br"));
|
menu.appendChild(document.createElement("br"));
|
||||||
menu.appendChild(state.ctxmenu.overMaskPxLabel);
|
menu.appendChild(state.ctxmenu.overMaskPxLabel);
|
||||||
|
menu.appendChild(document.createElement("br"));
|
||||||
|
menu.appendChild(state.ctxmenu.eagerGenerateCountLabel);
|
||||||
},
|
},
|
||||||
shortcut: "D",
|
shortcut: "D",
|
||||||
}
|
}
|
||||||
|
@ -1573,6 +1635,7 @@ const img2imgTool = () =>
|
||||||
state.keepUnmaskedBlur = 8;
|
state.keepUnmaskedBlur = 8;
|
||||||
state.fullResolution = false;
|
state.fullResolution = false;
|
||||||
state.preserveMasks = false;
|
state.preserveMasks = false;
|
||||||
|
state.eagerGenerateCount = 0;
|
||||||
|
|
||||||
state.denoisingStrength = 0.7;
|
state.denoisingStrength = 0.7;
|
||||||
|
|
||||||
|
@ -2006,6 +2069,19 @@ const img2imgTool = () =>
|
||||||
textStep: 1,
|
textStep: 1,
|
||||||
}
|
}
|
||||||
).slider;
|
).slider;
|
||||||
|
|
||||||
|
// Eager generation Slider
|
||||||
|
state.ctxmenu.eagerGenerateCountLabel = _toolbar_input.slider(
|
||||||
|
state,
|
||||||
|
"eagerGenerateCount",
|
||||||
|
"Generate-ahead count",
|
||||||
|
{
|
||||||
|
min: 0,
|
||||||
|
max: 100,
|
||||||
|
step: 2,
|
||||||
|
textStep: 1,
|
||||||
|
}
|
||||||
|
).slider;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.appendChild(state.ctxmenu.cursorSizeSlider);
|
menu.appendChild(state.ctxmenu.cursorSizeSlider);
|
||||||
|
@ -2023,6 +2099,8 @@ const img2imgTool = () =>
|
||||||
menu.appendChild(state.ctxmenu.denoisingStrengthSlider);
|
menu.appendChild(state.ctxmenu.denoisingStrengthSlider);
|
||||||
menu.appendChild(state.ctxmenu.borderMaskGradientCheckbox);
|
menu.appendChild(state.ctxmenu.borderMaskGradientCheckbox);
|
||||||
menu.appendChild(state.ctxmenu.borderMaskSlider);
|
menu.appendChild(state.ctxmenu.borderMaskSlider);
|
||||||
|
menu.appendChild(document.createElement("br"));
|
||||||
|
menu.appendChild(state.ctxmenu.eagerGenerateCountLabel);
|
||||||
},
|
},
|
||||||
shortcut: "I",
|
shortcut: "I",
|
||||||
}
|
}
|
||||||
|
@ -2031,7 +2109,7 @@ const img2imgTool = () =>
|
||||||
window.onbeforeunload = async () => {
|
window.onbeforeunload = async () => {
|
||||||
// Stop current generation on page close
|
// Stop current generation on page close
|
||||||
if (generating)
|
if (generating)
|
||||||
await fetch(`${host}${config.api.path}interrupt`, {method: "POST"});
|
await sendInterrupt();
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendSeed = (seed) => {
|
const sendSeed = (seed) => {
|
||||||
|
|
Loading…
Reference in a new issue