booru
parent
dbccad2215
commit
f01838eb9b
14
README.md
14
README.md
|
|
@ -25,7 +25,7 @@ Sometimes, when you type too fast or copy prompts from all over the places, you
|
|||
- [x] Toggle between auto formatting and manual formatting
|
||||
- In `Auto` mode: The process is ran whenever you click on **Generate**
|
||||
- In `Manual` mode: The process is only ran when you click the **Format** button
|
||||
- [x] **New:** Trigger the formatting when pasting text
|
||||
- [x] **New:** Trigger the formatting on the pasted text
|
||||
- [x] Toggle whether the above features are enabled / disabled by default in the `Prompt Format` section under the <ins>System</ins> category of the **Settings** tab
|
||||
- [x] Pressing `Alt` + `Shift` + `F` can also trigger formatting
|
||||
- [x] Assign "[alias](#tag-alias)" that counts as duplicates for the specified tags
|
||||
|
|
@ -58,3 +58,15 @@ Sometimes, when you type too fast or copy prompts from all over the places, you
|
|||
1. Since the formatting in `Auto` mode is triggered at the same time as the generation, the immediate image might not have its prompts updated.
|
||||
|
||||
2. Some Extensions *(**eg.** [tagcomplete](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete))* listen to the text editing event, meaning the formatting will cause them to be triggered. You can disable updating the actual prompts in the `Prompt Format` settings to prevent this. Though you may need to manually type something else for the prompt to get actually updated.
|
||||
|
||||
<hr>
|
||||
|
||||
<details>
|
||||
<summary><b>Booru</b></summary>
|
||||
|
||||
- [x] Automatically clean up unwanted texts
|
||||
- Structure is based on [gelbooru](https://gelbooru.com/)
|
||||
|
||||
<p align="center"><img src="booru.png" width=512></p>
|
||||
|
||||
</details>
|
||||
|
|
|
|||
14
README_ZH.md
14
README_ZH.md
|
|
@ -25,7 +25,7 @@
|
|||
- [x] 按下`Auto Format`以在手動與自動間切換
|
||||
- `自動`: 每次按下 **生成 (Generate)** 時處裡
|
||||
- `手動`: 手動按下 **Format** 時才處裡
|
||||
- [x] **新功能:** 處裡貼上的咒語
|
||||
- [x] **新功能:** 對貼上的咒語進行處裡
|
||||
- [x] 在 **Settings** 頁面 <ins>System</ins> 下的 `Prompt Format` 區可以 開啟/關閉 上述功能
|
||||
- [x] 按下 `Alt` + `Shift` + `F` 亦可觸發格式化
|
||||
- [x] 為指定單字新增 "[同義詞](#同義詞)"
|
||||
|
|
@ -58,3 +58,15 @@
|
|||
1. 由於 `自動`校正 和 生成 是同時觸發,當下所生產的第一張圖片之咒語可能不會是已更新的。
|
||||
|
||||
2. 有些擴充 *(如. [tagcomplete](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete))* 追蹤文字的編輯事件,意即文字校正會導致它們啟動。你可以到設定關閉咒語的自動更新。
|
||||
|
||||
<hr>
|
||||
|
||||
<details>
|
||||
<summary><b>Booru</b></summary>
|
||||
|
||||
- [x] 自動清除多餘字詞
|
||||
- 文字結構基於 [gelbooru](https://gelbooru.com/)
|
||||
|
||||
<p align="center"><img src="booru.png" width=512></p>
|
||||
|
||||
</details>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ class pfConfigs {
|
|||
this.removeUnderscore = this.#defaultRemoveUnderscore();
|
||||
this.comma = this.#appendComma();
|
||||
this.paste = this.#onpaste();
|
||||
this.booru = this.#procBooru();
|
||||
|
||||
this.promptFields = this.#getPromptFields();
|
||||
}
|
||||
|
||||
|
|
@ -46,6 +48,12 @@ class pfConfigs {
|
|||
return config.checked;
|
||||
}
|
||||
|
||||
/** @returns {boolean} */
|
||||
#procBooru() {
|
||||
const config = document.getElementById('setting_pf_booru').querySelector('input[type=checkbox]');
|
||||
return config.checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache All Prompt Fields
|
||||
* @returns {HTMLTextAreaElement[]}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ class LeFormatter {
|
|||
/** @param {string} input @param {boolean} dedupe @param {boolean} removeUnderscore @returns {string} */
|
||||
static formatString(input, dedupe, removeUnderscore) {
|
||||
|
||||
// Remove Underscore
|
||||
input = removeUnderscore ? this.#removeUnderscore(input) : input;
|
||||
|
||||
// Fix Commas inside Brackets
|
||||
input = input
|
||||
.replace(/[,\s]+\)/g, '),')
|
||||
|
|
@ -72,9 +75,6 @@ class LeFormatter {
|
|||
.replace(/\s*\|\s*/g, '|')
|
||||
.replace(/\s*\:\s*/g, ':');
|
||||
|
||||
// Remove Underscore
|
||||
input = removeUnderscore ? this.#removeUnderscore(input) : input;
|
||||
|
||||
// Sentence -> Tags
|
||||
let tags = input.split(',').map(word => word.trim());
|
||||
|
||||
|
|
@ -146,7 +146,6 @@ class LeFormatter {
|
|||
if (/^\s+$/.test(part))
|
||||
return part;
|
||||
|
||||
part = part.trim();
|
||||
if (!this.#cachedCards.includes(part))
|
||||
part = part.replaceAll('_', ' ');
|
||||
|
||||
|
|
@ -220,6 +219,16 @@ onUiLoaded(() => {
|
|||
event.preventDefault();
|
||||
|
||||
let paste = (event.clipboardData || window.clipboardData).getData('text');
|
||||
|
||||
if (config.booru) {
|
||||
paste = paste.replace(/\s\d+|\?\s+/g, ", ");
|
||||
for (const excl of ["Artist", "Character", "Copyright", "Tag"])
|
||||
paste = paste.replace(excl, "");
|
||||
|
||||
paste = paste.replaceAll("(", "\\(");
|
||||
paste = paste.replaceAll(")", "\\)");
|
||||
}
|
||||
|
||||
paste = LeFormatter.formatString(paste, config.dedupe, config.removeUnderscore);
|
||||
|
||||
const currentText = field.value;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,13 @@ def on_settings():
|
|||
|
||||
opts.add_option(
|
||||
"pf_disableupdateinput",
|
||||
OptionInfo(False, "Disable the automatic updates of the prompts", **args).info(
|
||||
'enable this if you have Extensions, such as <a href="https://github.com/DominikDoom/a1111-sd-webui-tagcomplete">tagcomplete</a>, that subscribe to text editing events'
|
||||
),
|
||||
OptionInfo(False, "Disable the automatic updates of the prompts", **args)
|
||||
.info(
|
||||
"""enable this if you have Extensions, such as
|
||||
<a href="https://github.com/DominikDoom/a1111-sd-webui-tagcomplete">tagcomplete</a>,
|
||||
that subscribe to text editing events"""
|
||||
)
|
||||
.needs_reload_ui(),
|
||||
)
|
||||
|
||||
opts.add_option(
|
||||
|
|
@ -31,14 +35,14 @@ def on_settings():
|
|||
|
||||
opts.add_option(
|
||||
"pf_appendcomma",
|
||||
OptionInfo(True, "Append a comma at the end of each line", **args).info(
|
||||
"only active when there are multiple lines"
|
||||
),
|
||||
OptionInfo(True, "Append a comma at the end of each line", **args)
|
||||
.info("only take effect when there are multiple lines")
|
||||
.needs_reload_ui(),
|
||||
)
|
||||
|
||||
opts.add_option(
|
||||
"pf_onpaste",
|
||||
OptionInfo(False, "Trigger a Format when pasting text", **args),
|
||||
OptionInfo(False, "Format the pasted text", **args).needs_reload_ui(),
|
||||
)
|
||||
|
||||
opts.add_option(
|
||||
|
|
@ -52,7 +56,7 @@ def on_settings():
|
|||
"max_lines": 1,
|
||||
"lines": 1,
|
||||
},
|
||||
**args
|
||||
**args,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -67,7 +71,7 @@ def on_settings():
|
|||
"max_lines": 16,
|
||||
"lines": 4,
|
||||
},
|
||||
**args
|
||||
**args,
|
||||
)
|
||||
.link("RegExr", "https://regexr.com/")
|
||||
.info(
|
||||
|
|
@ -77,5 +81,14 @@ def on_settings():
|
|||
),
|
||||
)
|
||||
|
||||
opts.add_option(
|
||||
"pf_booru",
|
||||
OptionInfo(
|
||||
False,
|
||||
'Process the "Booru Structure"',
|
||||
**args,
|
||||
).info("requires format on paste) (<b>Experimental</b>"),
|
||||
)
|
||||
|
||||
|
||||
on_ui_settings(on_settings)
|
||||
|
|
|
|||
Loading…
Reference in New Issue