Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impact-pack wildcards in autocomplete #426

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ to your ComfyUI `custom_nodes` directory

## Autocomplete
![image](https://github.com/pythongosssss/ComfyUI-Custom-Scripts/assets/125205205/b5971135-414f-4f4e-a6cf-2650dc01085f)
Provides embedding and custom word autocomplete. You can view embedding details by clicking on the info icon on the list.
Define your list of custom words via the settings.
Provides embedding, [Impact-Pack](https://github.com/ltdrdata/ComfyUI-Impact-Pack) wildcards and custom word autocomplete. You can view embedding details by clicking on the info icon on the list.
Define your list of custom words via the settings.
![image](https://github.com/pythongosssss/ComfyUI-Custom-Scripts/assets/125205205/160ef61c-7d7e-49d0-b60f-5a1501b74c9d)
You can quickly default to danbooru tags using the Load button, or load/manage other custom word lists.
![image](https://github.com/pythongosssss/ComfyUI-Custom-Scripts/assets/125205205/cc180b35-5f45-442f-9285-3ddf3fa320d0)
Expand Down
48 changes: 47 additions & 1 deletion web/js/autocompleter.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ async function addCustomWords(text) {
}
}

async function getImpactWildcards() {
const resp = await api.fetchApi("/impact/wildcards/list", { cache: "no-store" });
if (resp.status === 200) {
return await resp.json();
}
return undefined;
}

async function addImpactWildcards() {
const jObj = await getImpactWildcards();
if (jObj == null)
return;
const dict = jObj.data.reduce((p, wildcard) =>{
p[wildcard] = { text: wildcard, use_replacer: false, value: wildcard };
return p;
}, {});
console.log(dict);
TextAreaAutoComplete.updateWords("impact.wildcards", dict);
}

function toggleLoras() {
[TextAreaAutoComplete.globalWords, TextAreaAutoComplete.globalWordsExclLoras] = [
TextAreaAutoComplete.globalWordsExclLoras,
Expand Down Expand Up @@ -373,6 +393,27 @@ app.registerExtension({
}),
]
),
$el(
"label.comfy-tooltip-indicator",
{
title: "Show or not wildcards provided by impact pack extension. Require page reload!",
textContent: "Impact-pack wildcards enabled ",
style: {
display: "block",
},
},
[
$el("input", {
type: "checkbox",
checked: !!TextAreaAutoComplete.impactPackWildcardsEnabled,
onchange: (event) => {
const checked = !!event.target.checked;
TextAreaAutoComplete.impactPackWildcardsEnabled = checked;
localStorage.setItem(id + ".ShowImpactPackWildcards", TextAreaAutoComplete.impactPackWildcardsEnabled);
},
}),
]
),
$el(
"label",
{
Expand Down Expand Up @@ -525,6 +566,7 @@ app.registerExtension({
TextAreaAutoComplete.insertOnTab = localStorage.getItem(id + ".InsertOnTab") !== "false";
TextAreaAutoComplete.insertOnEnter = localStorage.getItem(id + ".InsertOnEnter") !== "false";
TextAreaAutoComplete.lorasEnabled = localStorage.getItem(id + ".ShowLoras") === "true";
TextAreaAutoComplete.impactPackWildcardsEnabled = localStorage.getItem(id + ".ShowImpactPackWildcards") === "true";
TextAreaAutoComplete.suggestionCount = +localStorage.getItem(id + ".SuggestionCount") || 20;
},
setup() {
Expand Down Expand Up @@ -571,7 +613,11 @@ app.registerExtension({
}

// store global words with/without loras
Promise.all([addEmbeddings(), addCustomWords()])
const autocompleteLoaders = [addEmbeddings(), addCustomWords()];
if (TextAreaAutoComplete.impactPackWildcardsEnabled) {
autocompleteLoaders.push(addImpactWildcards())
}
Promise.all(autocompleteLoaders)
.then(() => {
TextAreaAutoComplete.globalWordsExclLoras = Object.assign({}, TextAreaAutoComplete.globalWords);
})
Expand Down
1 change: 1 addition & 0 deletions web/js/common/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ export class TextAreaAutoComplete {
static insertOnEnter = true;
static replacer = undefined;
static lorasEnabled = false;
static impactPackWildcardsEnabled = false;
static suggestionCount = 20;

/** @type {Record<string, Record<string, AutoCompleteEntry>>} */
Expand Down