Change in random seed execution order, if a seed is marked as random, the value is been randomized before call, not after

This commit is contained in:
Sergey A. Kilimnik 2023-03-27 13:10:05 +03:00
parent bb1223d83f
commit 9de1535931
3 changed files with 20 additions and 16 deletions

View File

@ -285,7 +285,7 @@ app.registerExtension({
} }
if (widget.type === "number") { if (widget.type === "number") {
addRandomizeWidget(this, widget, "Random after every gen"); addRandomizeWidget(this, widget, "Random every gen");
} }
// When our value changes, update other widgets to reflect our changes // When our value changes, update other widgets to reflect our changes

View File

@ -842,6 +842,22 @@ class ComfyApp {
async queuePrompt(number, batchCount = 1) { async queuePrompt(number, batchCount = 1) {
for (let i = 0; i < batchCount; i++) { for (let i = 0; i < batchCount; i++) {
const workflow = this.graph.serialize();
for (const n of workflow.nodes) {
const node = graph.getNodeById(n.id);
if (node.widgets) {
for (const widget of node.widgets) {
// Allow widgets to run callbacks after a prompt has been queued
// e.g. random seed after every gen
if (widget.beforeQueued) {
widget.beforeQueued();
}
}
}
}
const p = await this.graphToPrompt(); const p = await this.graphToPrompt();
try { try {
@ -851,19 +867,6 @@ class ComfyApp {
return; return;
} }
for (const n of p.workflow.nodes) {
const node = graph.getNodeById(n.id);
if (node.widgets) {
for (const widget of node.widgets) {
// Allow widgets to run callbacks after a prompt has been queued
// e.g. random seed after every gen
if (widget.afterQueued) {
widget.afterQueued();
}
}
}
}
this.canvas.draw(true, true); this.canvas.draw(true, true);
await this.ui.queue.update(); await this.ui.queue.update();
} }

View File

@ -17,7 +17,7 @@ export function addRandomizeWidget(node, targetWidget, name, defaultValue = fals
serialize: false, // Don't include this in prompt. serialize: false, // Don't include this in prompt.
}); });
randomize.afterQueued = () => { randomize.beforeQueued = () => {
if (randomize.value) { if (randomize.value) {
const min = targetWidget.options?.min; const min = targetWidget.options?.min;
let max = targetWidget.options?.max; let max = targetWidget.options?.max;
@ -32,12 +32,13 @@ export function addRandomizeWidget(node, targetWidget, name, defaultValue = fals
} }
} }
}; };
return randomize; return randomize;
} }
function seedWidget(node, inputName, inputData) { function seedWidget(node, inputName, inputData) {
const seed = ComfyWidgets.INT(node, inputName, inputData); const seed = ComfyWidgets.INT(node, inputName, inputData);
const randomize = addRandomizeWidget(node, seed.widget, "Random seed after every gen", true); const randomize = addRandomizeWidget(node, seed.widget, "Random seed every gen", true);
seed.widget.linkedWidgets = [randomize]; seed.widget.linkedWidgets = [randomize];
return { widget: seed, randomize }; return { widget: seed, randomize };