mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2024-12-23 23:49:11 +01:00
Added calculation as to how many images will be generated with given prompts.
This commit is contained in:
parent
0ba9f0549e
commit
e213f6cb95
@ -1327,6 +1327,43 @@ function getPrompts(prompts) {
|
||||
return promptsToMake
|
||||
}
|
||||
|
||||
function getPromptsNumber(prompts) {
|
||||
if (typeof prompts === "undefined") {
|
||||
prompts = promptField.value
|
||||
}
|
||||
if (prompts.trim() === "" && activeTags.length === 0) {
|
||||
return [""]
|
||||
}
|
||||
|
||||
let promptsToMake = []
|
||||
let numberOfPrompts = 0
|
||||
if (prompts.trim() !== "") { // this needs to stay sort of the same, as the prompts have to be passed through to the other functions
|
||||
prompts = prompts.split("\n")
|
||||
prompts = prompts.map((prompt) => prompt.trim())
|
||||
prompts = prompts.filter((prompt) => prompt !== "")
|
||||
|
||||
promptsToMake = applySetOperator(prompts) // switched those around as Set grows in a linear fashion and permute in 2^n, and one has to be computed for the other to be calculated
|
||||
numberOfPrompts = applyPermuteOperatorNumber(promptsToMake)
|
||||
}
|
||||
const newTags = activeTags.filter((tag) => tag.inactive === undefined || tag.inactive === false)
|
||||
if (newTags.length > 0) {
|
||||
const promptTags = newTags.map((x) => x.name).join(", ")
|
||||
if (numberOfPrompts > 0) {
|
||||
// promptsToMake = promptsToMake.map((prompt) => `${prompt}, ${promptTags}`)
|
||||
// nothing changes, as all prompts just get modified
|
||||
} else {
|
||||
// promptsToMake.push(promptTags)
|
||||
numberOfPrompts = 1
|
||||
}
|
||||
}
|
||||
|
||||
// Why is this applied twice? It does not do anything here, as everything should have already been done earlier
|
||||
// promptsToMake = applyPermuteOperator(promptsToMake)
|
||||
// promptsToMake = applySetOperator(promptsToMake)
|
||||
|
||||
return numberOfPrompts
|
||||
}
|
||||
|
||||
function applySetOperator(prompts) {
|
||||
let promptsToMake = []
|
||||
let braceExpander = new BraceExpander()
|
||||
@ -1338,7 +1375,7 @@ function applySetOperator(prompts) {
|
||||
return promptsToMake
|
||||
}
|
||||
|
||||
function applyPermuteOperator(prompts) {
|
||||
function applyPermuteOperator(prompts) { // prompts is array of input, trimmed, filtered and split by \n
|
||||
let promptsToMake = []
|
||||
prompts.forEach((prompt) => {
|
||||
let promptMatrix = prompt.split("|")
|
||||
@ -1357,6 +1394,26 @@ function applyPermuteOperator(prompts) {
|
||||
return promptsToMake
|
||||
}
|
||||
|
||||
// returns how many prompts would have to be made with the given prompts
|
||||
function applyPermuteOperatorNumber(prompts) { // prompts is array of input, trimmed, filtered and split by \n
|
||||
let numberOfPrompts = 0
|
||||
prompts.forEach((prompt) => {
|
||||
let promptCounter = 1
|
||||
let promptMatrix = prompt.split("|")
|
||||
promptMatrix.shift()
|
||||
|
||||
promptMatrix = promptMatrix.map((p) => p.trim())
|
||||
promptMatrix = promptMatrix.filter((p) => p !== "")
|
||||
|
||||
if (promptMatrix.length > 0) {
|
||||
promptCounter *= permutePromptsNumber(promptMatrix)
|
||||
}
|
||||
numberOfPrompts += promptCounter
|
||||
})
|
||||
|
||||
return numberOfPrompts
|
||||
}
|
||||
|
||||
function permutePrompts(promptBase, promptMatrix) {
|
||||
let prompts = []
|
||||
let permutations = permute(promptMatrix)
|
||||
@ -1378,6 +1435,10 @@ function permutePrompts(promptBase, promptMatrix) {
|
||||
return prompts
|
||||
}
|
||||
|
||||
function permutePromptsNumber(promptMatrix) { // this should calculate how many different prompts can be made with the prompt matrix
|
||||
return permuteNumber(promptMatrix)
|
||||
}
|
||||
|
||||
// create a file name with embedded prompt and metadata
|
||||
// for easier cateloging and comparison
|
||||
function createFileName(prompt, seed, steps, guidance, outputFormat) {
|
||||
@ -1546,7 +1607,7 @@ heightField.addEventListener("change", onDimensionChange)
|
||||
|
||||
function renameMakeImageButton() {
|
||||
let totalImages =
|
||||
Math.max(parseInt(numOutputsTotalField.value), parseInt(numOutputsParallelField.value)) * getPrompts().length
|
||||
Math.max(parseInt(numOutputsTotalField.value), parseInt(numOutputsParallelField.value)) * getPromptsNumber()
|
||||
let imageLabel = "Image"
|
||||
if (totalImages > 1) {
|
||||
imageLabel = totalImages + " Images"
|
||||
|
@ -153,6 +153,10 @@ function permute(arr) {
|
||||
return permutations
|
||||
}
|
||||
|
||||
function permuteNumber(arr) {
|
||||
return Math.pow(2, arr.length)
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/8212878
|
||||
function millisecondsToStr(milliseconds) {
|
||||
function numberEnding(number) {
|
||||
|
Loading…
Reference in New Issue
Block a user