Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support to prompt shortcut in txt2img mode
- Loading branch information
1 parent
706437b
commit 70f6b6a
Showing
5 changed files
with
85 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function find_words_inside_braces(string) { | ||
const re = /\{(.*?)\}/g | ||
const keywords = string.match(re) | ||
console.log('keywords: ', keywords) | ||
return keywords | ||
} | ||
|
||
function replaceShortcut(text, prompt_shortcut_json) { | ||
const original_keywords = find_words_inside_braces(text) | ||
const strip_keywords = original_keywords.map((s) => { | ||
let content = s.slice(1, -1) //remove '{' and '}' | ||
content = content.trim() //remove any space in the beginning and end of content | ||
return content | ||
}) | ||
|
||
// original_substrings = list(map(lambda s: '{'+s+'}',raw_keywords)) | ||
|
||
// print("strip_keywords: ", strip_keywords) | ||
// print("original_substrings: ",original_substrings) | ||
// # print ("text:",text) | ||
|
||
let i = 0 | ||
for (const word of strip_keywords) { | ||
// # word = word.strip() | ||
// print("word: ",word) | ||
if (word.length > 0 && prompt_shortcut_json.hasOwnProperty(word)) { | ||
const prompt = prompt_shortcut_json[word] | ||
console.log('prompt: ', prompt) | ||
text = text.replace(original_keywords[i], prompt) | ||
} | ||
} | ||
console.log('final text: ', text) | ||
return text | ||
} | ||
module.exports = { | ||
find_words_inside_braces, | ||
replaceShortcut, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters