From 97e18bf9fd85c6d801d76224c8e779097287d268 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Tue, 21 Feb 2023 03:33:54 -0500 Subject: [PATCH] Document dynamic prompts and add escaping of {} characters. --- README.md | 2 ++ webshit/index.html | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 93c7b3ec..9a1eb194 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,8 @@ Dragging a generated png on the webpage or loading one will give you the full wo You can use () to change emphasis of a word or phrase like: (good code:1.2) or (bad code:0.8). The default emphasis for () is 1.1. To use () characters in your actual prompt escape them like \\( or \\). +You can use {day|night}, for wildcard/dynamic prompts. With this syntax "{wild|card|test}" will be randomly replaced by either "wild", "card" or "test" by the frontend every time you queue the prompt. To use {} characters in your actual prompt escape them like: \\{ or \\}. + To use a textual inversion concepts/embeddings in a text prompt put them in the models/embeddings directory and use them in the CLIPTextEncode node like this (you can omit the .pt extension): ```embedding:embedding_filename.pt``` diff --git a/webshit/index.html b/webshit/index.html index 7befd47f..490de6ab 100644 --- a/webshit/index.html +++ b/webshit/index.html @@ -331,9 +331,9 @@ function graphToPrompt() { // resolve the string var prompt = widget.input_div.innerText; - while (prompt.includes('{') && prompt.includes('}')) { - const startIndex = prompt.indexOf('{'); - const endIndex = prompt.indexOf('}'); + while (prompt.replace("\\{", "").includes('{') && prompt.replace("\\}", "").includes('}')) { + const startIndex = prompt.replace("\\{", "00").indexOf('{'); + const endIndex = prompt.replace("\\}", "00").indexOf('}'); const optionsString = prompt.substring(startIndex + 1, endIndex); const options = optionsString.split('|'); @@ -344,7 +344,7 @@ function graphToPrompt() { prompt = prompt.substring(0, startIndex) + randomOption + prompt.substring(endIndex + 1); } - widget.value = prompt; + widget.value = prompt.replace("\\{", "{").replace("\\}", "}"); } } }