Skip to content
Merged
Changes from all commits
Commits
Show all changes
21 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
26be12d
Preliminary fix for undefined LoRA error. Moved prompts and categorie…
Zanshinmu Nov 20, 2024
6d0be3f
Merge branch 'drawthingsai:main' into main
Zanshinmu Nov 20, 2024
736d224
Merge for update of dynamic-prompts to 3.5.9.1
Zanshinmu Nov 20, 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
135 changes: 70 additions & 65 deletions scripts/dynamic-prompts/dynamic-prompts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//@api-1.0
// dynamic prompts
// author: zanshinmu
// v3.5.9
// v3.5.9.1
// Discord Thread for Dynamic Prompts:
// https://discord.com/channels/1038516303666876436/1207467278426177736
/**
* Documentation for "Dynamic Prompts" Script (Version 3.5.4) for "Draw Things"
* Documentation for "Dynamic Prompts" Script (Version 3.5.9.1) for "Draw Things"
*
* This script generates dynamic prompts for the "Draw Things" application. Customize it to enhance your creative experience.
*
Expand Down Expand Up @@ -40,71 +40,10 @@
* To reduce the numbers, eliminate categories from your prompt.
*/

//Version
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;

//Sure, you can turn this on if you like your console cluttered. :P
const DEBUG = false;

class DebugPrint {
static Level = Object.freeze({
INFO: 'INFO',
WARN: 'WARN',
ERROR: 'ERROR'
});

#debugMode; // Private field to store debug mode state

/**
* Constructor for DebugPrint
* @param {boolean} [debugMode=false] - Whether to enable debug printing by default
*/
constructor(debugMode = false) {
this.#debugMode = debugMode;
}

/**
* Prints a message if debug mode is enabled
* @param {string} message - The message to print
* @param {DebugPrint.Level} [level=DebugPrint.Level.INFO] - The log level of the message
*/
print(message, level = DebugPrint.Level.INFO) {
if (!Object.values(DebugPrint.Level).includes(level)) {
throw new Error(`Invalid log level: ${level}`);
}

if (this.#debugMode) {
switch (level) {
case DebugPrint.Level.INFO:
console.log(`${message}`);
break;

case DebugPrint.Level.WARN:
console.warn(`${message}`);
break;

case DebugPrint.Level.ERROR:
console.error(`${message}`);
break;

}
}
}
}

// Initiate debug logger, set state to DEBUG;
const debug = new DebugPrint(DEBUG);
//store selected prompt data and UI config
let userPrompt = '';
let uiPrompt = '';
const UICONFIG = pipeline.configuration;
//Default example prompt for UI demonstrating category use
const defaultPrompt = "wide-angle shot of {weather} {time} {locale}"

/* These are the prompts randomly selected from if UI Prompt isn't valid.
/* Following are the prompts randomly selected from if UI Prompt mode isn't enabled.
Modify prompts to provide dynamic prompts with LoRAs which will be randomly selected from if a valid dynamic prompt is not found in the UI.

As of 3.0.1 there can be a 'configuration' object for each prompt which contains arbitrary settings which will be passed on to the pipeline at runtime. These settings correspond to the possible values of pipeline.configuration
Expand Down Expand Up @@ -170,7 +109,7 @@ const prompts = [
// Empty file will be ignored
];

// Categories definition
// Categories definition: This is where you add your dynamic categories.
const categories = {
cyborg: [
"{adjective} cyborg man, {hairstyle} {haircolor} hair, {features}, wearing {malestyle}",
Expand Down Expand Up @@ -291,6 +230,68 @@ const categories = {
]
};

//Version
const versionString = "v3.5.9.1";
//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;

//Sure, you can turn this on if you like your console cluttered. :P
const DEBUG = false;

class DebugPrint {
static Level = Object.freeze({
INFO: 'INFO',
WARN: 'WARN',
ERROR: 'ERROR'
});

#debugMode; // Private field to store debug mode state

/**
* Constructor for DebugPrint
* @param {boolean} [debugMode=false] - Whether to enable debug printing by default
*/
constructor(debugMode = false) {
this.#debugMode = debugMode;
}

/**
* Prints a message if debug mode is enabled
* @param {string} message - The message to print
* @param {DebugPrint.Level} [level=DebugPrint.Level.INFO] - The log level of the message
*/
print(message, level = DebugPrint.Level.INFO) {
if (!Object.values(DebugPrint.Level).includes(level)) {
throw new Error(`Invalid log level: ${level}`);
}

if (this.#debugMode) {
switch (level) {
case DebugPrint.Level.INFO:
console.log(`${message}`);
break;

case DebugPrint.Level.WARN:
console.warn(`${message}`);
break;

case DebugPrint.Level.ERROR:
console.error(`${message}`);
break;

}
}
}
}

// Initiate debug logger, set state to DEBUG;
const debug = new DebugPrint(DEBUG);
//store selected prompt data and UI config
let userPrompt = '';
let uiPrompt = '';
const UICONFIG = pipeline.configuration;

// UI
const categoryNames = Object.keys(categories).join(', ');
const seedOptions = ["Random","Increment","Static"];
Expand Down Expand Up @@ -547,6 +548,10 @@ function resolveLoras(loras){
for (let i = 0; i < loras.length; i++) {
let myLora = loras[i];
let myname = myLora.file;
if (typeof myname === 'undefined'){
debug.print("Empty LoRA", DebugPrint.level.WARN);
continue;
}
if (!myname.endsWith(FILESUFFIX)){
try{
let myfile = pipeline.findLoRAByName(myname).file;
Expand Down
Loading