update
parent
c4e856c5eb
commit
f321d7d13d
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2025 Haoming
|
Copyright (c) 2026 Haoming
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,11 @@ class pfConfigs {
|
||||||
|
|
||||||
/** @returns {string[]} */
|
/** @returns {string[]} */
|
||||||
static cacheCards() {
|
static cacheCards() {
|
||||||
const cards = document.getElementById("pf_embeddings").querySelector("textarea").value.split("\n");
|
const cards = new Set();
|
||||||
const config = document.getElementById("setting_pf_exclusion").querySelector("textarea").value;
|
const embeddings = document.getElementById("pf_embeddings").querySelector("textarea").value;
|
||||||
for (const tag of config.split(",").map((t) => t.trim())) if (tag) cards.push(tag);
|
for (const tag of embeddings.split("\n").map((t) => t.trim())) if (tag) cards.add(tag);
|
||||||
|
const settings = document.getElementById("setting_pf_exclusion").querySelector("textarea").value;
|
||||||
|
for (const tag of settings.split(",").map((t) => t.trim())) if (tag) cards.add(tag);
|
||||||
return cards;
|
return cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,21 +69,10 @@ class pfConfigs {
|
||||||
|
|
||||||
for (const line of config.split("\n")) {
|
for (const line of config.split("\n")) {
|
||||||
const [tag, words] = line.split(":");
|
const [tag, words] = line.split(":");
|
||||||
const mainTag = tag.trim();
|
const pattern = new RegExp(words);
|
||||||
|
alias.set(pattern, tag);
|
||||||
for (const word of words.split(",").map((part) => part.trim())) {
|
|
||||||
if (word === mainTag) continue;
|
|
||||||
|
|
||||||
const pattern = this.#parseRegExp(word);
|
|
||||||
alias.set(pattern, mainTag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return alias;
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param {string} input @returns {RegExp} */
|
|
||||||
static #parseRegExp(input) {
|
|
||||||
return new RegExp(`^${input.trimStart("^").trimEnd("$")}$`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
class pfUI {
|
class pfUI {
|
||||||
/** @param {string} text @param {string} tip @returns {HTMLButtonElement} */
|
/** @param {string} text @param {string} hint @returns {HTMLButtonElement} */
|
||||||
static #button(text, tip) {
|
static #button(text, hint) {
|
||||||
const button = document.createElement("button");
|
const button = document.createElement("button");
|
||||||
button.classList.add(["lg", "secondary", "gradio-button"]);
|
button.classList.add(["lg", "secondary", "gradio-button"]);
|
||||||
button.textContent = text;
|
button.textContent = text;
|
||||||
if (tip) button.title = tip;
|
if (hint) button.title = hint;
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -14,10 +14,8 @@ class pfUI {
|
||||||
label.classList.add("pf-checkbox");
|
label.classList.add("pf-checkbox");
|
||||||
label.removeAttribute("id");
|
label.removeAttribute("id");
|
||||||
|
|
||||||
const checkbox = label.children[0];
|
label.children[0].checked = value;
|
||||||
checkbox.checked = value;
|
label.children[1].textContent = text;
|
||||||
const span = label.children[1];
|
|
||||||
span.textContent = text;
|
|
||||||
|
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
@ -27,26 +25,26 @@ class pfUI {
|
||||||
const formatter = document.createElement("div");
|
const formatter = document.createElement("div");
|
||||||
formatter.id = "le-formatter";
|
formatter.id = "le-formatter";
|
||||||
|
|
||||||
|
const autoCB = this.#checkbox(autoRun, "Auto Format");
|
||||||
|
const dedupeCB = this.#checkbox(dedupe, "Remove Duplicates");
|
||||||
|
const underscoreCB = this.#checkbox(rmUnderscore, "Remove Underscores");
|
||||||
|
|
||||||
const manualBtn = this.#button("Format", "Manually Format the Prompts");
|
const manualBtn = this.#button("Format", "Manually Format the Prompts");
|
||||||
manualBtn.style.display = autoRun ? "none" : "flex";
|
manualBtn.style.display = autoRun ? "none" : "flex";
|
||||||
const refreshBtn = this.#button("Reload", "Reload Exclusion & Alias");
|
const refreshBtn = this.#button("Reload", "Reload Exclusion & Alias");
|
||||||
refreshBtn.style.display = rmUnderscore ? "flex" : "none";
|
refreshBtn.style.display = rmUnderscore ? "flex" : "none";
|
||||||
|
|
||||||
const autoCB = this.#checkbox(autoRun, "Auto Format");
|
|
||||||
const dedupeCB = this.#checkbox(dedupe, "Remove Duplicates");
|
|
||||||
const underscoreCB = this.#checkbox(rmUnderscore, "Remove Underscores");
|
|
||||||
|
|
||||||
formatter.appendChild(autoCB);
|
formatter.appendChild(autoCB);
|
||||||
formatter.appendChild(manualBtn);
|
formatter.appendChild(manualBtn);
|
||||||
formatter.appendChild(dedupeCB);
|
formatter.appendChild(dedupeCB);
|
||||||
formatter.appendChild(underscoreCB);
|
formatter.appendChild(underscoreCB);
|
||||||
formatter.appendChild(refreshBtn);
|
formatter.appendChild(refreshBtn);
|
||||||
|
|
||||||
formatter.manual = manualBtn;
|
|
||||||
formatter.refresh = refreshBtn;
|
|
||||||
formatter.auto = autoCB.children[0];
|
formatter.auto = autoCB.children[0];
|
||||||
|
formatter.manual = manualBtn;
|
||||||
formatter.dedupe = dedupeCB.children[0];
|
formatter.dedupe = dedupeCB.children[0];
|
||||||
formatter.underscore = underscoreCB.children[0];
|
formatter.underscore = underscoreCB.children[0];
|
||||||
|
formatter.refresh = refreshBtn;
|
||||||
|
|
||||||
return formatter;
|
return formatter;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,58 +62,28 @@ def on_settings():
|
||||||
.needs_reload_ui(),
|
.needs_reload_ui(),
|
||||||
)
|
)
|
||||||
|
|
||||||
opts.add_option(
|
for label, desc in [
|
||||||
"pf_startinauto",
|
("pf_startinauto", 'Launch the WebUI with "Auto Format" enabled'),
|
||||||
OptionInfo(
|
("pf_startwithdedupe", 'Launch the WebUI with "Remove Duplicates" enabled'),
|
||||||
True, "Launch the WebUI with Auto Format enabled", **args
|
("pf_startwithrmudscr", 'Launch the WebUI with "Remove Underscores" enabled'),
|
||||||
).needs_reload_ui(),
|
("pf_appendcomma", "Append a comma at the end of each line"),
|
||||||
)
|
("pf_onpaste", "Format the texts pasted from clipboard"),
|
||||||
|
("pf_booru", 'Process the "Booru Structure" on Paste'),
|
||||||
|
]:
|
||||||
|
opts.add_option(label, OptionInfo(True, desc, **args).needs_reload_ui())
|
||||||
|
|
||||||
opts.add_option(
|
_SCORE = "score_1, score_2, score_3, score_7, score_8, score_9"
|
||||||
"pf_startwithdedupe",
|
|
||||||
OptionInfo(
|
|
||||||
True, "Launch the WebUI with Remove Duplicates enabled", **args
|
|
||||||
).needs_reload_ui(),
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.add_option(
|
|
||||||
"pf_startwithrmudscr",
|
|
||||||
OptionInfo(
|
|
||||||
True, "Launch the WebUI with Remove Underscores enabled", **args
|
|
||||||
).needs_reload_ui(),
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.add_option(
|
|
||||||
"pf_appendcomma",
|
|
||||||
OptionInfo(True, "Append a comma at the end of each line", **args)
|
|
||||||
.info("only take effect when there are more than 1 line")
|
|
||||||
.needs_reload_ui(),
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.add_option(
|
|
||||||
"pf_onpaste",
|
|
||||||
OptionInfo(
|
|
||||||
False, "Format the texts pasted from clipboard", **args
|
|
||||||
).needs_reload_ui(),
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.add_option(
|
|
||||||
"pf_booru",
|
|
||||||
OptionInfo(False, 'Process the "Booru Structure"', **args)
|
|
||||||
.info("only take effect when the above option is enabled")
|
|
||||||
.needs_reload_ui(),
|
|
||||||
)
|
|
||||||
|
|
||||||
opts.add_option(
|
opts.add_option(
|
||||||
"pf_exclusion",
|
"pf_exclusion",
|
||||||
OptionInfo(
|
OptionInfo(
|
||||||
default="",
|
default=_SCORE,
|
||||||
label="Tags excluded from Remove Underscores",
|
label='Tags to exclude from "Remove Underscores"',
|
||||||
component=Textbox,
|
component=Textbox,
|
||||||
component_args={
|
component_args={
|
||||||
"placeholder": "score_9, score_8_up, score_7_up",
|
"placeholder": _SCORE,
|
||||||
"max_lines": 4,
|
|
||||||
"lines": 1,
|
"lines": 1,
|
||||||
|
"max_lines": 2,
|
||||||
},
|
},
|
||||||
**args,
|
**args,
|
||||||
).info("requires <b>Reload</b> button"),
|
).info("requires <b>Reload</b> button"),
|
||||||
|
|
@ -123,20 +93,17 @@ def on_settings():
|
||||||
"pf_alias",
|
"pf_alias",
|
||||||
OptionInfo(
|
OptionInfo(
|
||||||
default="",
|
default="",
|
||||||
label="Tag Alias for Remove Duplicates",
|
label='Tag Alias for "Remove Duplicates"',
|
||||||
component=Textbox,
|
component=Textbox,
|
||||||
component_args={
|
component_args={
|
||||||
"placeholder": "1girl: girl, woman, lady\nadult: \\d+\\s*(y\\.?o\\.?|[Yy]ear[s]? [Oo]ld)",
|
"placeholder": "1girl:girl|woman|lady",
|
||||||
"max_lines": 8,
|
"max_lines": 8,
|
||||||
"lines": 2,
|
"lines": 2,
|
||||||
},
|
},
|
||||||
**args,
|
**args,
|
||||||
)
|
)
|
||||||
.info("requires <b>Reload</b> button")
|
.info("requires <b>Reload</b> button")
|
||||||
.link(
|
.link("RegExr", "https://regexr.com/"),
|
||||||
"Regexper",
|
|
||||||
"https://regexper.com/#%5Cd%2B%5Cs*%28y%5C.%3Fo%5C.%3F%7C%5BYy%5Dear%5Bs%5D%3F%20%5BOo%5Dld%29",
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue