Skip to content
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ea8e94d
adding dynamic_prompts script
Zanshinmu Oct 13, 2024
dcc00db
Added render timer, bugfix
Zanshinmu Oct 14, 2024
0c79b42
Fixed wildcard expansion bug with deeply nested placeholders
Zanshinmu Oct 15, 2024
bdf336a
Fixed iterator bug, added output location, updated text, separated UI…
Zanshinmu Oct 18, 2024
153fd18
Resolving conflicts with main repo
Zanshinmu Oct 18, 2024
e8a7afd
Fix to remove -1 from filename, disable batchSize > 1
Zanshinmu Oct 18, 2024
2202615
Added image seed control, defaults to increment
Zanshinmu Oct 18, 2024
6be8a3c
Merge branch 'main' of github.com:Zanshinmu/community-scripts
Zanshinmu Oct 18, 2024
d8bb74d
Bugfix for prompts loras not setting weights and occasional DT crash.…
Zanshinmu Oct 22, 2024
71b3ab6
Preliminary fix for missing metadata, cleanup of code
Zanshinmu Oct 23, 2024
2846afb
Cleaned up iteration logic to handle edge cases. Added preliminary su…
Zanshinmu Oct 24, 2024
7026980
bugfixes for prompts objects missing fields
Zanshinmu Oct 25, 2024
9eab12e
Added debug printer class, final bugfixes for release
Zanshinmu Oct 25, 2024
560e26b
Merge branch 'drawthingsai:main' into main
Zanshinmu Oct 25, 2024
c3a38e9
Merge branch 'main' of github.com:Zanshinmu/community-scripts to crea…
Zanshinmu Oct 25, 2024
f87f43d
Fixed model downloading. Added total rendering time.
Zanshinmu Nov 15, 2024
b012d47
Merge branch 'drawthingsai:main' into main
Zanshinmu Nov 16, 2024
c972297
Merge branch 'main' of github.com:Zanshinmu/community-scripts to merg…
Zanshinmu Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 40 additions & 36 deletions scripts/dynamic-prompts/dynamic-prompts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@api-1.0
// dynamic prompts
// author: zanshinmu
// v3.5.8
// v3.5.9
// Discord Thread for Dynamic Prompts:
// https://discord.com/channels/1038516303666876436/1207467278426177736
/**
Expand Down Expand Up @@ -41,7 +41,7 @@
*/

//Version
const versionString = "v3.5.8";
const versionString = "v3.5.9";
//Maximum iterations for Iterate Mode, this is a good value for everything
//Macs with more resources can probably set this much higher
const maxIter = 500;
Expand Down Expand Up @@ -362,11 +362,14 @@ if(useUiPrompt){

// Main batch loop
if (!iterateMode){
const bstart = Date.now();
const bmessage = "✔︎ Total render time ‣";
for (let i = 0; i < batchCount; i++){
let batchCountLog = `Rendering ${i + 1} of ${batchCount}`;
console.warn(batchCountLog);
render(getDynamicPrompt(), i);
}
elapsed(bstart, message = bmessage);
} else {
const promptData = getDynamicPrompt();
const dynPrompt = promptData.prompt;
Expand All @@ -377,13 +380,16 @@ if (!iterateMode){
} else {
let k = 1;
console.log(`Iterating over dynamic prompt:\n '${dynPrompt}'\n Total combinations number ${p}.`);
const istart = Date.now();
const imessage = "✔︎ Total iteration time ‣";
for (let generatedPrompt of generatePrompts(dynPrompt)) {
let myConfig = promptData;
promptData.prompt = dynPrompt;
console.warn(`iterating render ${k} of ${p}\n${generatedPrompt}\n`);
render(generatedPrompt, k);
k++;
}
elapsed(istart, message = imessage);
}
}

Expand Down Expand Up @@ -512,41 +518,26 @@ function selectRandomPrompt() {
if (typeof myLoras !== 'undefined'){
myconfig.loras = myLoras.map(lora => ({ file: lora.file, weight: lora.weight }));
}
myconfig.model = mymodel;
myconfig.model = resolveModel(mymodel);
// Store the promptData object
const promptData = { prompt: myprompt, negativePrompt: myneg, configuration: myconfig };
if (downloadModels){
getModels(promptData);
}
debug.print(JSON.stringify(promptData), DebugPrint.Level.WARN);
debug.print(JSON.stringify(promptData), DebugPrint.Level.WARN);
return promptData;
}

//Download models if necessary
function getModels(promptData){
let models = [];
//Model first
if (typeof promptData.configuration.model !== 'undefined'){
models.push(promptData.configuration.model);
}

//Loras
if (typeof promptData.configuration.loras !== 'undefined'){
for (let i = 0; i < promptData.configuration.loras.length; i++) {
let lora = promptData.configuration.loras[i].file;
models.push(lora);
}
}
if (!pipeline.areModelsDownloaded(models)){
//Initiate Download
debug.print(`${JSON.stringify(models)} not clean, initiating download.`, DebugPrint.Level.WARN);
pipeline.downloadBuiltins(models);
function resolveModel(model){
if(downloadModels){
let myNameArray = [];
myNameArray.push(model);
pipeline.downloadBuiltins(myNameArray);
debug.print(`Model ${model} downloaded`);
} else {
debug.print(`${JSON.stringify(models)} clean, not initiating download.`, DebugPrint.Level.WARN);
debug.print('Download models disabled.');
}
return model;
}

// Resolves LoRAs to filename
// Resolves LoRAs to filenames
function resolveLoras(loras){
if (typeof loras === 'undefined'){
return loras;
Expand All @@ -557,13 +548,24 @@ function resolveLoras(loras){
let myLora = loras[i];
let myname = myLora.file;
if (!myname.endsWith(FILESUFFIX)){
try{
let myfile = pipeline.findLoRAByName(myname).file;
// Assign resolved name
myLora.file = myfile;
debug.print(`Filename ${myname} resolved to ${myfile}`);
debug.print(`Filename ${myname} resolved to ${JSON.stringify(myfile)}`);
} catch (e){
debug.print(`${e} Is it downloaded?`);
if(downloadModels){
let myNameArray = [];
myNameArray.push(myname);
myLora.file = pipeline.downloadBuiltins(myNameArray);
} else {
myLora.file = myname;
}
}
myLoras.push(myLora);
}
myLoras.push(myLora);
}
return myLoras;
}

Expand Down Expand Up @@ -614,13 +616,16 @@ function getDynamicPrompt () {
return promptData;
}

function timer (start){
function elapsed (start, message = "✔︎ Render time ‣"){
const end = Date.now();
const duration = end - start;
const minutes = Math.floor(duration / 60000);
const hours = Math.floor(duration / 3600000);
const minutes = Math.floor((duration % 3600000) / 60000); // calculate the remaining minutes after subtracting the elapsed hours from the total duration
let seconds = Math.floor((duration % 60000) / 1000);
seconds = seconds < 10 ? '0' + seconds : seconds;
console.log(`✔︎ Render time ‣ ${minutes}:${seconds}\n`);
const formattedHours = String(hours).padStart(2, '0');
const formattedMinutes = String(minutes).padStart(2, '0');
const formattedSeconds = String(seconds).padStart(2, '0');
console.log(`${message} ${formattedHours}:${formattedMinutes}:${formattedSeconds}\n`);
}

// Run pipeline
Expand Down Expand Up @@ -655,14 +660,13 @@ function render (promptData, batchCount){
canvas.clear();

debug.print(JSON.stringify(finalConfiguration), DebugPrint.Level.WARN);

pipeline.run({
configuration: finalConfiguration,
prompt: generatedPrompt,
negativePrompt: neg
});
//Output render time elapsed
timer(start);
elapsed(start);
//Save Image if enabled
savetoImageDir(finalConfiguration, batchCount);
}
Expand Down
Loading