|
|
|
|
@@ -289,7 +289,8 @@ function insertTextAtCursor(textArea, result, tagword) {
|
|
|
|
|
textArea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
|
|
|
|
|
|
|
|
// Update previous tags with the edited prompt to prevent re-searching the same term
|
|
|
|
|
let weightedTags = newPrompt.match(WEIGHT_REGEX)
|
|
|
|
|
let weightedTags = [...newPrompt.matchAll(WEIGHT_REGEX)]
|
|
|
|
|
.map(match => match[1]);
|
|
|
|
|
let tags = newPrompt.match(TAG_REGEX)
|
|
|
|
|
if (weightedTags !== null) {
|
|
|
|
|
tags = tags.filter(tag => !weightedTags.some(weighted => tag.includes(weighted)))
|
|
|
|
|
@@ -402,7 +403,8 @@ async function autocomplete(textArea, prompt, fixedTag = null) {
|
|
|
|
|
if (fixedTag === null) {
|
|
|
|
|
// Match tags with RegEx to get the last edited one
|
|
|
|
|
// We also match for the weighting format (e.g. "tag:1.0") here, and combine the two to get the full tag word set
|
|
|
|
|
let weightedTags = prompt.match(WEIGHT_REGEX)
|
|
|
|
|
let weightedTags = [...prompt.matchAll(WEIGHT_REGEX)]
|
|
|
|
|
.map(match => match[1]);
|
|
|
|
|
let tags = prompt.match(TAG_REGEX)
|
|
|
|
|
if (weightedTags !== null) {
|
|
|
|
|
tags = tags.filter(tag => !weightedTags.some(weighted => tag.includes(weighted)))
|
|
|
|
|
@@ -446,7 +448,7 @@ async function autocomplete(textArea, prompt, fixedTag = null) {
|
|
|
|
|
else // Look in extensions wildcard files
|
|
|
|
|
wcPair = wildcardExtFiles.find(x => x[1].toLowerCase() === wcFile);
|
|
|
|
|
|
|
|
|
|
let wildcards = (await readFile(`file/${wcPair[0]}/${wcPair[1]}.txt`)).split("\n")
|
|
|
|
|
let wildcards = (await readFile(`file/${wcPair[0]}/${wcPair[1]}.txt?${new Date().getTime()}`)).split("\n")
|
|
|
|
|
.filter(x => x.trim().length > 0 && !x.startsWith('#')); // Remove empty lines and comments
|
|
|
|
|
|
|
|
|
|
results = wildcards.filter(x => (wcWord !== null && wcWord.length > 0) ? x.toLowerCase().includes(wcWord) : x) // Filter by tagword
|
|
|
|
|
@@ -584,15 +586,15 @@ function navigateInList(textArea, event) {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var styleAdded = false;
|
|
|
|
|
onUiUpdate(async function () {
|
|
|
|
|
// One-time setup
|
|
|
|
|
document.addEventListener("DOMContentLoaded", async () => {
|
|
|
|
|
// Get our tag base path from the temp file
|
|
|
|
|
let tagBasePath = await readFile("file/tmp/tagAutocompletePath.txt");
|
|
|
|
|
let tagBasePath = await readFile(`file/tmp/tagAutocompletePath.txt?${new Date().getTime()}`);
|
|
|
|
|
|
|
|
|
|
// Load config
|
|
|
|
|
if (acConfig === null) {
|
|
|
|
|
try {
|
|
|
|
|
acConfig = JSON.parse(await readFile(`file/${tagBasePath}/config.json`));
|
|
|
|
|
acConfig = JSON.parse(await readFile(`file/${tagBasePath}/config.json?${new Date().getTime()}`));
|
|
|
|
|
if (acConfig.translation.onlyShowTranslation) {
|
|
|
|
|
acConfig.translation.searchByTranslation = true; // if only show translation, enable search by translation is necessary
|
|
|
|
|
}
|
|
|
|
|
@@ -604,7 +606,7 @@ onUiUpdate(async function () {
|
|
|
|
|
// Load main tags and translations
|
|
|
|
|
if (allTags.length === 0) {
|
|
|
|
|
try {
|
|
|
|
|
allTags = await loadCSV(`file/${tagBasePath}/${acConfig.tagFile}`);
|
|
|
|
|
allTags = await loadCSV(`file/${tagBasePath}/${acConfig.tagFile}?${new Date().getTime()}`);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error("Error loading tags file: " + e);
|
|
|
|
|
return;
|
|
|
|
|
@@ -638,16 +640,16 @@ onUiUpdate(async function () {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Load wildcards
|
|
|
|
|
if (wildcardFiles.length === 0 && acConfig.useWildcards) {
|
|
|
|
|
if (acConfig.useWildcards && wildcardFiles.length === 0) {
|
|
|
|
|
try {
|
|
|
|
|
let wcFileArr = (await readFile(`file/${tagBasePath}/temp/wc.txt`)).split("\n");
|
|
|
|
|
let wcFileArr = (await readFile(`file/${tagBasePath}/temp/wc.txt?${new Date().getTime()}`)).split("\n");
|
|
|
|
|
let wcBasePath = wcFileArr[0].trim(); // First line should be the base path
|
|
|
|
|
wildcardFiles = wcFileArr.slice(1)
|
|
|
|
|
.filter(x => x.trim().length > 0) // Remove empty lines
|
|
|
|
|
.map(x => [wcBasePath, x.trim().replace(".txt", "")]); // Remove file extension & newlines
|
|
|
|
|
|
|
|
|
|
// To support multiple sources, we need to separate them using the provided "-----" strings
|
|
|
|
|
let wcExtFileArr = (await readFile(`file/${tagBasePath}/temp/wce.txt`)).split("\n");
|
|
|
|
|
let wcExtFileArr = (await readFile(`file/${tagBasePath}/temp/wce.txt?${new Date().getTime()}`)).split("\n");
|
|
|
|
|
let splitIndices = [];
|
|
|
|
|
for (let index = 0; index < wcExtFileArr.length; index++) {
|
|
|
|
|
if (wcExtFileArr[index].trim() === "-----") {
|
|
|
|
|
@@ -674,9 +676,9 @@ onUiUpdate(async function () {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Load embeddings
|
|
|
|
|
if (embeddings.length === 0 && acConfig.useEmbeddings) {
|
|
|
|
|
if (acConfig.useEmbeddings && embeddings.length === 0) {
|
|
|
|
|
try {
|
|
|
|
|
embeddings = (await readFile(`file/${tagBasePath}/temp/emb.txt`)).split("\n")
|
|
|
|
|
embeddings = (await readFile(`file/${tagBasePath}/temp/emb.txt?${new Date().getTime()}`)).split("\n")
|
|
|
|
|
.filter(x => x.trim().length > 0) // Remove empty lines
|
|
|
|
|
.map(x => x.replace(".bin", "").replace(".pt", "").replace(".png", "")); // Remove file extensions
|
|
|
|
|
} catch (e) {
|
|
|
|
|
@@ -705,7 +707,6 @@ onUiUpdate(async function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textAreas.forEach(area => {
|
|
|
|
|
|
|
|
|
|
// Return if autocomplete is disabled for the current area type in config
|
|
|
|
|
let textAreaId = getTextAreaIdentifier(area);
|
|
|
|
|
if ((!acConfig.activeIn.img2img && textAreaId.includes("img2img"))
|
|
|
|
|
@@ -734,8 +735,9 @@ onUiUpdate(async function () {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
acAppendComma = acConfig.appendComma;
|
|
|
|
|
// Add our custom options elements
|
|
|
|
|
if (gradioApp().querySelector("#tagAutocompleteOptions") === null) {
|
|
|
|
|
if (!acConfig.hideUIOptions && gradioApp().querySelector("#tagAutocompleteOptions") === null) {
|
|
|
|
|
let optionsDiv = document.createElement("div");
|
|
|
|
|
optionsDiv.id = "tagAutocompleteOptions";
|
|
|
|
|
optionsDiv.classList.add("flex", "flex-col", "p-1", "px-1", "relative", "text-sm");
|
|
|
|
|
@@ -756,7 +758,6 @@ onUiUpdate(async function () {
|
|
|
|
|
});
|
|
|
|
|
// Add comma switch
|
|
|
|
|
let cbComma = createCheckbox("Append commas");
|
|
|
|
|
acAppendComma = acConfig.appendComma;
|
|
|
|
|
cbComma.querySelector("input").checked = acAppendComma;
|
|
|
|
|
cbComma.querySelector("input").addEventListener("change", (e) => {
|
|
|
|
|
acAppendComma = e.target.checked;
|
|
|
|
|
@@ -771,8 +772,6 @@ onUiUpdate(async function () {
|
|
|
|
|
quicksettings.parentNode.insertBefore(optionsDiv, quicksettings.nextSibling);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (styleAdded) return;
|
|
|
|
|
|
|
|
|
|
// Add style to dom
|
|
|
|
|
let acStyle = document.createElement('style');
|
|
|
|
|
let css = gradioApp().querySelector('.dark') ? autocompleteCSS_dark : autocompleteCSS_light;
|
|
|
|
|
|