Upload 1064 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- a1111-sd-webui-tagcomplete-main/.gitignore +2 -0
- a1111-sd-webui-tagcomplete-main/LICENSE +21 -0
- a1111-sd-webui-tagcomplete-main/README.md +598 -0
- a1111-sd-webui-tagcomplete-main/README_JA.md +522 -0
- a1111-sd-webui-tagcomplete-main/README_ZH.md +179 -0
- a1111-sd-webui-tagcomplete-main/javascript/__globals.js +64 -0
- a1111-sd-webui-tagcomplete-main/javascript/_baseParser.js +21 -0
- a1111-sd-webui-tagcomplete-main/javascript/_caretPosition.js +145 -0
- a1111-sd-webui-tagcomplete-main/javascript/_result.js +37 -0
- a1111-sd-webui-tagcomplete-main/javascript/_textAreas.js +190 -0
- a1111-sd-webui-tagcomplete-main/javascript/_utils.js +278 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_chants.js +54 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_embeddings.js +65 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_hypernets.js +52 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_loras.js +64 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_lycos.js +64 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_modelKeyword.js +42 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_umi.js +245 -0
- a1111-sd-webui-tagcomplete-main/javascript/ext_wildcards.js +178 -0
- a1111-sd-webui-tagcomplete-main/javascript/tagAutocomplete.js +1431 -0
- a1111-sd-webui-tagcomplete-main/scripts/__pycache__/model_keyword_support.cpython-310.pyc +0 -0
- a1111-sd-webui-tagcomplete-main/scripts/__pycache__/shared_paths.cpython-310.pyc +0 -0
- a1111-sd-webui-tagcomplete-main/scripts/__pycache__/tag_autocomplete_helper.cpython-310.pyc +0 -0
- a1111-sd-webui-tagcomplete-main/scripts/model_keyword_support.py +81 -0
- a1111-sd-webui-tagcomplete-main/scripts/shared_paths.py +71 -0
- a1111-sd-webui-tagcomplete-main/scripts/tag_autocomplete_helper.py +570 -0
- a1111-sd-webui-tagcomplete-main/tags/danbooru.csv +0 -0
- a1111-sd-webui-tagcomplete-main/tags/demo-chants.json +32 -0
- a1111-sd-webui-tagcomplete-main/tags/e621.csv +0 -0
- a1111-sd-webui-tagcomplete-main/tags/e621_sfw.csv +0 -0
- a1111-sd-webui-tagcomplete-main/tags/extra-quality-tags.csv +6 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/emb.txt +0 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/hyp.txt +0 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/known_lora_hashes.txt +0 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/lora.txt +6 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/lyco.txt +0 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/umi_tags.txt +0 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/wc.txt +0 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/wc_yaml.json +1 -0
- a1111-sd-webui-tagcomplete-main/tags/temp/wce.txt +0 -0
- put extensions here.txt +0 -0
- sd-webui-controlnet-main/.github/ISSUE_TEMPLATE/bug_report.yml +91 -0
- sd-webui-controlnet-main/.github/ISSUE_TEMPLATE/config.yml +1 -0
- sd-webui-controlnet-main/.github/workflows/tests.yml +113 -0
- sd-webui-controlnet-main/.gitignore +179 -0
- sd-webui-controlnet-main/LICENSE +674 -0
- sd-webui-controlnet-main/README.md +242 -0
- sd-webui-controlnet-main/__pycache__/preload.cpython-310.pyc +0 -0
- sd-webui-controlnet-main/annotator/__pycache__/annotator_path.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -53,3 +53,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
sd-webui-controlnet-main/annotator/downloads/midas/tmpvn4t6ofw filter=lfs diff=lfs merge=lfs -text
|
a1111-sd-webui-tagcomplete-main/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tags/temp/
|
| 2 |
+
__pycache__/
|
a1111-sd-webui-tagcomplete-main/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2022 Dominik Reh
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR O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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 2 |
+
|
| 3 |
+
<div align="center">
|
| 4 |
+
|
| 5 |
+
# SD WebUI Tag Autocomplete
|
| 6 |
+
## English • [简体中文](./README_ZH.md) • [日本語](./README_JA.md)
|
| 7 |
+
|
| 8 |
+
Booru style tag autocompletion for the AUTOMATIC1111 Stable Diffusion WebUI
|
| 9 |
+
|
| 10 |
+
[![Github Release][release-shield]][release-url]
|
| 11 |
+
[![stargazers][stargazers-shield]][stargazers-url]
|
| 12 |
+
[![contributors][contributors-shield]][contributors-url]
|
| 13 |
+
[![forks][forks-shield]][forks-url]
|
| 14 |
+
[![issues][issues-shield]][issues-url]
|
| 15 |
+
|
| 16 |
+
[Changelog][release-url] •
|
| 17 |
+
[Known Issues](#%EF%B8%8F-common-problems--known-issues) •
|
| 18 |
+
[Report Bug][issues-url] •
|
| 19 |
+
[Request Feature][issues-url]
|
| 20 |
+
</div>
|
| 21 |
+
<br/>
|
| 22 |
+
|
| 23 |
+
# 📄 Description
|
| 24 |
+
|
| 25 |
+
Tag Autocomplete is an extension for the popular [AUTOMATIC1111 web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) for Stable Diffusion.
|
| 26 |
+
|
| 27 |
+
It displays autocompletion hints for recognized tags from "image booru" boards such as Danbooru, which are primarily used for browsing Anime-style illustrations.
|
| 28 |
+
Since some Stable Diffusion models were trained using this information, for example [Waifu Diffusion](https://github.com/harubaru/waifu-diffusion) and many of the NAI-descendant models or merges, using exact tags in prompts can often improve composition and consistency.
|
| 29 |
+
|
| 30 |
+
You can install it using the inbuilt available extensions list, clone the files manually as described [below](#-installation), or use a pre-packaged version from [Releases](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/releases).
|
| 31 |
+
|
| 32 |
+
<br/>
|
| 33 |
+
|
| 34 |
+
# ✨ Features
|
| 35 |
+
- 🚀 Instant completion hints while typing (under normal circumstances)
|
| 36 |
+
- ⌨️ Keyboard navigation
|
| 37 |
+
- 🌒 Dark & Light mode support
|
| 38 |
+
- 🛠️ Many [settings](#%EF%B8%8F-settings) and customizability
|
| 39 |
+
- 🌍 [Translation support](#translations) for tags, with optional live preview for the full prompt
|
| 40 |
+
- **Note:** Translation files are provided by the community, see [here](#list-of-translations) for a list of translations I know of.
|
| 41 |
+
|
| 42 |
+
Tag autocomplete supports built-in completion for:
|
| 43 |
+
- 🏷️ **Danbooru & e621 tags** (Top 100k by post count, as of November 2022)
|
| 44 |
+
- ✳️ [**Wildcards**](#wildcards)
|
| 45 |
+
- ➕ [**Extra network**](#extra-networks-embeddings-hypernets-lora-) filenames, including
|
| 46 |
+
- Textual Inversion embeddings [(jump to readme section)]
|
| 47 |
+
- Hypernetworks
|
| 48 |
+
- LoRA
|
| 49 |
+
- LyCORIS / LoHA
|
| 50 |
+
- 🪄 [**Chants**](#chants) (custom format for longer prompt presets)
|
| 51 |
+
- 🏷️ "[**Extra file**](#extra-file)", one set of customizable extra tags
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
Additionally, some support for other third party extensions exists:
|
| 55 |
+
<details>
|
| 56 |
+
<summary>Click to expand</summary>
|
| 57 |
+
|
| 58 |
+
- [Image Browser][image-browser-url] - Filename & EXIF keyword search
|
| 59 |
+
- [Multidiffusion Upscaler][multidiffusion-url] - Regional Prompts
|
| 60 |
+
- [Dataset Tag Editor][tag-editor-url] - Caption, Interrogate Result, Edit Tags & Edit Caption
|
| 61 |
+
- [WD 1.4 Tagger][wd-tagger-url] - Additional & Excluded tags
|
| 62 |
+
- [Umi AI][umi-url] - Completion for YAML wildcards
|
| 63 |
+
</details>
|
| 64 |
+
<br/>
|
| 65 |
+
|
| 66 |
+
# 🖼️ Screenshots & Demo videos
|
| 67 |
+
<details>
|
| 68 |
+
<summary>Click to expand</summary>
|
| 69 |
+
Basic usage (with keyboard navigation):
|
| 70 |
+
|
| 71 |
+
https://user-images.githubusercontent.com/34448969/200128020-10d9a8b2-cea6-4e3f-bcd2-8c40c8c73233.mp4
|
| 72 |
+
|
| 73 |
+
Wildcard script support:
|
| 74 |
+
|
| 75 |
+
https://user-images.githubusercontent.com/34448969/200128031-22dd7c33-71d1-464f-ae36-5f6c8fd49df0.mp4
|
| 76 |
+
|
| 77 |
+
Extra Network preview support:
|
| 78 |
+
|
| 79 |
+
https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/assets/34448969/3c0cad84-fb5f-436d-b05a-28db35860d13
|
| 80 |
+
|
| 81 |
+
Dark and Light mode supported, including tag colors:
|
| 82 |
+
|
| 83 |
+

|
| 84 |
+

|
| 85 |
+
</details>
|
| 86 |
+
<br/>
|
| 87 |
+
|
| 88 |
+
# 📦 Installation
|
| 89 |
+
## Using the built-in extension list
|
| 90 |
+
1. Open the `Extensions` tab
|
| 91 |
+
2. Open the `Available` sub-tab
|
| 92 |
+
3. Click **Load from**
|
| 93 |
+
4. Find **Booru tag autocompletion** in the list
|
| 94 |
+
- The extension was one of the first available, so selecting "oldest first" will show it high up in the list.
|
| 95 |
+
- Alternatively, use <kbd>CRTL</kbd> + <kbd>F</kbd> to search for the text on the page
|
| 96 |
+
5. Click **Install** on the right side
|
| 97 |
+
|
| 98 |
+

|
| 99 |
+

|
| 100 |
+

|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
## Manual clone
|
| 104 |
+
```bash
|
| 105 |
+
git clone "https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git" extensions/tag-autocomplete
|
| 106 |
+
```
|
| 107 |
+
(The second argument specifies the name of the folder, you can choose whatever you like).
|
| 108 |
+
|
| 109 |
+
<br/>
|
| 110 |
+
|
| 111 |
+
# ❇️ Additional completion support
|
| 112 |
+
## Wildcards
|
| 113 |
+
Autocompletion also works with wildcard files used by https://github.com/AUTOMATIC1111/stable-diffusion-webui-wildcards or other similar scripts/extensions.
|
| 114 |
+
Completion is triggered by typing `__` (double underscore). It will first show a list of your wildcard files, and upon choosing one, the replacement options inside that file.
|
| 115 |
+
This enables you to either insert categories to be replaced by the script, or directly choose one and use wildcards as a sort of categorized custom tag system.
|
| 116 |
+
|
| 117 |
+

|
| 118 |
+

|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
Wildcards are searched for in every extension folder, as well as the `scripts/wildcards` folder to support legacy versions. This means that you can combine wildcards from multiple extensions. Nested folders are also supported if you have grouped your wildcards in that way.
|
| 122 |
+
|
| 123 |
+
## Extra networks (Embeddings, Hypernets, LoRA, ...)
|
| 124 |
+
Completion for these types is triggered by typing `<`. By default it will show them all mixed together, but further filtering can be done in the following way:
|
| 125 |
+
- `<e:` will only show embeddings
|
| 126 |
+
- `<l:` will only show LoRA and LyCORIS
|
| 127 |
+
- Or `<lora:` and `<lyco:` respectively for the long form
|
| 128 |
+
- `<h:` or `<hypernet:` will only show Hypernetworks
|
| 129 |
+
|
| 130 |
+
### Live previews
|
| 131 |
+
Tag Autocomplete will now also show the preview images used for the cards in the Extra Networks menu in a small window next to the regular popup.
|
| 132 |
+
This enables quick comparisons and additional info for unclear filenames without having to stop typing to look it up in the webui menu.
|
| 133 |
+
It works for all supported extra network types that use preview images (Loras/Lycos, Embeddings & Hypernetworks). The preview window will stay hidden for normal tags or if no preview was found.
|
| 134 |
+
|
| 135 |
+

|
| 136 |
+
|
| 137 |
+
### Lora / Lyco trigger word completion
|
| 138 |
+
This feature will try to add known trigger words on autocompleting a Lora/Lyco.
|
| 139 |
+
|
| 140 |
+
It primarily uses the list provided by the [model-keyword](https://github.com/mix1009/model-keyword/) extension, which thus needs to be installed to use this feature. The list is also regularly updated through it.
|
| 141 |
+
However, once installed, you can deactivate it if you want, since tag autocomplete only needs the local keyword lists it ships with, not the extension itself.
|
| 142 |
+
The used files are `lora-keyword.txt` and `lora-keyword-user.txt` in the model-keyword installation folder.
|
| 143 |
+
If the main file isn't found, the feature will simply deactivate itself, everything else should work normally.
|
| 144 |
+
|
| 145 |
+
#### Note:
|
| 146 |
+
As of [v1.5.0](https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/a3ddf464a2ed24c999f67ddfef7969f8291567be), the webui provides a native method to add activation keywords for Lora through the Extra networks config UI.
|
| 147 |
+
These trigger words will always be preferred over the model-keyword ones and can be used without needing to install the model-keyword extension. This will however, obviously, be limited to those manually added keywords. For automatic discovery of keywords, you will still need the big list provided by model-keyword.
|
| 148 |
+
|
| 149 |
+
Custom trigger words can be added through two methods:
|
| 150 |
+
1. Using the extra networks UI (recommended):
|
| 151 |
+
- Only works with webui version v1.5.0 upwards, but much easier to use and works without the model-keyword extension
|
| 152 |
+
- This method requires no manual refresh
|
| 153 |
+
- <details>
|
| 154 |
+
<summary>Image example</summary>
|
| 155 |
+
|
| 156 |
+

|
| 157 |
+

|
| 158 |
+
</details>
|
| 159 |
+
2. Through the model-keyword UI:
|
| 160 |
+
- One issue with this method is that it has no official support for the Lycoris extension and doesn't scan its folder for files, so to add them through the UI you will have to temporarily move them into the Lora model folder to be able to select them in model-keywords dropdown. Some are already included in the default list though, so trying it out first is advisable.
|
| 161 |
+
- After having added your custom keywords, you will need to either restart the UI or use the "Refresh TAC temp files" setting button.
|
| 162 |
+
- <details>
|
| 163 |
+
<summary>Image example</summary>
|
| 164 |
+
|
| 165 |
+

|
| 166 |
+
</details>
|
| 167 |
+
|
| 168 |
+
Sometimes the inserted keywords can be wrong due to a hash collision, however model-keyword and tag autocomplete take the name of the file into account too if the collision is known.
|
| 169 |
+
|
| 170 |
+
If it still inserts something wrong or you simply don't want the keywords added that time, you can undo / redo it directly after as often as you want, until you type something else
|
| 171 |
+
(It uses the default undo/redo action of the browser, so <kbd>CTRL</kbd> + <kbd>Z</kbd>, context menu and mouse macros should all work).
|
| 172 |
+
|
| 173 |
+
### Embedding type filtering
|
| 174 |
+
Embeddings trained for Stable Diffusion 1.x or 2.x models respectively are incompatible with the other type. To make it easier to find valid embeds, they are categorized by "v1 Embedding" and "v2 Embedding", including a slight color difference. You can also filter your search to include only v1 or v2 embeddings by typing `<v1/2` or `<e:v1/2` followed by the actual search term.
|
| 175 |
+
|
| 176 |
+
For example:
|
| 177 |
+
|
| 178 |
+

|
| 179 |
+
|
| 180 |
+
## Chants
|
| 181 |
+
Chants are longer prompt presets. The name is inspired by some early prompt collections from Chinese users, which often were called along the lines of "Spellbook", "Codex", etc. The prompt snippets from such documents were fittingly called spells or chants for this reason.
|
| 182 |
+
|
| 183 |
+
Similar to embeddings and loras, this feature is triggered by typing the `<`, `<c:` or `<chant:` commands. For instance, when you enter `<c:HighQuality` in the prompt box and select it, the following prompt text will be inserted:
|
| 184 |
+
```
|
| 185 |
+
(masterpiece, best quality, high quality, highres, ultra-detailed),
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
Chants can be added in JSON files following this format:
|
| 190 |
+
<details>
|
| 191 |
+
<summary>Chant format (click to expand)</summary>
|
| 192 |
+
|
| 193 |
+
```json
|
| 194 |
+
[
|
| 195 |
+
{
|
| 196 |
+
"name": "Basic-NegativePrompt",
|
| 197 |
+
"terms": "Negative,Low,Quality",
|
| 198 |
+
"content": "(worst quality, low quality, normal quality)",
|
| 199 |
+
"color": 3
|
| 200 |
+
},
|
| 201 |
+
{
|
| 202 |
+
"name": "Basic-HighQuality",
|
| 203 |
+
"terms": "Best,High,Quality",
|
| 204 |
+
"content": "(masterpiece, best quality, high quality, highres, ultra-detailed)",
|
| 205 |
+
"color": 1
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"name": "Basic-Start",
|
| 209 |
+
"terms": "Basic, Start, Simple, Demo",
|
| 210 |
+
"content": "(masterpiece, best quality, high quality, highres), 1girl, extremely beautiful detailed face, ...",
|
| 211 |
+
"color": 5
|
| 212 |
+
}
|
| 213 |
+
]
|
| 214 |
+
```
|
| 215 |
+
</details>
|
| 216 |
+
<br/>
|
| 217 |
+
|
| 218 |
+
The file can then be selected using the "Chant file" settings dropdown if it is located inside the extension's `tags` folder.
|
| 219 |
+
|
| 220 |
+
A chant object has four fields:
|
| 221 |
+
- `name` - Display name
|
| 222 |
+
- `terms` - Search terms
|
| 223 |
+
- `content` - The actual prompt content
|
| 224 |
+
- `color` - Color, using the same category color system as normal tags
|
| 225 |
+
|
| 226 |
+
## Umi AI tags
|
| 227 |
+
https://github.com/Klokinator/Umi-AI is a feature-rich wildcard extension similar to Unprompted or Dynamic Wildcards.
|
| 228 |
+
In recent releases, it uses YAML-based wildcard tags to enable a complex chaining system,for example `<[preset][--female][sfw][species]>` will choose the preset category, exclude female related tags, further narrow it down with the following categories, and then choose one random fill-in matching all these criteria at runtime. Completion is triggered by `<[` and then each following new unclosed bracket, e.g. `<[xyz][`, until closed by `>`.
|
| 229 |
+
|
| 230 |
+
Tag Autocomplete can recommend these options in a smart way, meaning while you continue to add category tags, it will only show results still matching what comes before.
|
| 231 |
+
It also shows how many fill-in tags are available to choose from for that combo in place of the tag post count, enabling a quick overview and filtering of the large initial set.
|
| 232 |
+
|
| 233 |
+
Most of the credit goes to [@ctwrs](https://github.com/ctwrs) here, they contributed a lot as one of the Umi developers.
|
| 234 |
+
|
| 235 |
+
# 🛠️ Settings
|
| 236 |
+
|
| 237 |
+
The extension has a large amount of configuration & customizability built in. Most should be self-explanatory, but for a detailed description click on a section below.
|
| 238 |
+
|
| 239 |
+
<!-- Filename -->
|
| 240 |
+
<details>
|
| 241 |
+
<summary>Tag filename</summary>
|
| 242 |
+
|
| 243 |
+
The main tag file the script uses. Included by default are `danbooru.csv` and `e621.csv`. While you can add custom tags here, the vast majority of models are not trained on anything other than these two (mostly danbooru), so it will not have much benefit.
|
| 244 |
+
|
| 245 |
+
You can also set it to `None` if you want to use other functionality of the extension (e.g. Wildcard or LoRA completion), but aren't interested in the normal tags.
|
| 246 |
+
|
| 247 |
+

|
| 248 |
+
</details>
|
| 249 |
+
<!-- Active In -->
|
| 250 |
+
<details>
|
| 251 |
+
<summary>"Active in" settings</summary>
|
| 252 |
+
|
| 253 |
+
Specifies where tag autocomplete should attach itself to and listen for changes.
|
| 254 |
+
Negative prompts follow the settings for txt2img & img2img, so they will only be active if their "parent" is active.
|
| 255 |
+
|
| 256 |
+

|
| 257 |
+
</details>
|
| 258 |
+
<!-- Blacklist -->
|
| 259 |
+
<details>
|
| 260 |
+
<summary>Black / Whitelist</summary>
|
| 261 |
+
|
| 262 |
+
While the above options can turn off tag autocomplete globally, sometimes you might want to enable or disable it only for specific models. For example, if most of your models are Anime ones, you could add your photorealistic models, that weren't trained on booru tags and don't benefit from it, to the blacklist, which will automatically disable it after you switch to these models. You can use both the model name (including file extension) and their webui hashes (both short and long form).
|
| 263 |
+
|
| 264 |
+
`Blacklist` will exclude all specified models, while `Whitelist` will only activate it for these and stay off by default. One exception is an empty whitelist, which will be ignored (making it the same as an empty blacklist).
|
| 265 |
+
|
| 266 |
+

|
| 267 |
+
</details>
|
| 268 |
+
<!-- Move Popup -->
|
| 269 |
+
<details>
|
| 270 |
+
<summary>Move completion popup with cursor</summary>
|
| 271 |
+
|
| 272 |
+
This option enables or disables the floating popup to follow the position of your cursor, like it would do in an IDE. The script tries to reserve enough room for the popup to prevent squishing on the right side, but that doesn't always work for longer tags. If disabled, the popup will stay on the left.
|
| 273 |
+
|
| 274 |
+

|
| 275 |
+
|
| 276 |
+

|
| 277 |
+

|
| 278 |
+
</details>
|
| 279 |
+
<!-- Results Count -->
|
| 280 |
+
<details>
|
| 281 |
+
<summary>Result count</summary>
|
| 282 |
+
|
| 283 |
+
Settings for the amount of results to show at once.
|
| 284 |
+
If `Show all results` is active, it will show a scrollable list instead of cutting it off after the number specified in `Maximum results`. For performance reasons, in that case not all are loaded at once, but instead in blocks. The block size is dictated by `How many results to load at once`. Once you reach the bottom, the next block will load (but that should rarely happen).
|
| 285 |
+
|
| 286 |
+
Notably, `Maximum results` will still have an influence if `Show all results` is used, since it dictates the height of the popup before scrolling begins.
|
| 287 |
+
|
| 288 |
+

|
| 289 |
+
</details>
|
| 290 |
+
<!-- Delay time -->
|
| 291 |
+
<details>
|
| 292 |
+
<summary>Completion delay</summary>
|
| 293 |
+
|
| 294 |
+
Depending on the configuration, real time tag completion can get computationally expensive.
|
| 295 |
+
This option sets a "debounce" delay in milliseconds (1000ms = 1s), during which no second completion will get queried. This might especially be useful if you type very fast.
|
| 296 |
+
|
| 297 |
+

|
| 298 |
+
</details>
|
| 299 |
+
<!-- Search for -->
|
| 300 |
+
<details>
|
| 301 |
+
<summary>"Search for" settings</summary>
|
| 302 |
+
|
| 303 |
+
Pretty self explanatory, enables or disables certain completion types.
|
| 304 |
+
|
| 305 |
+
Umi AI wildcards are included in the normal wildcard option here, although they use a different format, since their usage intention is similar.
|
| 306 |
+
|
| 307 |
+

|
| 308 |
+
</details>
|
| 309 |
+
<!-- Wiki links -->
|
| 310 |
+
<details>
|
| 311 |
+
<summary>"?" Wiki links</summary>
|
| 312 |
+
|
| 313 |
+
If this option is turned on, it will show a `?` link next to the tag. Clicking this will try to open the wiki page for that tag on danbooru or e621, depending on which tag file you use.
|
| 314 |
+
|
| 315 |
+
> ⚠️ Warning:
|
| 316 |
+
>
|
| 317 |
+
> Danbooru and e621 are external sites and include a lot of NSFW content, which might show in the list of examples for a tag on its wiki page. Because of this, the option is disabled by default.
|
| 318 |
+
|
| 319 |
+

|
| 320 |
+
</details>
|
| 321 |
+
<!-- Wiki links -->
|
| 322 |
+
<details>
|
| 323 |
+
<summary>Extra network live previews</summary>
|
| 324 |
+
|
| 325 |
+
This option enables a small preview window alongside the normal completion popup that will show the card preview also usd in the extra networks tab for that file.
|
| 326 |
+
|
| 327 |
+

|
| 328 |
+
</details>
|
| 329 |
+
<!-- Insertion -->
|
| 330 |
+
<details>
|
| 331 |
+
<summary>Completion settings</summary>
|
| 332 |
+
|
| 333 |
+
These settings specify how the text will be inserted.
|
| 334 |
+
|
| 335 |
+
Booru sites mostly use underscores in tags instead of spaces, but during preprocessing most models replaced this back with spaces since the CLIP encoder used in Stable diffusion was trained on natural language. Thus, by default tag autocomplete will as well.
|
| 336 |
+
|
| 337 |
+
Parentheses are used as control characters in the webui to give more attention / weight to a specific part of the prompt, so tags including parentheses are escaped (`\( \)`) by default to not influence that.
|
| 338 |
+
|
| 339 |
+
Depending on the last setting, tag autocomplete will append a comma and space after inserting a tag, which may help for rapid completion of multiple tags in a row.
|
| 340 |
+
|
| 341 |
+

|
| 342 |
+
</details>
|
| 343 |
+
<!-- Lora keywords -->
|
| 344 |
+
<details>
|
| 345 |
+
<summary>Lora / Lyco trigger word insertion</summary>
|
| 346 |
+
|
| 347 |
+
See [the detailed readme section](#lora--lyco-trigger-word-completion) for more info.
|
| 348 |
+
|
| 349 |
+
Selects the mode to use for Lora / Lyco trigger word insertion.
|
| 350 |
+
Needs the [model-keyword](https://github.com/mix1009/model-keyword/) extension to be installed, else it will do nothing.
|
| 351 |
+
|
| 352 |
+
- Never
|
| 353 |
+
- Will not complete trigger words, even if the model-keyword extension is installed
|
| 354 |
+
- Only user list
|
| 355 |
+
- Will only load the custom keywords specified in the lora-keyword-user.txt file and ignore the default list
|
| 356 |
+
- Always
|
| 357 |
+
- Will load and use both lists
|
| 358 |
+
|
| 359 |
+
Switching from "Never" to what you had before or back will not require a restart, but changing between the full and user only list will.
|
| 360 |
+
|
| 361 |
+

|
| 362 |
+
</details>
|
| 363 |
+
<!-- Wildcard path mode -->
|
| 364 |
+
<details>
|
| 365 |
+
<summary>Wildcard path completion</summary>
|
| 366 |
+
|
| 367 |
+
Some collections of wildcards are organized in nested subfolders.
|
| 368 |
+
They are listed with the full path to the file, like "hair/colors/light/..." or "clothing/male/casual/..." etc.
|
| 369 |
+
|
| 370 |
+
In these cases it is often hard to type the full path manually, but you still want to narrow the selection before further scrolling in the list.
|
| 371 |
+
For this, a partial completion of the path can be triggered with <kbd>Tab</kbd> (or the custom hotkey for `ChooseSelectedOrFirst`) if the results to choose from are all paths.
|
| 372 |
+
|
| 373 |
+
This setting determines the mode it should use for completion:
|
| 374 |
+
- To next folder level:
|
| 375 |
+
- Completes until the next `/` in the path, preferring your selection as the way forward
|
| 376 |
+
- If you want to directly choose an option, <kbd>Enter</kbd> / the `ChooseSelected` hotkey will skip it and fully complete.
|
| 377 |
+
- To first difference:
|
| 378 |
+
- Completes until the first difference in the results and waits for additional info
|
| 379 |
+
- E.g. if you have "/sub/folder_a/..." and "/sub/folder_b/...", completing after typing "su" will insert everything up to "/sub/folder_" and stop there until you type a or b to clarify.
|
| 380 |
+
- If you selected something with the arrow keys (regardless of pressing Enter or Tab), it will skip it and fully complete.
|
| 381 |
+
- Always fully:
|
| 382 |
+
- As the name suggests, disables the partial completion behavior and inserts the full path under all circumstances like with normal tags.
|
| 383 |
+
|
| 384 |
+

|
| 385 |
+
</details>
|
| 386 |
+
<!-- Alias -->
|
| 387 |
+
<details>
|
| 388 |
+
<summary>Alias settings</summary>
|
| 389 |
+
|
| 390 |
+
Tags often are referred to with multiple aliases. If `Search by alias` is turned on, those will be included in the search results, which might help if you are unsure of the correct tag. They will still get replaced by the actual tag they are linked to on insertion, since that is what the models were trained on.
|
| 391 |
+
|
| 392 |
+
`Only show alias` sets if you want to see only the alias or also the tag it maps to
|
| 393 |
+
(shown as `<alias> ➝ <actual>`)
|
| 394 |
+
|
| 395 |
+

|
| 396 |
+
</details>
|
| 397 |
+
<!-- Translations -->
|
| 398 |
+
<details>
|
| 399 |
+
<summary>Translation settings</summary>
|
| 400 |
+
|
| 401 |
+
Tag Autocomplete has support for tag translations specified in a separate file (`Translation filename`). You can search for tags using those translations, meaning that if you don't know the English tagword and have a translation file in your native language, you can use that instead.
|
| 402 |
+
|
| 403 |
+
It also has a legacy format option for some old files used in the community, as well as an experimental live translation preview for the whole prompt so you can easily find and edit tags afterwards.
|
| 404 |
+
|
| 405 |
+
For more details, see the [section on translations](#translations) below.
|
| 406 |
+
|
| 407 |
+

|
| 408 |
+
</details>
|
| 409 |
+
<!-- Extra file -->
|
| 410 |
+
<details>
|
| 411 |
+
<summary>Extra file settings</summary>
|
| 412 |
+
|
| 413 |
+
Specifies a set of extra tags that get appended either before or after the regular results, as specified here. Mostly useful for small custom tag sets such as the commonly used quality tags (masterpiece, best quality, etc.)
|
| 414 |
+
|
| 415 |
+
If you want completion for longer presets or even whole prompts, have a look at [Chants](#chants) instead.
|
| 416 |
+
|
| 417 |
+

|
| 418 |
+
</details>
|
| 419 |
+
<!-- Chants -->
|
| 420 |
+
<details>
|
| 421 |
+
<summary>Chant filename</summary>
|
| 422 |
+
|
| 423 |
+
Chants are longer presets or even whole prompts that can be selected & inserted at once, similar to the built in styles dropdown of the webui. They do offer some additional features though, and are faster to use.
|
| 424 |
+
|
| 425 |
+
For more info, see the section on [Chants](#chants) above.
|
| 426 |
+
|
| 427 |
+

|
| 428 |
+
</details>
|
| 429 |
+
<!-- Hotkeys -->
|
| 430 |
+
<details>
|
| 431 |
+
<summary>Hotkeys</summary>
|
| 432 |
+
|
| 433 |
+
You can specify the hotkeys for most keyboard navigation features here.
|
| 434 |
+
Should be one of the key names specified in https://www.w3.org/TR/uievents-key/#named-key-attribute-value.
|
| 435 |
+
|
| 436 |
+
Function explanation:
|
| 437 |
+
- Move Up / Down: Select the next tag
|
| 438 |
+
- Jump Up / Down: Move by five places at once
|
| 439 |
+
- Jump to Start / End: Jump to the top or bottom of the list
|
| 440 |
+
- ChooseSelected: Select the highlighted tag, or close popup if nothing was selected
|
| 441 |
+
- ChooseSelectedOrFirst: Same as above, but default to the first result if nothing was selected
|
| 442 |
+
- Close: Closes the popup
|
| 443 |
+
|
| 444 |
+

|
| 445 |
+
</details>
|
| 446 |
+
<!-- Colors -->
|
| 447 |
+
<details>
|
| 448 |
+
<summary>Colors</summary>
|
| 449 |
+
|
| 450 |
+
Here, you can change the default colors used for different tag categories. They were chosen to be similar to the category colors of their source site.
|
| 451 |
+
|
| 452 |
+
The format is standard JSON
|
| 453 |
+
- The object names correspond to the tag filename they should be used for.
|
| 454 |
+
- The numbers are specifying the tag type, which is dependent on the tag source. For more info, see [CSV tag data](#csv-tag-data).
|
| 455 |
+
- The first value in the square brackets is for dark, the second for light mode. HTML color names and hex codes should both work.
|
| 456 |
+
|
| 457 |
+
This can also be used to add new color sets for custom tag files.
|
| 458 |
+
|
| 459 |
+

|
| 460 |
+
</details>
|
| 461 |
+
<!-- Temp files refresh -->
|
| 462 |
+
<details>
|
| 463 |
+
<summary>Refresh TAC temp files</summary>
|
| 464 |
+
|
| 465 |
+
This is a "fake" setting, meaning it doesn't actually configure anything. Rather, it is a small hack to abuse the refresh button developers can add to webui options. Clicking on the refresh button next to this setting will force tag autocomplete to recreate and reload some temporary internal files, which normally only happens on restarting the UI.
|
| 466 |
+
|
| 467 |
+
Tag autocomplete depends on these files for various functionality, especially related to extra networks and wildcard completion. This setting can be used to rebuild the lists if you have, for example, added a few new LoRAs into the folder and don't want to restart the UI to get tag autocomplete to list them.
|
| 468 |
+
|
| 469 |
+
You can also add this to your quicksettings bar to have the refresh button available at all times.
|
| 470 |
+
|
| 471 |
+

|
| 472 |
+
</details>
|
| 473 |
+
<br/>
|
| 474 |
+
|
| 475 |
+
# Translations
|
| 476 |
+
An additional file can be added in the translation section, which will be used to translate both tags and aliases and also enables searching by translation.
|
| 477 |
+
This file needs to be a CSV in the format `<English tag/alias>,<Translation>`. Some older files use a three column format, which requires a compatibility setting to be activated.
|
| 478 |
+
You can find it under `Settings > Tag autocomplete > Translation filename > Translation file uses old 3-column translation format instead of the new 2-column one`.
|
| 479 |
+
With it on, the second column will be unused and skipped during parsing.
|
| 480 |
+
|
| 481 |
+
Example with Chinese translation:
|
| 482 |
+
|
| 483 |
+

|
| 484 |
+

|
| 485 |
+
|
| 486 |
+
## List of translations
|
| 487 |
+
- [🇨🇳 Chinese tags](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/discussions/23) by @HalfMAI, using machine translation and manual correction for the most common tags (uses legacy format)
|
| 488 |
+
- [🇨🇳 Chinese tags](https://github.com/sgmklp/tag-for-autocompletion-with-translation) by @sgmklp, smaller set of manual translations based on https://github.com/zcyzcy88/TagTable
|
| 489 |
+
|
| 490 |
+
> ### 🫵 I need your help!
|
| 491 |
+
> Translations are a community effort. If you have translated a tag file or want to create one, please open a Pull Request or Issue so your link can be added here.
|
| 492 |
+
> Please make sure the quality is alright though, machine translation gets a lot of stuff wrong even for the most common tags.
|
| 493 |
+
|
| 494 |
+
## Live preview
|
| 495 |
+
> ⚠️ Warning:
|
| 496 |
+
>
|
| 497 |
+
> This feature is still experimental, you might encounter some bugs when using it.
|
| 498 |
+
|
| 499 |
+
This will show a live preview of all detected tags in the prompt, both correctly separated by commas as well as in a longer sentence. It can detect up to three-word pairs in natural sentences, preferring perfect multi-word matches over single tags.
|
| 500 |
+
|
| 501 |
+
Above the detected tags will be their translation from the translation file, so if you aren't sure what the English tag means, you can easily find it there even after they have been inserted into the prompt (instead of just in the popup during completion).
|
| 502 |
+
|
| 503 |
+
The option defaults to off, but you can activate it by choosing a translation file and checking "Show live tag translation below prompt".
|
| 504 |
+
It will not affect the normal functionality if it is off.
|
| 505 |
+
|
| 506 |
+
Example with Chinese translation:
|
| 507 |
+
|
| 508 |
+

|
| 509 |
+
|
| 510 |
+
Clicking on a detected tag will also select it in the prompt for quick editing.
|
| 511 |
+
|
| 512 |
+

|
| 513 |
+
|
| 514 |
+
#### ⚠️ Known issues with live translation:
|
| 515 |
+
The translation updates when the user types or pastes text, but not if the action happens programmatically (e.g. applying a style or loading from PNG Info / Image Browser). This can be worked around by typing something manually after the programmatic edit.
|
| 516 |
+
|
| 517 |
+
# Extra file
|
| 518 |
+
An extra file can be used to add new / custom tags not included in the main set.
|
| 519 |
+
The format is identical to the normal tag format shown in [CSV tag data](#csv-tag-data) below, with one exception:
|
| 520 |
+
Since custom tags likely have no count, column three (or two if counting from zero) is instead used for the gray meta text displayed next to the tag.
|
| 521 |
+
If left empty, it will instead show "Custom tag".
|
| 522 |
+
|
| 523 |
+
An example with the included (very basic) extra-quality-tags.csv file:
|
| 524 |
+
|
| 525 |
+

|
| 526 |
+
|
| 527 |
+
Whether the custom tags should be added before or after the normal tags can be chosen in the settings.
|
| 528 |
+
|
| 529 |
+
# CSV tag data
|
| 530 |
+
The script expects a CSV file with tags saved in the following way:
|
| 531 |
+
```csv
|
| 532 |
+
<name>,<type>,<postCount>,"<aliases>"
|
| 533 |
+
```
|
| 534 |
+
Example:
|
| 535 |
+
```csv
|
| 536 |
+
1girl,0,4114588,"1girls,sole_female"
|
| 537 |
+
solo,0,3426446,"female_solo,solo_female"
|
| 538 |
+
highres,5,3008413,"high_res,high_resolution,hires"
|
| 539 |
+
long_hair,0,2898315,longhair
|
| 540 |
+
commentary_request,5,2610959,
|
| 541 |
+
```
|
| 542 |
+
Notably, it does not expect column names in the first row and both count and aliases are technically optional,
|
| 543 |
+
although count is always included in the default data. Multiple aliases need to be comma separated as well, but encased in string quotes to not break the CSV parsing.
|
| 544 |
+
|
| 545 |
+
The numbering system follows the [tag API docs](https://danbooru.donmai.us/wiki_pages/api%3Atags) of Danbooru:
|
| 546 |
+
| Value | Description |
|
| 547 |
+
|-------|-------------|
|
| 548 |
+
|0 | General |
|
| 549 |
+
|1 | Artist |
|
| 550 |
+
|3 | Copyright |
|
| 551 |
+
|4 | Character |
|
| 552 |
+
|5 | Meta |
|
| 553 |
+
|
| 554 |
+
or similarly for e621:
|
| 555 |
+
| Value | Description |
|
| 556 |
+
|-------|-------------|
|
| 557 |
+
|-1 | Invalid |
|
| 558 |
+
|0 | General |
|
| 559 |
+
|1 | Artist |
|
| 560 |
+
|3 | Copyright |
|
| 561 |
+
|4 | Character |
|
| 562 |
+
|5 | Species |
|
| 563 |
+
|6 | Invalid |
|
| 564 |
+
|7 | Meta |
|
| 565 |
+
|8 | Lore |
|
| 566 |
+
|
| 567 |
+
The tag type is used for coloring entries in the result list.
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
## ⚠️ Common Problems & Known Issues:
|
| 571 |
+
- Depending on your browser settings, sometimes an old version of the script can get cached. Try
|
| 572 |
+
<kbd>CTRL</kbd> + <kbd>F5</kbd>
|
| 573 |
+
to force-reload the site without cache if e.g. a new feature doesn't appear for you after an update.
|
| 574 |
+
- If the prompt popup has broken styling for you or doesn't appear at all (like [this](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/assets/34448969/7bbfdd54-fc23-4bfc-85af-24704b139b3a)), make sure to update your **openpose-editor** extension if you have it installed. It is known to cause issues with other extensions in older versions.
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
<!-- Variable declarations for shorter main text -->
|
| 578 |
+
[release-shield]: https://img.shields.io/github/v/release/DominikDoom/a1111-sd-webui-tagcomplete?logo=github&style=
|
| 579 |
+
[release-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/releases
|
| 580 |
+
|
| 581 |
+
[contributors-shield]: https://img.shields.io/github/contributors/DominikDoom/a1111-sd-webui-tagcomplete
|
| 582 |
+
[contributors-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/graphs/contributors
|
| 583 |
+
|
| 584 |
+
[forks-shield]: https://img.shields.io/github/forks/DominikDoom/a1111-sd-webui-tagcomplete
|
| 585 |
+
[forks-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/network/members
|
| 586 |
+
|
| 587 |
+
[stargazers-shield]: https://img.shields.io/github/stars/DominikDoom/a1111-sd-webui-tagcomplete
|
| 588 |
+
[stargazers-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/stargazers
|
| 589 |
+
|
| 590 |
+
[issues-shield]: https://img.shields.io/github/issues/DominikDoom/a1111-sd-webui-tagcomplete
|
| 591 |
+
[issues-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/issues/new/choose
|
| 592 |
+
|
| 593 |
+
<!-- Links for feature section -->
|
| 594 |
+
[image-browser-url]: https://github.com/AlUlkesh/stable-diffusion-webui-images-browser
|
| 595 |
+
[multidiffusion-url]: https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111
|
| 596 |
+
[tag-editor-url]: https://github.com/toshiaki1729/stable-diffusion-webui-dataset-tag-editor
|
| 597 |
+
[wd-tagger-url]: https://github.com/toriato/stable-diffusion-webui-wd14-tagger
|
| 598 |
+
[umi-url]: https://github.com/Klokinator/Umi-AI
|
a1111-sd-webui-tagcomplete-main/README_JA.md
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 2 |
+
|
| 3 |
+
<div align="center">
|
| 4 |
+
|
| 5 |
+
# SD WebUI Tag Autocomplete
|
| 6 |
+
## [English Document](./README.md), [中文文档](./README_ZH.md), 日本語
|
| 7 |
+
|
| 8 |
+
Booruスタイルタグを自動補完するためのAUTOMATIC1111 Stable Diffusion WebUI用拡張機能
|
| 9 |
+
|
| 10 |
+
[![Github Release][release-shield]][release-url]
|
| 11 |
+
[![stargazers][stargazers-shield]][stargazers-url]
|
| 12 |
+
[![contributors][contributors-shield]][contributors-url]
|
| 13 |
+
[![forks][forks-shield]][forks-url]
|
| 14 |
+
[![issues][issues-shield]][issues-url]
|
| 15 |
+
|
| 16 |
+
[変更内容][release-url] •
|
| 17 |
+
[確認されている問題](#%EF%B8%8F-よくある問題また現在確認されている問題) •
|
| 18 |
+
[バグを報告する][issues-url] •
|
| 19 |
+
[機能追加に関する要望][issues-url]
|
| 20 |
+
</div>
|
| 21 |
+
<br/>
|
| 22 |
+
|
| 23 |
+
# 📄 説明
|
| 24 |
+
|
| 25 |
+
Tag AutocompleteはStable Diffusion向けの人気のweb UIである、[AUTOMATIC1111 web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui)の拡張機能として利用できます。
|
| 26 |
+
|
| 27 |
+
主にアニメ系イラストを閲覧するための掲示板「Danbooru」などで利用されているタグの自動補完ヒントを表示するための拡張機能となります。
|
| 28 |
+
例えば[Waifu Diffusion](https://github.com/harubaru/waifu-diffusion)やNAIから派生した多くのモデルやマージなど、Stable Diffusionモデルの中にはこの情報を使って学習されたものもあるため、プロンプトに正確なタグを使用することで、多くのケースで構図を改善した思い通りの画像が生成できるようになります。
|
| 29 |
+
|
| 30 |
+
組み込みの利用可能な拡張機能リストを使ってインストールしたり、[下記](#-インストール)の説明に従って手動でファイルをcloneしたり、[Releases](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/releases)にあるパッケージ済みのバージョンを使うことができます。
|
| 31 |
+
|
| 32 |
+
<br/>
|
| 33 |
+
|
| 34 |
+
# ✨ Features
|
| 35 |
+
- 🚀 タイピング中に補完のためのヒントを表示 (通常時)
|
| 36 |
+
- ⌨️ キーボードナビゲーション
|
| 37 |
+
- 🌒 ダーク&ライトモードのサポート
|
| 38 |
+
- 🛠️ 多くの[設定](#%EF%B8%8F-設定)とカスタマイズ性を提供
|
| 39 |
+
- 🌍 [翻訳サポート](#翻訳)タグ、オプションでプロンプトのライブ プレビュー付き
|
| 40 |
+
- 私が知っている翻訳のリストは[こちら](#翻訳リスト)を参照してください。
|
| 41 |
+
|
| 42 |
+
タグの自動補完は組み込まれている補完内容をサポートしています:
|
| 43 |
+
- 🏷️ **Danbooru & e621 tags** (投稿数上位100k、2022年11月現在)
|
| 44 |
+
- ✳️ [**ワイルドカード**](#ワイルドカード)
|
| 45 |
+
- ➕ [**Extra networks**](#extra-networks-embeddings-hypernets-lora-) filenames, including
|
| 46 |
+
- Textual Inversion embeddings
|
| 47 |
+
- Hypernetworks
|
| 48 |
+
- LoRA
|
| 49 |
+
- LyCORIS / LoHA
|
| 50 |
+
- 🪄 [**Chants(詠唱)**](#chants詠唱) (長いプロンプトプリセット用のカスタムフォーマット)
|
| 51 |
+
- 🏷️ "[**Extra file**](#extra-file)", カスタマイズ可能なextra tagsセット
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
さらに、サードパーティの拡張機能にも対応しています:
|
| 55 |
+
<details>
|
| 56 |
+
<summary>クリックして開く</summary>
|
| 57 |
+
|
| 58 |
+
- [Image Browser][image-browser-url] - ファイル名とEXIFキーワードによる検索
|
| 59 |
+
- [Multidiffusion Upscaler][multidiffusion-url] - 地域別のプロンプト
|
| 60 |
+
- [Dataset Tag Editor][tag-editor-url] - キャプション, 結果の確認, タグの編集 & キャプションの編集
|
| 61 |
+
- [WD 1.4 Tagger][wd-tagger-url] - 追加と除外タグ
|
| 62 |
+
- [Umi AI][umi-url] - YAMLワイルドカードの補完
|
| 63 |
+
</details>
|
| 64 |
+
<br/>
|
| 65 |
+
|
| 66 |
+
## スクリーンショット & デモ動画
|
| 67 |
+
<details>
|
| 68 |
+
<summary>クリックすると開きます</summary>
|
| 69 |
+
基本的な使い方 (キーボード操作を用いたもの):
|
| 70 |
+
|
| 71 |
+
https://user-images.githubusercontent.com/34448969/200128020-10d9a8b2-cea6-4e3f-bcd2-8c40c8c73233.mp4
|
| 72 |
+
|
| 73 |
+
ワイルドカードをサポート:
|
| 74 |
+
|
| 75 |
+
https://user-images.githubusercontent.com/34448969/200128031-22dd7c33-71d1-464f-ae36-5f6c8fd49df0.mp4
|
| 76 |
+
|
| 77 |
+
タグカラーを含むDarkモードとLightモードに対応:
|
| 78 |
+
|
| 79 |
+

|
| 80 |
+

|
| 81 |
+
</details>
|
| 82 |
+
|
| 83 |
+
# 📦 インストール
|
| 84 |
+
## 内蔵されている拡張機能リストを用いた方法
|
| 85 |
+
1. Extensions タブを開く
|
| 86 |
+
2. Available タブを開く
|
| 87 |
+
3. "Load from:" をクリック
|
| 88 |
+
4. リストの中から "Booru tag autocompletion" を探す
|
| 89 |
+
- この拡張機能は最初から利用可能だったものなので、 "oldest first" を選択すると、リストの上位に表示されます。
|
| 90 |
+
5. 右側にある "Install" をクリック
|
| 91 |
+
|
| 92 |
+

|
| 93 |
+

|
| 94 |
+

|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
## 手動でcloneする方法
|
| 98 |
+
```bash
|
| 99 |
+
git clone "https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git" extensions/tag-autocomplete
|
| 100 |
+
```
|
| 101 |
+
(第2引数でフォルダ名を指定可能なので、好きな名前を指定しても良いでしょう)
|
| 102 |
+
|
| 103 |
+
# ❇️ 追加で有効化できる補完機能
|
| 104 |
+
## ワイルドカード
|
| 105 |
+
|
| 106 |
+
自動補完は、https://github.com/AUTOMATIC1111/stable-diffusion-webui-wildcards 、または他の類似のスクリプト/拡張機能で使用されるワイルドカードファイルでも利用可能です。補完は `__` (ダブルアンダースコア) と入力することで開始されます。最初にワイルドカードファイルのリストが表示され、1つを選択すると、そのファイル内の置換オプションが表示されます。
|
| 107 |
+
これにより、スクリプトによって置換されるカテゴリを挿入するか、または直接1つを選択して、ワイルドカードをカテゴリ化されたカスタムタグシステムのようなものとして使用することができます。
|
| 108 |
+
|
| 109 |
+

|
| 110 |
+

|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
ワイルドカードはすべての拡張機能フォルダと、古いバージョンをサポートするための `scripts/wildcards` フォルダで検索されます。これは複数の拡張機能からワイルドカードを組み合わせることができることを意味しています。ワイルドカードをグループ化した場合、ネストされたフォルダもサポートされます。
|
| 114 |
+
|
| 115 |
+
## Extra networks (Embeddings, Hypernets, LoRA, ...)
|
| 116 |
+
これら3つのタイプの補完は、`<`と入力することで行われます。デフォルトでは3つとも混在して表示されますが、以下の方法でさらにフィルタリングを行うことができます:
|
| 117 |
+
- `<e:` は、embeddingsのみを表示します。
|
| 118 |
+
- `<l:` は、LoRAとLyCORISのみを表示します。
|
| 119 |
+
- または `<lora:` と `<lyco:` で入力することも可能です
|
| 120 |
+
- `<h:` 、または `<hypernet:` はHypernetworksのみを表示します
|
| 121 |
+
|
| 122 |
+
### Embedding type filtering
|
| 123 |
+
Stable Diffusion 1.xまたは2.xモデル用にそれぞれトレーニングされたembeddingsは、他のタイプとの互換性がありません。有効なembeddingsを見つけやすくするため、若干の色の違いも含めて「v1 Embedding」と「v2 Embedding」で分類しています。また、`<v1/2`または`<e:v1/2`に続けて実際の検索のためのキーワードを入力すると、v1またはv2embeddingsのみを含むように検索を絞り込むことができます。
|
| 124 |
+
|
| 125 |
+
例:
|
| 126 |
+
|
| 127 |
+

|
| 128 |
+
|
| 129 |
+
## Chants(詠唱)
|
| 130 |
+
Chants(詠唱)は、より長いプロンプトプリセットです。この名前は、中国のユーザーによる初期のプロンプト集からヒントを得たもので、しばしば「呪文書」(原文は「Spellbook」「Codex」)などと呼ばれていました。
|
| 131 |
+
このような文書から得られるプロンプトのスニペットは、このような理由から呪文や詠唱と呼ばれるにふさわしいものでした。
|
| 132 |
+
|
| 133 |
+
EmbeddingsやLoraと同様に、この機能は `<`, `<c:`, `<chant:` コマンドを入力することで発動します。例えば、プロンプトボックスに `<c:HighQuality` と入力して選択すると、次のようなプロンプトテキストが挿入されます:
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
(masterpiece, best quality, high quality, highres, ultra-detailed),
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
Chants(詠唱)は、以下のフォーマットに従ってJSONファイルで追加することができます::
|
| 140 |
+
|
| 141 |
+
<details>
|
| 142 |
+
<summary>Chant format (click to expand)</summary>
|
| 143 |
+
|
| 144 |
+
```json
|
| 145 |
+
[
|
| 146 |
+
{
|
| 147 |
+
"name": "Basic-NegativePrompt",
|
| 148 |
+
"terms": "Negative,Low,Quality",
|
| 149 |
+
"content": "(worst quality, low quality, normal quality)",
|
| 150 |
+
"color": 3
|
| 151 |
+
},
|
| 152 |
+
{
|
| 153 |
+
"name": "Basic-HighQuality",
|
| 154 |
+
"terms": "Best,High,Quality",
|
| 155 |
+
"content": "(masterpiece, best quality, high quality, highres, ultra-detailed)",
|
| 156 |
+
"color": 1
|
| 157 |
+
},
|
| 158 |
+
{
|
| 159 |
+
"name": "Basic-Start",
|
| 160 |
+
"terms": "Basic, Start, Simple, Demo",
|
| 161 |
+
"content": "(masterpiece, best quality, high quality, highres), 1girl, extremely beautiful detailed face, ...",
|
| 162 |
+
"color": 5
|
| 163 |
+
}
|
| 164 |
+
]
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
</details>
|
| 168 |
+
<br/>
|
| 169 |
+
|
| 170 |
+
このファイルが拡張機能の `tags` フォルダ内にある場合、settings内の"Chant file"ドロップダウンから選択することができます。
|
| 171 |
+
|
| 172 |
+
chantオブジェクト���4つのフィールドを持ちます:
|
| 173 |
+
- `name` - 表示される名称
|
| 174 |
+
- `terms` - 検索キーワード
|
| 175 |
+
- `content` - 実際に挿入されるプロンプト
|
| 176 |
+
- `color` - 表示される色。通常のタグと同じカテゴリーカラーシステムを使用しています。
|
| 177 |
+
|
| 178 |
+
## Umi AI tags
|
| 179 |
+
https://github.com/Klokinator/Umi-AI は、Unprompted や Dynamic Wildcards に似た、機能豊富なワイルドカード拡張です。
|
| 180 |
+
例えば `<[preset][--female][sfw][species]>` はプリセットカテゴリーを選び、女性関連のタグを除外し、さらに次のカテゴリーで絞り込み、実行時にこれらすべての条件に一致するランダムなフィルインを1つ選び出します。補完は `<[`] とそれに続く新しい開く括弧、例えば `<[xyz][`] で始まり、 `>` で閉じるまで続きます。
|
| 181 |
+
|
| 182 |
+
タグの自動補完は、これらのオプションをスマートに提案していきます。つまり、カテゴリータグの追加を続けても、その前に来たものと一致する結果だけが表示されるのです。
|
| 183 |
+
また、タグの投稿数の代わりに、そのコンボから選択可能なフィルインタグの数を表示し、大規模になる初期内容に対して迅速な概要とフィルタリングを可能にします。
|
| 184 |
+
|
| 185 |
+
ほとんどの功績は[@ctwrs](https://github.com/ctwrs)によるものです。この方はUmiの開発者の一人として多くの貢献をしています。
|
| 186 |
+
|
| 187 |
+
# 🛠️ 設定
|
| 188 |
+
|
| 189 |
+
この拡張機能には多くの設定とカスタマイズ機能が組み込まれています。ほとんどのことははっきりしていますが、詳細な説明は以下のセクションをクリックしてください。
|
| 190 |
+
|
| 191 |
+
<!-- Filename -->
|
| 192 |
+
<details>
|
| 193 |
+
<summary>Tag filename</summary>
|
| 194 |
+
|
| 195 |
+
スクリプトが使用するメインのタグファイルとなります。デフォルトでは `danbooru.csv` と `e621.csv` が含まれており、ここにカスタムタグを追加することもできますが、大半のモデルはこの2つ以外(主にdanbooru)では学習していないため、あまり意味はありません。
|
| 196 |
+
|
| 197 |
+
拡張機能の他の機能(ワイルドカードやLoRA補完など)を使いたいが、通常のタグには興味がない場合は、`None`に設定することも可能です。
|
| 198 |
+
|
| 199 |
+

|
| 200 |
+
</details>
|
| 201 |
+
|
| 202 |
+
<!-- Active In -->
|
| 203 |
+
<details>
|
| 204 |
+
<summary>"Active in" の設定</summary>
|
| 205 |
+
|
| 206 |
+
タグのオートコンプリートがどこにアタッチされ、変更を受け付けるかを指定します。
|
| 207 |
+
ネガティブプロンプトはtxt2imgとimg2imgの設定に従うので、"親 "がアクティブな場合にのみアクティブとなります。
|
| 208 |
+
|
| 209 |
+

|
| 210 |
+
</details>
|
| 211 |
+
|
| 212 |
+
<!-- Blacklist -->
|
| 213 |
+
<details>
|
| 214 |
+
<summary>Black / Whitelist</summary>
|
| 215 |
+
|
| 216 |
+
このオプションは、タグのオートコンプリートをグローバルにオフにすることができますが、特定のモデルに対してのみ有効または無効にしたい場合もあります。
|
| 217 |
+
例えば、あなたのモデルのほとんどがアニメモデルである場合、boorタグでトレーニングされておらず、その恩恵を受けないフォトリアリスティックモデルをブラックリストに追加し、これらのモデルに切り替えた後に自動的に無効にすることができます。モデル名(拡張子を含む)とwebuiハッシュ(短い形式と長い形式の両方)の両方を使用できます。
|
| 218 |
+
|
| 219 |
+
`Blacklist`は指定したすべてのモデルを除外しますが、`Whitelist`はこれらのモデルに対してのみ有効で、デフォルトではオフのままです。例外として、空のホワイトリストは無視されます(空のブラックリストと同じです)。
|
| 220 |
+
|
| 221 |
+

|
| 222 |
+
</details>
|
| 223 |
+
<!-- Move Popup -->
|
| 224 |
+
<details>
|
| 225 |
+
<summary>カーソルで補完ポップアップを移動</summary>
|
| 226 |
+
|
| 227 |
+
このオプションは、IDEで行われるような、カーソルの位置に追従するフローティングポップアップを有効または無効にします。スクリプトはポップアップが右側でつぶれないように十分なスペースを確保しようとしますが、長いタグでは必ずしもうまくいきません。無効にした場合、ポップアップは左側に表示されます。
|
| 228 |
+
|
| 229 |
+

|
| 230 |
+
|
| 231 |
+

|
| 232 |
+

|
| 233 |
+
</details>
|
| 234 |
+
<!-- Results Count -->
|
| 235 |
+
<details>
|
| 236 |
+
<summary>結果の数</summary>
|
| 237 |
+
|
| 238 |
+
一度に表示する結果の量を設定できます。
|
| 239 |
+
`Show all results`が有効な場合、`Maximum results`で指定された数で切り捨てられるのではなく、スクロール可能なリストが表示されます。パフォーマンス上の理由から、この場合はすべてを一度に読み込むのではなく、ブロック単位で読み込みます。ブロックの大きさは`How many results to load at once`によって決まります。一番下に到達すると、次のブロックがロードされます(しかし、そんなことはめったには起こらないと思います)。
|
| 240 |
+
|
| 241 |
+
特筆すべきこととして、`Show all results` が使用される場合でも、`Maximum results` は影響を及ぼします。これは、スクロールが開始される前のポップアップの高さを制限するからです。
|
| 242 |
+
|
| 243 |
+

|
| 244 |
+
</details>
|
| 245 |
+
<!-- Delay time -->
|
| 246 |
+
<details>
|
| 247 |
+
<summary>補完の遅れについて</summary>
|
| 248 |
+
|
| 249 |
+
設定によっては、リアルタイムのタグ補完は計算量が多くなることがあります。
|
| 250 |
+
このオプションは debounce による遅延をミリ秒単位で設定します(1000ミリ秒 = 1秒)。このオプションは、入力が非常に速い場合に特に有効です。
|
| 251 |
+
|
| 252 |
+

|
| 253 |
+
</details>
|
| 254 |
+
<!-- Search for -->
|
| 255 |
+
<details>
|
| 256 |
+
<summary>"Search for" に関する設定</summary>
|
| 257 |
+
|
| 258 |
+
特定の補完タイプを有効または無効にします。
|
| 259 |
+
|
| 260 |
+
Umi AIワイルドカードは、使用目的が似ているため、異なるフォーマットを使用しますが、ここでは通常のワイルドカードオプションに含まれます。
|
| 261 |
+
|
| 262 |
+

|
| 263 |
+
</details>
|
| 264 |
+
<!-- Wiki links -->
|
| 265 |
+
<details>
|
| 266 |
+
<summary>"?" Wiki links</summary>
|
| 267 |
+
|
| 268 |
+
このオプションがオンになっている場合、タグの横に `?` リンクが表示されます。これをクリックすると、danbooruまたはe621のそのタグのWikiページを開こうとします。
|
| 269 |
+
|
| 270 |
+
> ⚠️ 警告:
|
| 271 |
+
>
|
| 272 |
+
> Danbooruとe621は外部サイトであり、多くのNSFWコンテンツを含んでいます。このため、このオプションはデフォルトで無効になっています。
|
| 273 |
+
|
| 274 |
+

|
| 275 |
+
</details>
|
| 276 |
+
<!-- Insertion -->
|
| 277 |
+
<details>
|
| 278 |
+
<summary>補完設定</summary>
|
| 279 |
+
|
| 280 |
+
これらの設定で、テキストの挿入方法を指定できます。
|
| 281 |
+
|
| 282 |
+
Booruのサイトでは、タグにスペースの代わりにアンダースコアを使用することがほとんどですが、Stable diffusionで使用されているCLIPエンコーダーは自然言語でトレーニングされているため、前処理中にほとんどのモデルがこのアンダースコアをスペースに置き換えました。したがって、デフォルトではタグのオートコンプリートも同じようになります。
|
| 283 |
+
|
| 284 |
+
括弧は、プロンプトの特定の部分をより注目/重視するために、Webuiの制御文字として使用されるため、デフォルトでは括弧を含むタグはエスケープされます (`\( \)`) 。
|
| 285 |
+
|
| 286 |
+
最後の設定によりますが、タグのオートコンプリートはタグを挿入した後にカンマとスペースを追加します。
|
| 287 |
+
|
| 288 |
+

|
| 289 |
+
</details>
|
| 290 |
+
<!-- Wildcard path mode -->
|
| 291 |
+
<details>
|
| 292 |
+
<summary>ワイルドカードのパス補完</summary>
|
| 293 |
+
|
| 294 |
+
ワイルドカードのいくつかのコレクションは、ネストしたサブフォルダに整理されています。
|
| 295 |
+
それらは、"hair/colors/light/... " や "clothing/male/casual/... " などのように、ファイルへのフルパスとともにリストアップされています。
|
| 296 |
+
|
| 297 |
+
このような場合、手動でフルパスを入力するのは難しいことが多いのですが、それでもリストをさらにスクロールする前に選択範囲を狭めたいものです。
|
| 298 |
+
この場合、選択する結果がすべてのパスであれば、<kbd>Tab</kbd>(または`ChooseSelectedOrFirst`のカスタムホットキー)でパスの部分補完をトリガーすることが可能です。
|
| 299 |
+
|
| 300 |
+
この設定は、補完に使用するモードを決定します:
|
| 301 |
+
- 次のフォルダレベルまで:
|
| 302 |
+
- パス内の次の/まで補完し、選択したものを進む方向として優先します
|
| 303 |
+
- オプションを直接選択したい場合は、<kbd>Enter</kbd> キーまたは `ChooseSelected` ホットキーを使用し���スキップし、完全に補完します。
|
| 304 |
+
- 最初の差分まで:
|
| 305 |
+
- 結果内の最初の違いまで補完し、追加の情報を待ちます
|
| 306 |
+
- 例:"/sub/folder_a/..." と "/sub/folder_b/..." がある場合、"su" と入力した後に補完すると、"/sub/folder_" まですべてを挿入し、a または b を入力して明確にするまでそこで停止します。
|
| 307 |
+
- 矢印キーで何かを選択した場合(EnterキーやTabキーを押すかどうかに関係なく)、それをスキップして完全に補完します。
|
| 308 |
+
- 常に全て:
|
| 309 |
+
- 名前が示すように、部分的な補完動作を無効にし、通常のタグのようにすべての状況下で完全なパスを挿入します。
|
| 310 |
+
|
| 311 |
+

|
| 312 |
+
</details>
|
| 313 |
+
<!-- Alias -->
|
| 314 |
+
<details>
|
| 315 |
+
<summary>Alias 設定</summary>
|
| 316 |
+
|
| 317 |
+
タグはしばしば複数の別名(Alias)で参照されます。`Search by alias`がオンになっている場合、それらは検索結果に含まれ、正しいタグがわからない場合に役立ちます。この場合でも、挿入時にリンクされている実際のタグに置き換えられます。
|
| 318 |
+
|
| 319 |
+
`Only show alias` セットは、エイリアスのみを表示したい場合、またはそのエイリアスがマップするタグも表示したい場合に使用します。
|
| 320 |
+
(`<alias> ➝ <actual>`として表示されます)
|
| 321 |
+
|
| 322 |
+

|
| 323 |
+
</details>
|
| 324 |
+
<!-- Translations -->
|
| 325 |
+
<details>
|
| 326 |
+
<summary>翻訳設定</summary>
|
| 327 |
+
|
| 328 |
+
Tag Autocompleteは、別のファイル(`Translation filename`)で指定されたタグの翻訳をサポートしています。つまり、英語のタグ名が分からなくても、自身の言語の翻訳ファイルがあれば、それを代わりに使うことができます。
|
| 329 |
+
|
| 330 |
+
また、コミュニティで使用されている古いファイルのためのレガシーフォーマットオプションや、プロンプト全体のライブ翻訳プレビューなど実験的な機能もあります。
|
| 331 |
+
|
| 332 |
+
詳細については、以下の [翻訳に関するセクション](#翻訳) を参照してください。
|
| 333 |
+
|
| 334 |
+

|
| 335 |
+
</details>
|
| 336 |
+
<!-- Extra file -->
|
| 337 |
+
<details>
|
| 338 |
+
<summary>Extra ファイル設定</summary>
|
| 339 |
+
|
| 340 |
+
ここで指定したように、通常の結果の前後に追加される追加タグのセットを指定します。一般的に使用される品質タグ (`masterpiece, best quality,` など) のような小さなカスタムタグセットに便利です。
|
| 341 |
+
|
| 342 |
+
長いプリセットやプロンプト全体を補完したい場合は、代わりに [Chants(詠唱)](#chants詠唱) を参照してください。
|
| 343 |
+
|
| 344 |
+

|
| 345 |
+
</details>
|
| 346 |
+
<!-- Chants -->
|
| 347 |
+
<details>
|
| 348 |
+
<summary>Chant ファイル名</summary>
|
| 349 |
+
|
| 350 |
+
Chantとは、長いプリセット、あるいはプロンプト全体を一度に選択して挿入できるもので、Webuiに内蔵されているスタイルのドロップダウンに似ています。Chantにはいくつかの追加機能があり、より速く使用することができます。
|
| 351 |
+
|
| 352 |
+
詳しくは上記の[Chants(詠唱)](#chants詠唱)のセクションを参照してください。
|
| 353 |
+
|
| 354 |
+

|
| 355 |
+
</details>
|
| 356 |
+
<!-- Hotkeys -->
|
| 357 |
+
<details>
|
| 358 |
+
<summary>Hotkeys</summary>
|
| 359 |
+
|
| 360 |
+
ほとんどのキーボードナビゲーション機能のホットキーをここで指定できます。
|
| 361 |
+
https://www.w3.org/TR/uievents-key/#named-key-attribute-value
|
| 362 |
+
|
| 363 |
+
機能の説明
|
| 364 |
+
- Move Up / Down:次のタグを選択
|
| 365 |
+
- Jump Up / Down:一度に5箇所移動する。
|
| 366 |
+
- Jump to Start / End: リストの先頭または末尾にジャンプ
|
| 367 |
+
- ChooseSelected ハイライトされたタグを選択するか、何も選択されていない場合はポップアップを閉じます。
|
| 368 |
+
- ChooseSelectedOrFirst:上記と同じですが、何も選択されていない場合、デフォルトで最初の結果が選択されます。
|
| 369 |
+
- Close ポップアップを閉じる
|
| 370 |
+
|
| 371 |
+

|
| 372 |
+
</details>
|
| 373 |
+
<!-- Colors -->
|
| 374 |
+
<details>
|
| 375 |
+
<summary>Colors</summary>
|
| 376 |
+
|
| 377 |
+
ここでは、異なるタグカテゴリーに使用されるデフォルトの色を変更することができます。これらは、ソースサイトのカテゴリの色に似ているように選択されています。
|
| 378 |
+
|
| 379 |
+
フォーマットは標準的なJSON
|
| 380 |
+
- オブジェクト名は、タグのファイル名に対応しています。
|
| 381 |
+
- 数字はタグの種類を表し、��グのソースに依存します。詳細については、[CSV tag data](#csv-tag-data)を参照してください。
|
| 382 |
+
- 角括弧内の最初の値はダークモード、2番目の値はライトモードです。HTMLの色名と16進数コードのどちらでも使えます。
|
| 383 |
+
|
| 384 |
+
これは、カスタムタグ・ファイルに新しいカラーセットを追加するためにも使用できます。
|
| 385 |
+
|
| 386 |
+

|
| 387 |
+
</details>
|
| 388 |
+
<!-- Temp files refresh -->
|
| 389 |
+
<details>
|
| 390 |
+
<summary>TACの一時作成ファイルのリフレッシュ</summary>
|
| 391 |
+
|
| 392 |
+
これは "フェイク"設定で、実際には何も設定しません。むしろ、開発者がwebuiのオプションに追加できる更新ボタンを悪用するための小さなハックです。この設定の隣にある更新ボタンをクリックすると、タグオートコンプリートにいくつかの一時的な内部ファイルを再作成・再読み込みさせます。
|
| 393 |
+
|
| 394 |
+
タグオートコンプリートは様々な機能、特に余分なネットワークとワイルドカード補完に関連するこれらのファイルに依存しています。この設定は、例えば新しいLoRAをいくつかフォルダに追加し、タグ・オートコンプリートにリストを表示させるためにUIを再起動したくない場合に、リストを再構築するために使用できます。
|
| 395 |
+
|
| 396 |
+
また、この設定をクイック設定バーに追加することで、いつでも更新ボタンを利用できるようになります。
|
| 397 |
+
|
| 398 |
+

|
| 399 |
+
</details>
|
| 400 |
+
<br/>
|
| 401 |
+
|
| 402 |
+
# 翻訳
|
| 403 |
+
タグとエイリアスの両方を翻訳するために使用することができ、また翻訳による検索を可能にするための、追加のファイルを翻訳セクションに追加することができます。
|
| 404 |
+
このファイルは、`<English tag/alias>,<Translation>`という形式のCSVである必要がありますが、3列のフォーマットを使用する古いファイルとの後方互換性のために、`oldFormat`をオンにすると、代わりに新しい2列の翻訳形式ではなく、古い3列の翻訳形式を使用するようになります。
|
| 405 |
+
その場合、2番目のカラムは使用されず、パース時にスキップされます。
|
| 406 |
+
|
| 407 |
+
中国語の翻訳例:
|
| 408 |
+
|
| 409 |
+

|
| 410 |
+

|
| 411 |
+
|
| 412 |
+
## 翻訳リスト
|
| 413 |
+
- [🇨🇳 Chinese tags](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/discussions/23) by @HalfMAI, 最も一般的なタグを機械翻訳と手作業で修正(レガシーフォーマットを使用)
|
| 414 |
+
- [🇨🇳 Chinese tags](https://github.com/sgmklp/tag-for-autocompletion-with-translation) by @sgmklp, [こちら](https://github.com/zcyzcy88/TagTable)をベースにして、より小さくした手動での翻訳セット。
|
| 415 |
+
|
| 416 |
+
> ### 🫵 あなたの助けが必要です!
|
| 417 |
+
> 翻訳はコミュニティの努力により支えられています。もしあなたがタグファイルを翻訳したことがある場合、または作成したい場合は、あなたの成果をここに追加できるように、Pull RequestまたはIssueを開いてください。
|
| 418 |
+
> 機械翻訳は、最も一般的なタグであっても、多くのことを間違えてしまいます。
|
| 419 |
+
|
| 420 |
+
## ライブ・プレビュー
|
| 421 |
+
> ⚠️ 警告:
|
| 422 |
+
>
|
| 423 |
+
> この機能はまだ実験的なもので、使用中にバグに遭遇するかもしれません。
|
| 424 |
+
|
| 425 |
+
この機能はプロンプト内のすべての検出されたタグのライブプレビューを表示します。検出されたタグは、カンマで正しく区切られたものと長い文章の中にあるものの両方が表示されます。自然な文章では3単語まで検出することができ、1つのタグよりも複数単語の完全な一致を優先します。
|
| 426 |
+
|
| 427 |
+
検出されたタグの上には翻訳ファイルからの訳文が表示されるので、英語のタグの意味がよく分からない場合でも、プロンプトにタグが挿入された後でも(完了時のポップアップではなく)簡単に見つけることができます。
|
| 428 |
+
|
| 429 |
+
このオプションはデフォルトではオフになっていますが、翻訳ファイルを選択し、「Show live tag translation below prompt」をチェックすることで有効にすることができます。
|
| 430 |
+
オフでも通常の機能には影響しません。
|
| 431 |
+
|
| 432 |
+
中国語翻訳時の例:
|
| 433 |
+
|
| 434 |
+

|
| 435 |
+
|
| 436 |
+
検出されたタグをクリックすると、そのタグがプロンプトで選択され、素��く編集できます。
|
| 437 |
+
|
| 438 |
+

|
| 439 |
+
|
| 440 |
+
#### ⚠️ ライブ翻訳に関する確認されている問題:
|
| 441 |
+
ユーザーがテキストを入力または貼り付けると翻訳が更新されますが、プログラムによる操作(スタイルの適用やPNG Info / Image Browserからの読み込みなど)では更新されません。これは、プログラムによる編集の後に手動で何かを入力することで回避できます。
|
| 442 |
+
|
| 443 |
+
# Extra file
|
| 444 |
+
エクストラファイルは、メインセットに含まれない新しいタグやカスタムタグを追加するために使用されます。
|
| 445 |
+
[CSV tag data](#csv-tag-data)にある通常のタグのフォーマットと同じですが、ひとつだけ例外があります:
|
| 446 |
+
カスタムタグにはカウントがないため、3列目(0から数える場合は2列目)はタグの横に表示される灰色のメタテキストに使用されます。
|
| 447 |
+
空欄のままだと、「カスタムタグ」と表示されます。
|
| 448 |
+
|
| 449 |
+
これは同梱されるextra-quality-tags.csvファイルを使用した例で、非常に基本的な内容となります:
|
| 450 |
+
|
| 451 |
+

|
| 452 |
+
|
| 453 |
+
カスタムタグを通常のタグの前に追加するか、後に追加するかは、設定で選択することができます。
|
| 454 |
+
|
| 455 |
+
# CSV tag data
|
| 456 |
+
このスクリプトは、以下の方法で保存されたタグ付きCSVファイルを想定しています:
|
| 457 |
+
```csv
|
| 458 |
+
<name>,<type>,<postCount>,"<aliases>"
|
| 459 |
+
```
|
| 460 |
+
Example:
|
| 461 |
+
```csv
|
| 462 |
+
1girl,0,4114588,"1girls,sole_female"
|
| 463 |
+
solo,0,3426446,"female_solo,solo_female"
|
| 464 |
+
highres,5,3008413,"high_res,high_resolution,hires"
|
| 465 |
+
long_hair,0,2898315,longhair
|
| 466 |
+
commentary_request,5,2610959,
|
| 467 |
+
```
|
| 468 |
+
注目すべきは、最初の行にカラム名を記載していないことと、count と aliases の両方が技術的にはオプションであることです、
|
| 469 |
+
ただし、countは常にデフォルトデータに含まれています。複数のエイリアスは同様にカンマで区切る必要がありますが、CSVの解析に支障がないようにダブルクオーテーションで囲みます。
|
| 470 |
+
|
| 471 |
+
番号の付け方についてはDanbooruの[tag API docs](https://danbooru.donmai.us/wiki_pages/api%3Atags)を参照してください:
|
| 472 |
+
| Value | Description |
|
| 473 |
+
|-------|-------------|
|
| 474 |
+
|0 | General |
|
| 475 |
+
|1 | Artist |
|
| 476 |
+
|3 | Copyright |
|
| 477 |
+
|4 | Character |
|
| 478 |
+
|5 | Meta |
|
| 479 |
+
|
| 480 |
+
また、e621についても同様です:
|
| 481 |
+
| Value | Description |
|
| 482 |
+
|-------|-------------|
|
| 483 |
+
|-1 | Invalid |
|
| 484 |
+
|0 | General |
|
| 485 |
+
|1 | Artist |
|
| 486 |
+
|3 | Copyright |
|
| 487 |
+
|4 | Character |
|
| 488 |
+
|5 | Species |
|
| 489 |
+
|6 | Invalid |
|
| 490 |
+
|7 | Meta |
|
| 491 |
+
|8 | Lore |
|
| 492 |
+
|
| 493 |
+
タグの種類は、結果の一覧のエントリーの色付けに使用されます。
|
| 494 |
+
|
| 495 |
+
## ⚠️ よくある問題、また現在確認されている問題:
|
| 496 |
+
- お使いのブラウザの設定によっては、古いバージョンのスクリプトがキャッシュされることがあります。例えば、アップデート後に新機能が表示されない場合は、キャッシュを使わずにサイトを強制的にリロードするために、
|
| 497 |
+
<kbd>CTRL</kbd> + <kbd>F5</kbd>
|
| 498 |
+
を試してください。
|
| 499 |
+
- プロンプトのポップアップが壊れたスタイルで表示されるか、全く表示されない場合([このような場合](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/assets/34448969/7bbfdd54-fc23-4bfc-85af-24704b139b3a))、openpose-editor 拡張機能がインストールされている場合は更新してください。古いバージョンでは他の拡張機能との間で問題が生じることが知られています。
|
| 500 |
+
|
| 501 |
+
<!-- Variable declarations for shorter main text -->
|
| 502 |
+
[release-shield]: https://img.shields.io/github/v/release/DominikDoom/a1111-sd-webui-tagcomplete?logo=github&style=
|
| 503 |
+
[release-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/releases
|
| 504 |
+
|
| 505 |
+
[contributors-shield]: https://img.shields.io/github/contributors/DominikDoom/a1111-sd-webui-tagcomplete
|
| 506 |
+
[contributors-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/graphs/contributors
|
| 507 |
+
|
| 508 |
+
[forks-shield]: https://img.shields.io/github/forks/DominikDoom/a1111-sd-webui-tagcomplete
|
| 509 |
+
[forks-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/network/members
|
| 510 |
+
|
| 511 |
+
[stargazers-shield]: https://img.shields.io/github/stars/DominikDoom/a1111-sd-webui-tagcomplete
|
| 512 |
+
[stargazers-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/stargazers
|
| 513 |
+
|
| 514 |
+
[issues-shield]: https://img.shields.io/github/issues/DominikDoom/a1111-sd-webui-tagcomplete
|
| 515 |
+
[issues-url]: https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/issues/new/choose
|
| 516 |
+
|
| 517 |
+
<!-- Links for feature section -->
|
| 518 |
+
[image-browser-url]: https://github.com/AlUlkesh/stable-diffusion-webui-images-browser
|
| 519 |
+
[multidiffusion-url]: https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111
|
| 520 |
+
[tag-editor-url]: https://github.com/toshiaki1729/stable-diffusion-webui-dataset-tag-editor
|
| 521 |
+
[wd-tagger-url]: https://github.com/toriato/stable-diffusion-webui-wd14-tagger
|
| 522 |
+
[umi-url]: https://github.com/Klokinator/Umi-AI
|
a1111-sd-webui-tagcomplete-main/README_ZH.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 2 |
+
|
| 3 |
+
# Booru tag autocompletion for A1111
|
| 4 |
+
|
| 5 |
+
[](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/releases)
|
| 6 |
+
## [English Document](./README.md), [日本語ドキュメント](./README_JA.md)
|
| 7 |
+
|
| 8 |
+
## 功能概述
|
| 9 |
+
|
| 10 |
+
本脚本为 [AUTOMATIC1111 web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui)的自定义脚本,能在输入Tag时提供booru风格(如Danbooru)的TAG自动补全。因为有一些模型是基于这种TAG风格训练的(例如[Waifu Diffusion](https://github.com/harubaru/waifu-diffusion)),因此使用这些Tag能获得较为精确的效果。
|
| 11 |
+
|
| 12 |
+
这个脚本的创建是为了减少因复制Tag在Web UI和 booru网站的反复切换。
|
| 13 |
+
你可以按照[以下方法](#installation)下载或拷贝文件,也可以使用[Releases](https://github.com/DominikDoom/a1111-sd-webui-tagcomplete/releases)中打包好的文件。
|
| 14 |
+
|
| 15 |
+
## 常见问题 & 已知缺陷:
|
| 16 |
+
- 很多中国用户都报告过此扩展名和其他扩展名的 JavaScript 文件被阻止的问题。
|
| 17 |
+
常见的罪魁祸首是 IDM / Internet Download Manager 浏览器插件,它似乎出于安全目的阻止了本地文件请求。
|
| 18 |
+
如果您安装了 IDM,请确保在使用 webui 时禁用以下插件:
|
| 19 |
+
|
| 20 |
+

|
| 21 |
+
|
| 22 |
+
- 当`replaceUnderscores`选项开启时, 脚本只会替换Tag的一部分如果Tag包含多个单词,比如将`atago (azur lane)`修改`atago`为`taihou`并使用自动补全时.会得到 `taihou (azur lane), lane)`的结果, 因为脚本没有把后面的部分认为成同一个Tag。
|
| 23 |
+
|
| 24 |
+
## 演示与截图
|
| 25 |
+
演示视频(使用了键盘导航):
|
| 26 |
+
|
| 27 |
+
https://user-images.githubusercontent.com/34448969/200128020-10d9a8b2-cea6-4e3f-bcd2-8c40c8c73233.mp4
|
| 28 |
+
|
| 29 |
+
Wildcard支持演示:
|
| 30 |
+
|
| 31 |
+
https://user-images.githubusercontent.com/34448969/200128031-22dd7c33-71d1-464f-ae36-5f6c8fd49df0.mp4
|
| 32 |
+
|
| 33 |
+
深浅色主题支持,包括Tag的颜色:
|
| 34 |
+
|
| 35 |
+

|
| 36 |
+

|
| 37 |
+
|
| 38 |
+
## 安装
|
| 39 |
+
### 作为一种扩展(推荐)
|
| 40 |
+
要么把它克隆到你的扩展文件夹里
|
| 41 |
+
```bash
|
| 42 |
+
git clone "https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git" extensions/tag-autocomplete
|
| 43 |
+
```
|
| 44 |
+
(第二个参数指定文件夹的名称,你可以选择任何你喜欢的东西)。
|
| 45 |
+
|
| 46 |
+
或者手动创建一个文件夹,将 `javascript`、`scripts`和`tags`文件夹放在其中。
|
| 47 |
+
|
| 48 |
+
### 在根目录下(过时的方法)
|
| 49 |
+
这种安装方法适用于添加扩展系统之前的旧版webui,在目前的版本上是行不通的。
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
在这两种配置中,标签文件夹包含`colors.json`和脚本用于自动完成的标签数据。
|
| 53 |
+
默认情况下,Tag数据包括`Danbooru.csv`和`e621.csv`。
|
| 54 |
+
|
| 55 |
+
在扫描过`/embeddings`和wildcards后,会将列表存放在`tags/temp`文件夹下。删除该文件夹不会有任何影响,下次启动时它会重新创建。
|
| 56 |
+
|
| 57 |
+
### 注意:
|
| 58 |
+
本脚本的允许需要**全部的三个文件夹**。
|
| 59 |
+
|
| 60 |
+
## [Wildcard](https://github.com/jtkelm2/stable-diffusion-webui-1/blob/master/scripts/wildcards.py) & Embedding 支持
|
| 61 |
+
自动补全同样适用于 [Wildcard](https://github.com/jtkelm2/stable-diffusion-webui-1/blob/master/scripts/wildcards.py)中所述的通配符文件(后面有演示视频)。这将使你能够插入Wildcard脚本需要的通配符,更进一步的,你还可以插入通配符文件内的某个具体Tag。
|
| 62 |
+
|
| 63 |
+
当输入`__`字符时,`/scripts/wildcards`文件夹下的通配符文件会列出到自动补全,当你选择某个具体通配符文件时,会列出其中的所有的具体Tag,但如果你仅需要选择某个通配符,请按下空格。
|
| 64 |
+
|
| 65 |
+
当输入`<`字符时,`embeddings`文件夹下的`.pt`和`.bin`文件会列出到自动完成。需要注意的是,一些颜文字也会包含`<`(比如`>_<`),所以它们也会出现在结果中。
|
| 66 |
+
|
| 67 |
+
现在这项功能默认是启用的,并会自动扫描`/embeddings`和`/scripts/wildcards`文件夹,不再需要使用`tags/wildcardNames.txt`文件了,早期版本的用户可以将它删除。
|
| 68 |
+
|
| 69 |
+
## 配置文件
|
| 70 |
+
该扩展有大量的配置和可定制性的内建:
|
| 71 |
+
|
| 72 |
+

|
| 73 |
+
|
| 74 |
+
| 设置 | 描述 |
|
| 75 |
+
|---------|-------------|
|
| 76 |
+
| tagFile | 指定要使用的标记文件。您可以提供您喜欢的自定义标签数据库,但由于该脚本是在考虑 Danbooru 标签的情况下开发的,因此它可能无法与其他配置一起正常工作。|
|
| 77 |
+
| activeIn | 允许有选择地(取消)激活 txt2img、img2img 和两者的否定��示的脚本。|
|
| 78 |
+
| maxResults | 最多显示多少个结果。对于默认标记集,结果按出现次数排序。对于嵌入和通配符,它将在可滚动列表中显示所有结果。 |
|
| 79 |
+
| showAllResults | 如果为真,将忽略 maxResults 并在可滚动列表中显示所有结果。 **警告:** 对于长列表,您的浏览器可能会滞后。 |
|
| 80 |
+
| resultStepLength | 允许以指定大小的小批次加载结果,以便在长列表中获得更好的性能,或者在showAllResults为真时。 |
|
| 81 |
+
| delayTime | 指定在触发自动完成之前要等待多少毫秒。有助于防止打字时过于频繁的更新。 |
|
| 82 |
+
| replaceUnderscores | 如果为 true,则在单击标签时将取消划线替换为空格。对于某些型号可能会更好。|
|
| 83 |
+
| escapeParentheses | 如果为 true,则转义包含 () 的标签,因此它们不会对 Web UI 的提示权重功能做出贡献。 |
|
| 84 |
+
| useWildcards | 用于切换通配符完成功能。 |
|
| 85 |
+
| useEmbeddings | 用于切换嵌入完成功能。 |
|
| 86 |
+
| alias | 标签别名的选项。更多信息在下面的部分。 |
|
| 87 |
+
| translation | 用于翻译标签的选项。更多信息在下面的部分。 |
|
| 88 |
+
| extras | 附加标签文件/翻译的选项。更多信息在下面的部分。|
|
| 89 |
+
|
| 90 |
+
### 标签颜色
|
| 91 |
+
标签类型的颜色可以通过改变标签自动完成设置中的JSON代码来指定。格式是标准的JSON,对象名称对应于它们应该使用的标签文件名(没有.csv)
|
| 92 |
+
|
| 93 |
+
方括号中的第一个值是指深色,第二个是指浅色模式。颜色名称和十六进制代码都应该有效。
|
| 94 |
+
```json
|
| 95 |
+
{
|
| 96 |
+
"danbooru": {
|
| 97 |
+
"-1": ["red", "maroon"],
|
| 98 |
+
"0": ["lightblue", "dodgerblue"],
|
| 99 |
+
"1": ["indianred", "firebrick"],
|
| 100 |
+
"3": ["violet", "darkorchid"],
|
| 101 |
+
"4": ["lightgreen", "darkgreen"],
|
| 102 |
+
"5": ["orange", "darkorange"]
|
| 103 |
+
},
|
| 104 |
+
"e621": {
|
| 105 |
+
"-1": ["red", "maroon"],
|
| 106 |
+
"0": ["lightblue", "dodgerblue"],
|
| 107 |
+
"1": ["gold", "goldenrod"],
|
| 108 |
+
"3": ["violet", "darkorchid"],
|
| 109 |
+
"4": ["lightgreen", "darkgreen"],
|
| 110 |
+
"5": ["tomato", "darksalmon"],
|
| 111 |
+
"6": ["red", "maroon"],
|
| 112 |
+
"7": ["whitesmoke", "black"],
|
| 113 |
+
"8": ["seagreen", "darkseagreen"]
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
```
|
| 117 |
+
这也可以用来为自定义标签文件添加新的颜色集。数字是指定标签的类型,这取决于标签来源。关于例子,见[CSV tag data](#csv-tag-data)。
|
| 118 |
+
|
| 119 |
+
### 别名,翻译&新增Tag
|
| 120 |
+
#### 别名
|
| 121 |
+
像Booru网站一样,标签可以有一个或多个别名,完成后重定向到实际值。这些将根据`config.json`中的设置进行搜索/显示。
|
| 122 |
+
- `searchByAlias` - 是否也要搜索别名,或只搜索实际的标签。
|
| 123 |
+
- `onlyShowAlias` - 只显示别名,不显示 `别名->实际`。仅用于显示,最后的文本仍然是实际的标签。
|
| 124 |
+
|
| 125 |
+
#### 翻译
|
| 126 |
+
可以在翻译部分添加一个额外的文件,它将被用来翻译标签和别名,同时也可以通过翻译进行搜索。
|
| 127 |
+
这个文件需要是CSV格式的`<英语标签/别名>,<翻译>`,但为了向后兼容使用三栏格式的旧的额外文件,你可以打开`oldFormat`来代替它。
|
| 128 |
+
|
| 129 |
+
完整和部分中文标签集的示例:
|
| 130 |
+
|
| 131 |
+

|
| 132 |
+

|
| 133 |
+
|
| 134 |
+
#### Extra文件
|
| 135 |
+
额外文件可以用来添加未包含在主集中的新的/自定义标签。
|
| 136 |
+
其格式与下面 [CSV tag data](#csv-tag-data) 中的正常标签格式相同,但有一个例外。
|
| 137 |
+
由于自定义标签没有帖子计数,第三列(如果从零开始计算,则为第二列)用于显示标签旁边的灰色元文本。
|
| 138 |
+
如果留空,它将显示 "Custom tag"。
|
| 139 |
+
|
| 140 |
+
以默认的(非常基本的)extra-quality-tags.csv为例:
|
| 141 |
+
|
| 142 |
+

|
| 143 |
+
|
| 144 |
+
你可以在设置中选择自定义标签是否应该加在常规标签之前或之后。
|
| 145 |
+
|
| 146 |
+
### CSV tag data
|
| 147 |
+
本脚本的Tag文件格式如下,你可以安装这个格式制作自己的Tag文件:
|
| 148 |
+
```csv
|
| 149 |
+
1girl,0,4114588,"1girls,sole_female"
|
| 150 |
+
solo,0,3426446,"female_solo,solo_female"
|
| 151 |
+
highres,5,3008413,"high_res,high_resolution,hires"
|
| 152 |
+
long_hair,0,2898315,longhair
|
| 153 |
+
commentary_request,5,2610959,
|
| 154 |
+
```
|
| 155 |
+
值得注意的是,不希望在第一行有列名,而且count和aliases在技术上都是可选的。
|
| 156 |
+
尽管count总是包含在默认数据中。多个别名也需要用逗号分隔,但要用字符串引号包裹,以免破坏CSV解析。
|
| 157 |
+
编号系统遵循 Danbooru 的 [tag API docs](https://danbooru.donmai.us/wiki_pages/api%3Atags):
|
| 158 |
+
| Value | Description |
|
| 159 |
+
|-------|-------------|
|
| 160 |
+
|0 | General |
|
| 161 |
+
|1 | Artist |
|
| 162 |
+
|3 | Copyright |
|
| 163 |
+
|4 | Character |
|
| 164 |
+
|5 | Meta |
|
| 165 |
+
|
| 166 |
+
类似的还有e621:
|
| 167 |
+
| Value | Description |
|
| 168 |
+
|-------|-------------|
|
| 169 |
+
|-1 | Invalid |
|
| 170 |
+
|0 | General |
|
| 171 |
+
|1 | Artist |
|
| 172 |
+
|3 | Copyright |
|
| 173 |
+
|4 | Character |
|
| 174 |
+
|5 | Species |
|
| 175 |
+
|6 | Invalid |
|
| 176 |
+
|7 | Meta |
|
| 177 |
+
|8 | Lore |
|
| 178 |
+
|
| 179 |
+
标记类型用于为结果列表中的条目着色.
|
a1111-sd-webui-tagcomplete-main/javascript/__globals.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Core components
|
| 2 |
+
var TAC_CFG = null;
|
| 3 |
+
var tagBasePath = "";
|
| 4 |
+
var modelKeywordPath = "";
|
| 5 |
+
var tacSelfTrigger = false;
|
| 6 |
+
|
| 7 |
+
// Tag completion data loaded from files
|
| 8 |
+
var allTags = [];
|
| 9 |
+
var translations = new Map();
|
| 10 |
+
var extras = [];
|
| 11 |
+
// Same for tag-likes
|
| 12 |
+
var wildcardFiles = [];
|
| 13 |
+
var wildcardExtFiles = [];
|
| 14 |
+
var yamlWildcards = [];
|
| 15 |
+
var umiWildcards = [];
|
| 16 |
+
var embeddings = [];
|
| 17 |
+
var hypernetworks = [];
|
| 18 |
+
var loras = [];
|
| 19 |
+
var lycos = [];
|
| 20 |
+
var modelKeywordDict = new Map();
|
| 21 |
+
var chants = [];
|
| 22 |
+
|
| 23 |
+
// Selected model info for black/whitelisting
|
| 24 |
+
var currentModelHash = "";
|
| 25 |
+
var currentModelName = "";
|
| 26 |
+
|
| 27 |
+
// Current results
|
| 28 |
+
var results = [];
|
| 29 |
+
var resultCount = 0;
|
| 30 |
+
|
| 31 |
+
// Relevant for parsing
|
| 32 |
+
var previousTags = [];
|
| 33 |
+
var tagword = "";
|
| 34 |
+
var originalTagword = "";
|
| 35 |
+
let hideBlocked = false;
|
| 36 |
+
|
| 37 |
+
// Tag selection for keyboard navigation
|
| 38 |
+
var selectedTag = null;
|
| 39 |
+
var oldSelectedTag = null;
|
| 40 |
+
var resultCountBeforeNormalTags = 0;
|
| 41 |
+
|
| 42 |
+
// Lora keyword undo/redo history
|
| 43 |
+
var textBeforeKeywordInsertion = "";
|
| 44 |
+
var textAfterKeywordInsertion = "";
|
| 45 |
+
var lastEditWasKeywordInsertion = false;
|
| 46 |
+
var keywordInsertionUndone = false;
|
| 47 |
+
|
| 48 |
+
// UMI
|
| 49 |
+
var umiPreviousTags = [];
|
| 50 |
+
|
| 51 |
+
/// Extendability system:
|
| 52 |
+
/// Provides "queues" for other files of the script (or really any js)
|
| 53 |
+
/// to add functions to be called at certain points in the script.
|
| 54 |
+
/// Similar to a callback system, but primitive.
|
| 55 |
+
|
| 56 |
+
// Queues
|
| 57 |
+
const QUEUE_AFTER_INSERT = [];
|
| 58 |
+
const QUEUE_AFTER_SETUP = [];
|
| 59 |
+
const QUEUE_FILE_LOAD = [];
|
| 60 |
+
const QUEUE_AFTER_CONFIG_CHANGE = [];
|
| 61 |
+
const QUEUE_SANITIZE = [];
|
| 62 |
+
|
| 63 |
+
// List of parsers to try
|
| 64 |
+
const PARSERS = [];
|
a1111-sd-webui-tagcomplete-main/javascript/_baseParser.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class FunctionNotOverriddenError extends Error {
|
| 2 |
+
constructor(message = "", ...args) {
|
| 3 |
+
super(message, ...args);
|
| 4 |
+
this.message = message + " is an abstract base function and must be overwritten.";
|
| 5 |
+
}
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
class BaseTagParser {
|
| 9 |
+
triggerCondition = null;
|
| 10 |
+
|
| 11 |
+
constructor (triggerCondition) {
|
| 12 |
+
if (new.target === BaseTagParser) {
|
| 13 |
+
throw new TypeError("Cannot construct abstract BaseCompletionParser directly");
|
| 14 |
+
}
|
| 15 |
+
this.triggerCondition = triggerCondition;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
parse() {
|
| 19 |
+
throw new FunctionNotOverriddenError("parse()");
|
| 20 |
+
}
|
| 21 |
+
}
|
a1111-sd-webui-tagcomplete-main/javascript/_caretPosition.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// From https://github.com/component/textarea-caret-position
|
| 2 |
+
|
| 3 |
+
// We'll copy the properties below into the mirror div.
|
| 4 |
+
// Note that some browsers, such as Firefox, do not concatenate properties
|
| 5 |
+
// into their shorthand (e.g. padding-top, padding-bottom etc. -> padding),
|
| 6 |
+
// so we have to list every single property explicitly.
|
| 7 |
+
var properties = [
|
| 8 |
+
'direction', // RTL support
|
| 9 |
+
'boxSizing',
|
| 10 |
+
'width', // on Chrome and IE, exclude the scrollbar, so the mirror div wraps exactly as the textarea does
|
| 11 |
+
'height',
|
| 12 |
+
'overflowX',
|
| 13 |
+
'overflowY', // copy the scrollbar for IE
|
| 14 |
+
|
| 15 |
+
'borderTopWidth',
|
| 16 |
+
'borderRightWidth',
|
| 17 |
+
'borderBottomWidth',
|
| 18 |
+
'borderLeftWidth',
|
| 19 |
+
'borderStyle',
|
| 20 |
+
|
| 21 |
+
'paddingTop',
|
| 22 |
+
'paddingRight',
|
| 23 |
+
'paddingBottom',
|
| 24 |
+
'paddingLeft',
|
| 25 |
+
|
| 26 |
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/font
|
| 27 |
+
'fontStyle',
|
| 28 |
+
'fontVariant',
|
| 29 |
+
'fontWeight',
|
| 30 |
+
'fontStretch',
|
| 31 |
+
'fontSize',
|
| 32 |
+
'fontSizeAdjust',
|
| 33 |
+
'lineHeight',
|
| 34 |
+
'fontFamily',
|
| 35 |
+
|
| 36 |
+
'textAlign',
|
| 37 |
+
'textTransform',
|
| 38 |
+
'textIndent',
|
| 39 |
+
'textDecoration', // might not make a difference, but better be safe
|
| 40 |
+
|
| 41 |
+
'letterSpacing',
|
| 42 |
+
'wordSpacing',
|
| 43 |
+
|
| 44 |
+
'tabSize',
|
| 45 |
+
'MozTabSize'
|
| 46 |
+
|
| 47 |
+
];
|
| 48 |
+
|
| 49 |
+
var isBrowser = (typeof window !== 'undefined');
|
| 50 |
+
var isFirefox = (isBrowser && window.mozInnerScreenX != null);
|
| 51 |
+
|
| 52 |
+
function getCaretCoordinates(element, position, options) {
|
| 53 |
+
if (!isBrowser) {
|
| 54 |
+
throw new Error('textarea-caret-position#getCaretCoordinates should only be called in a browser');
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
var debug = options && options.debug || false;
|
| 58 |
+
if (debug) {
|
| 59 |
+
var el = document.querySelector('#input-textarea-caret-position-mirror-div');
|
| 60 |
+
if (el) el.parentNode.removeChild(el);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// The mirror div will replicate the textarea's style
|
| 64 |
+
var div = document.createElement('div');
|
| 65 |
+
div.id = 'input-textarea-caret-position-mirror-div';
|
| 66 |
+
document.body.appendChild(div);
|
| 67 |
+
|
| 68 |
+
var style = div.style;
|
| 69 |
+
var computed = window.getComputedStyle ? window.getComputedStyle(element) : element.currentStyle; // currentStyle for IE < 9
|
| 70 |
+
var isInput = element.nodeName === 'INPUT';
|
| 71 |
+
|
| 72 |
+
// Default textarea styles
|
| 73 |
+
style.whiteSpace = 'pre-wrap';
|
| 74 |
+
if (!isInput)
|
| 75 |
+
style.wordWrap = 'break-word'; // only for textarea-s
|
| 76 |
+
|
| 77 |
+
// Position off-screen
|
| 78 |
+
style.position = 'absolute'; // required to return coordinates properly
|
| 79 |
+
if (!debug)
|
| 80 |
+
style.visibility = 'hidden'; // not 'display: none' because we want rendering
|
| 81 |
+
|
| 82 |
+
// Transfer the element's properties to the div
|
| 83 |
+
properties.forEach(function (prop) {
|
| 84 |
+
if (isInput && prop === 'lineHeight') {
|
| 85 |
+
// Special case for <input>s because text is rendered centered and line height may be != height
|
| 86 |
+
if (computed.boxSizing === "border-box") {
|
| 87 |
+
var height = parseInt(computed.height);
|
| 88 |
+
var outerHeight =
|
| 89 |
+
parseInt(computed.paddingTop) +
|
| 90 |
+
parseInt(computed.paddingBottom) +
|
| 91 |
+
parseInt(computed.borderTopWidth) +
|
| 92 |
+
parseInt(computed.borderBottomWidth);
|
| 93 |
+
var targetHeight = outerHeight + parseInt(computed.lineHeight);
|
| 94 |
+
if (height > targetHeight) {
|
| 95 |
+
style.lineHeight = height - outerHeight + "px";
|
| 96 |
+
} else if (height === targetHeight) {
|
| 97 |
+
style.lineHeight = computed.lineHeight;
|
| 98 |
+
} else {
|
| 99 |
+
style.lineHeight = 0;
|
| 100 |
+
}
|
| 101 |
+
} else {
|
| 102 |
+
style.lineHeight = computed.height;
|
| 103 |
+
}
|
| 104 |
+
} else {
|
| 105 |
+
style[prop] = computed[prop];
|
| 106 |
+
}
|
| 107 |
+
});
|
| 108 |
+
|
| 109 |
+
if (isFirefox) {
|
| 110 |
+
// Firefox lies about the overflow property for textareas: https://bugzilla.mozilla.org/show_bug.cgi?id=984275
|
| 111 |
+
if (element.scrollHeight > parseInt(computed.height))
|
| 112 |
+
style.overflowY = 'scroll';
|
| 113 |
+
} else {
|
| 114 |
+
style.overflow = 'hidden'; // for Chrome to not render a scrollbar; IE keeps overflowY = 'scroll'
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
div.textContent = element.value.substring(0, position);
|
| 118 |
+
// The second special handling for input type="text" vs textarea:
|
| 119 |
+
// spaces need to be replaced with non-breaking spaces - http://stackoverflow.com/a/13402035/1269037
|
| 120 |
+
if (isInput)
|
| 121 |
+
div.textContent = div.textContent.replace(/\s/g, '\u00a0');
|
| 122 |
+
|
| 123 |
+
var span = document.createElement('span');
|
| 124 |
+
// Wrapping must be replicated *exactly*, including when a long word gets
|
| 125 |
+
// onto the next line, with whitespace at the end of the line before (#7).
|
| 126 |
+
// The *only* reliable way to do that is to copy the *entire* rest of the
|
| 127 |
+
// textarea's content into the <span> created at the caret position.
|
| 128 |
+
// For inputs, just '.' would be enough, but no need to bother.
|
| 129 |
+
span.textContent = element.value.substring(position) || '.'; // || because a completely empty faux span doesn't render at all
|
| 130 |
+
div.appendChild(span);
|
| 131 |
+
|
| 132 |
+
var coordinates = {
|
| 133 |
+
top: span.offsetTop + parseInt(computed['borderTopWidth']),
|
| 134 |
+
left: span.offsetLeft + parseInt(computed['borderLeftWidth']),
|
| 135 |
+
height: parseInt(computed['lineHeight'])
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
if (debug) {
|
| 139 |
+
span.style.backgroundColor = '#aaa';
|
| 140 |
+
} else {
|
| 141 |
+
document.body.removeChild(div);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
return coordinates;
|
| 145 |
+
}
|
a1111-sd-webui-tagcomplete-main/javascript/_result.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Result data type for cleaner use of optional completion result properties
|
| 2 |
+
|
| 3 |
+
// Type enum
|
| 4 |
+
const ResultType = Object.freeze({
|
| 5 |
+
"tag": 1,
|
| 6 |
+
"extra": 2,
|
| 7 |
+
"embedding": 3,
|
| 8 |
+
"wildcardTag": 4,
|
| 9 |
+
"wildcardFile": 5,
|
| 10 |
+
"yamlWildcard": 6,
|
| 11 |
+
"umiWildcard": 7,
|
| 12 |
+
"hypernetwork": 8,
|
| 13 |
+
"lora": 9,
|
| 14 |
+
"lyco": 10,
|
| 15 |
+
"chant": 11
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
// Class to hold result data and annotations to make it clearer to use
|
| 19 |
+
class AutocompleteResult {
|
| 20 |
+
// Main properties
|
| 21 |
+
text = "";
|
| 22 |
+
type = ResultType.tag;
|
| 23 |
+
|
| 24 |
+
// Additional info, only used in some cases
|
| 25 |
+
category = null;
|
| 26 |
+
count = null;
|
| 27 |
+
aliases = null;
|
| 28 |
+
meta = null;
|
| 29 |
+
hash = null;
|
| 30 |
+
sortKey = null;
|
| 31 |
+
|
| 32 |
+
// Constructor
|
| 33 |
+
constructor(text, type) {
|
| 34 |
+
this.text = text;
|
| 35 |
+
this.type = type;
|
| 36 |
+
}
|
| 37 |
+
}
|
a1111-sd-webui-tagcomplete-main/javascript/_textAreas.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Utility functions to select text areas the script should work on,
|
| 2 |
+
// including third party options.
|
| 3 |
+
// Supported third party options so far:
|
| 4 |
+
// - Dataset Tag Editor
|
| 5 |
+
|
| 6 |
+
// Core text area selectors
|
| 7 |
+
const core = [
|
| 8 |
+
"#txt2img_prompt > label > textarea",
|
| 9 |
+
"#img2img_prompt > label > textarea",
|
| 10 |
+
"#txt2img_neg_prompt > label > textarea",
|
| 11 |
+
"#img2img_neg_prompt > label > textarea",
|
| 12 |
+
".prompt > label > textarea",
|
| 13 |
+
"#txt2img_edit_style_prompt > label > textarea",
|
| 14 |
+
"#txt2img_edit_style_neg_prompt > label > textarea",
|
| 15 |
+
"#img2img_edit_style_prompt > label > textarea",
|
| 16 |
+
"#img2img_edit_style_neg_prompt > label > textarea"
|
| 17 |
+
];
|
| 18 |
+
|
| 19 |
+
// Third party text area selectors
|
| 20 |
+
const thirdParty = {
|
| 21 |
+
"dataset-tag-editor": {
|
| 22 |
+
"base": "#tab_dataset_tag_editor_interface",
|
| 23 |
+
"hasIds": false,
|
| 24 |
+
"selectors": [
|
| 25 |
+
"Caption of Selected Image",
|
| 26 |
+
"Interrogate Result",
|
| 27 |
+
"Edit Caption",
|
| 28 |
+
"Edit Tags"
|
| 29 |
+
]
|
| 30 |
+
},
|
| 31 |
+
"image browser": {
|
| 32 |
+
"base": "#tab_image_browser",
|
| 33 |
+
"hasIds": false,
|
| 34 |
+
"selectors": [
|
| 35 |
+
"Filename keyword search",
|
| 36 |
+
"EXIF keyword search"
|
| 37 |
+
]
|
| 38 |
+
},
|
| 39 |
+
"tab_tagger": {
|
| 40 |
+
"base": "#tab_tagger",
|
| 41 |
+
"hasIds": false,
|
| 42 |
+
"selectors": [
|
| 43 |
+
"Additional tags (split by comma)",
|
| 44 |
+
"Exclude tags (split by comma)"
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
"tiled-diffusion-t2i": {
|
| 48 |
+
"base": "#txt2img_script_container",
|
| 49 |
+
"hasIds": true,
|
| 50 |
+
"onDemand": true,
|
| 51 |
+
"selectors": [
|
| 52 |
+
"[id^=MD-t2i][id$=prompt] textarea",
|
| 53 |
+
"[id^=MD-t2i][id$=prompt] input[type='text']"
|
| 54 |
+
]
|
| 55 |
+
},
|
| 56 |
+
"tiled-diffusion-i2i": {
|
| 57 |
+
"base": "#img2img_script_container",
|
| 58 |
+
"hasIds": true,
|
| 59 |
+
"onDemand": true,
|
| 60 |
+
"selectors": [
|
| 61 |
+
"[id^=MD-i2i][id$=prompt] textarea",
|
| 62 |
+
"[id^=MD-i2i][id$=prompt] input[type='text']"
|
| 63 |
+
]
|
| 64 |
+
},
|
| 65 |
+
"adetailer-t2i": {
|
| 66 |
+
"base": "#txt2img_script_container",
|
| 67 |
+
"hasIds": true,
|
| 68 |
+
"onDemand": true,
|
| 69 |
+
"selectors": [
|
| 70 |
+
"[id^=script_txt2img_adetailer_ad_prompt] textarea",
|
| 71 |
+
"[id^=script_txt2img_adetailer_ad_negative_prompt] textarea"
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
"adetailer-i2i": {
|
| 75 |
+
"base": "#img2img_script_container",
|
| 76 |
+
"hasIds": true,
|
| 77 |
+
"onDemand": true,
|
| 78 |
+
"selectors": [
|
| 79 |
+
"[id^=script_img2img_adetailer_ad_prompt] textarea",
|
| 80 |
+
"[id^=script_img2img_adetailer_ad_negative_prompt] textarea"
|
| 81 |
+
]
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function getTextAreas() {
|
| 86 |
+
// First get all core text areas
|
| 87 |
+
let textAreas = [...gradioApp().querySelectorAll(core.join(", "))];
|
| 88 |
+
|
| 89 |
+
for (const [key, entry] of Object.entries(thirdParty)) {
|
| 90 |
+
if (entry.hasIds) { // If the entry has proper ids, we can just select them
|
| 91 |
+
textAreas = textAreas.concat([...gradioApp().querySelectorAll(entry.selectors.join(", "))]);
|
| 92 |
+
} else { // Otherwise, we have to find the text areas by their adjacent labels
|
| 93 |
+
let base = gradioApp().querySelector(entry.base);
|
| 94 |
+
|
| 95 |
+
// Safety check
|
| 96 |
+
if (!base) continue;
|
| 97 |
+
|
| 98 |
+
let allTextAreas = [...base.querySelectorAll("textarea, input[type='text']")];
|
| 99 |
+
|
| 100 |
+
// Filter the text areas where the adjacent label matches one of the selectors
|
| 101 |
+
let matchingTextAreas = allTextAreas.filter(ta => [...ta.parentElement.childNodes].some(x => entry.selectors.includes(x.innerText)));
|
| 102 |
+
textAreas = textAreas.concat(matchingTextAreas);
|
| 103 |
+
}
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
return textAreas;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
function addOnDemandObservers(setupFunction) {
|
| 110 |
+
for (const [key, entry] of Object.entries(thirdParty)) {
|
| 111 |
+
if (!entry.onDemand) continue;
|
| 112 |
+
|
| 113 |
+
let base = gradioApp().querySelector(entry.base);
|
| 114 |
+
if (!base) continue;
|
| 115 |
+
|
| 116 |
+
let accordions = [...base?.querySelectorAll(".gradio-accordion")];
|
| 117 |
+
if (!accordions) continue;
|
| 118 |
+
|
| 119 |
+
accordions.forEach(acc => {
|
| 120 |
+
let accObserver = new MutationObserver((mutationList, observer) => {
|
| 121 |
+
for (const mutation of mutationList) {
|
| 122 |
+
if (mutation.type === "childList") {
|
| 123 |
+
let newChildren = mutation.addedNodes;
|
| 124 |
+
if (!newChildren) {
|
| 125 |
+
accObserver.disconnect();
|
| 126 |
+
continue;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
newChildren.forEach(child => {
|
| 130 |
+
if (child.classList.contains("gradio-accordion") || child.querySelector(".gradio-accordion")) {
|
| 131 |
+
let newAccordions = [...child.querySelectorAll(".gradio-accordion")];
|
| 132 |
+
newAccordions.forEach(nAcc => accObserver.observe(nAcc, { childList: true }));
|
| 133 |
+
}
|
| 134 |
+
});
|
| 135 |
+
|
| 136 |
+
if (entry.hasIds) { // If the entry has proper ids, we can just select them
|
| 137 |
+
[...gradioApp().querySelectorAll(entry.selectors.join(", "))].forEach(x => setupFunction(x));
|
| 138 |
+
} else { // Otherwise, we have to find the text areas by their adjacent labels
|
| 139 |
+
let base = gradioApp().querySelector(entry.base);
|
| 140 |
+
|
| 141 |
+
// Safety check
|
| 142 |
+
if (!base) continue;
|
| 143 |
+
|
| 144 |
+
let allTextAreas = [...base.querySelectorAll("textarea, input[type='text']")];
|
| 145 |
+
|
| 146 |
+
// Filter the text areas where the adjacent label matches one of the selectors
|
| 147 |
+
let matchingTextAreas = allTextAreas.filter(ta => [...ta.parentElement.childNodes].some(x => entry.selectors.includes(x.innerText)));
|
| 148 |
+
matchingTextAreas.forEach(x => setupFunction(x));
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
});
|
| 153 |
+
accObserver.observe(acc, { childList: true });
|
| 154 |
+
});
|
| 155 |
+
};
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
const thirdPartyIdSet = new Set();
|
| 159 |
+
// Get the identifier for the text area to differentiate between positive and negative
|
| 160 |
+
function getTextAreaIdentifier(textArea) {
|
| 161 |
+
let txt2img_p = gradioApp().querySelector('#txt2img_prompt > label > textarea');
|
| 162 |
+
let txt2img_n = gradioApp().querySelector('#txt2img_neg_prompt > label > textarea');
|
| 163 |
+
let img2img_p = gradioApp().querySelector('#img2img_prompt > label > textarea');
|
| 164 |
+
let img2img_n = gradioApp().querySelector('#img2img_neg_prompt > label > textarea');
|
| 165 |
+
|
| 166 |
+
let modifier = "";
|
| 167 |
+
switch (textArea) {
|
| 168 |
+
case txt2img_p:
|
| 169 |
+
modifier = ".txt2img.p";
|
| 170 |
+
break;
|
| 171 |
+
case txt2img_n:
|
| 172 |
+
modifier = ".txt2img.n";
|
| 173 |
+
break;
|
| 174 |
+
case img2img_p:
|
| 175 |
+
modifier = ".img2img.p";
|
| 176 |
+
break;
|
| 177 |
+
case img2img_n:
|
| 178 |
+
modifier = ".img2img.n";
|
| 179 |
+
break;
|
| 180 |
+
default:
|
| 181 |
+
// If the text area is not a core text area, it must be a third party text area
|
| 182 |
+
// Add it to the set of third party text areas and get its index as a unique identifier
|
| 183 |
+
if (!thirdPartyIdSet.has(textArea))
|
| 184 |
+
thirdPartyIdSet.add(textArea);
|
| 185 |
+
|
| 186 |
+
modifier = `.thirdParty.ta${[...thirdPartyIdSet].indexOf(textArea)}`;
|
| 187 |
+
break;
|
| 188 |
+
}
|
| 189 |
+
return modifier;
|
| 190 |
+
}
|
a1111-sd-webui-tagcomplete-main/javascript/_utils.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Utility functions for tag autocomplete
|
| 2 |
+
|
| 3 |
+
// Parse the CSV file into a 2D array. Doesn't use regex, so it is very lightweight.
|
| 4 |
+
// We are ignoring newlines in quote fields since we expect one-line entries and parsing would break for unclosed quotes otherwise
|
| 5 |
+
function parseCSV(str) {
|
| 6 |
+
const arr = [];
|
| 7 |
+
let quote = false; // 'true' means we're inside a quoted field
|
| 8 |
+
|
| 9 |
+
// Iterate over each character, keep track of current row and column (of the returned array)
|
| 10 |
+
for (let row = 0, col = 0, c = 0; c < str.length; c++) {
|
| 11 |
+
let cc = str[c], nc = str[c+1]; // Current character, next character
|
| 12 |
+
arr[row] = arr[row] || []; // Create a new row if necessary
|
| 13 |
+
arr[row][col] = arr[row][col] || ''; // Create a new column (start with empty string) if necessary
|
| 14 |
+
|
| 15 |
+
// If the current character is a quotation mark, and we're inside a
|
| 16 |
+
// quoted field, and the next character is also a quotation mark,
|
| 17 |
+
// add a quotation mark to the current column and skip the next character
|
| 18 |
+
if (cc == '"' && quote && nc == '"') { arr[row][col] += cc; ++c; continue; }
|
| 19 |
+
|
| 20 |
+
// If it's just one quotation mark, begin/end quoted field
|
| 21 |
+
if (cc == '"') { quote = !quote; continue; }
|
| 22 |
+
|
| 23 |
+
// If it's a comma and we're not in a quoted field, move on to the next column
|
| 24 |
+
if (cc == ',' && !quote) { ++col; continue; }
|
| 25 |
+
|
| 26 |
+
// If it's a newline (CRLF), skip the next character and move on to the next row and move to column 0 of that new row
|
| 27 |
+
if (cc == '\r' && nc == '\n') { ++row; col = 0; ++c; quote = false; continue; }
|
| 28 |
+
|
| 29 |
+
// If it's a newline (LF or CR) move on to the next row and move to column 0 of that new row
|
| 30 |
+
if (cc == '\n') { ++row; col = 0; quote = false; continue; }
|
| 31 |
+
if (cc == '\r') { ++row; col = 0; quote = false; continue; }
|
| 32 |
+
|
| 33 |
+
// Otherwise, append the current character to the current column
|
| 34 |
+
arr[row][col] += cc;
|
| 35 |
+
}
|
| 36 |
+
return arr;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
// Load file
|
| 40 |
+
async function readFile(filePath, json = false, cache = false) {
|
| 41 |
+
if (!cache)
|
| 42 |
+
filePath += `?${new Date().getTime()}`;
|
| 43 |
+
|
| 44 |
+
let response = await fetch(`file=${filePath}`);
|
| 45 |
+
|
| 46 |
+
if (response.status != 200) {
|
| 47 |
+
console.error(`Error loading file "${filePath}": ` + response.status, response.statusText);
|
| 48 |
+
return null;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
if (json)
|
| 52 |
+
return await response.json();
|
| 53 |
+
else
|
| 54 |
+
return await response.text();
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// Load CSV
|
| 58 |
+
async function loadCSV(path) {
|
| 59 |
+
let text = await readFile(path);
|
| 60 |
+
return parseCSV(text);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Fetch API
|
| 64 |
+
async function fetchAPI(url, json = true, cache = false) {
|
| 65 |
+
if (!cache) {
|
| 66 |
+
const appendChar = url.includes("?") ? "&" : "?";
|
| 67 |
+
url += `${appendChar}${new Date().getTime()}`
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
let response = await fetch(url);
|
| 71 |
+
|
| 72 |
+
if (response.status != 200) {
|
| 73 |
+
console.error(`Error fetching API endpoint "${url}": ` + response.status, response.statusText);
|
| 74 |
+
return null;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
if (json)
|
| 78 |
+
return await response.json();
|
| 79 |
+
else
|
| 80 |
+
return await response.text();
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
async function postAPI(url, body) {
|
| 84 |
+
let response = await fetch(url, { method: "POST", body: body });
|
| 85 |
+
|
| 86 |
+
if (response.status != 200) {
|
| 87 |
+
console.error(`Error posting to API endpoint "${url}": ` + response.status, response.statusText);
|
| 88 |
+
return null;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return await response.json();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// Extra network preview thumbnails
|
| 95 |
+
async function getExtraNetworkPreviewURL(filename, type) {
|
| 96 |
+
const previewJSON = await fetchAPI(`tacapi/v1/thumb-preview/${filename}?type=${type}`, true, true);
|
| 97 |
+
if (previewJSON?.url) {
|
| 98 |
+
const properURL = `sd_extra_networks/thumb?filename=${previewJSON.url}`;
|
| 99 |
+
if ((await fetch(properURL)).status == 200) {
|
| 100 |
+
return properURL;
|
| 101 |
+
} else {
|
| 102 |
+
// create blob url
|
| 103 |
+
const blob = await (await fetch(`tacapi/v1/thumb-preview-blob/${filename}?type=${type}`)).blob();
|
| 104 |
+
return URL.createObjectURL(blob);
|
| 105 |
+
}
|
| 106 |
+
} else {
|
| 107 |
+
return null;
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// Debounce function to prevent spamming the autocomplete function
|
| 112 |
+
var dbTimeOut;
|
| 113 |
+
const debounce = (func, wait = 300) => {
|
| 114 |
+
return function (...args) {
|
| 115 |
+
if (dbTimeOut) {
|
| 116 |
+
clearTimeout(dbTimeOut);
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
dbTimeOut = setTimeout(() => {
|
| 120 |
+
func.apply(this, args);
|
| 121 |
+
}, wait);
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
// Difference function to fix duplicates not being seen as changes in normal filter
|
| 126 |
+
function difference(a, b) {
|
| 127 |
+
if (a.length == 0) {
|
| 128 |
+
return b;
|
| 129 |
+
}
|
| 130 |
+
if (b.length == 0) {
|
| 131 |
+
return a;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
return [...b.reduce((acc, v) => acc.set(v, (acc.get(v) || 0) - 1),
|
| 135 |
+
a.reduce((acc, v) => acc.set(v, (acc.get(v) || 0) + 1), new Map())
|
| 136 |
+
)].reduce((acc, [v, count]) => acc.concat(Array(Math.abs(count)).fill(v)), []);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// Object flatten function adapted from https://stackoverflow.com/a/61602592
|
| 140 |
+
// $roots keeps previous parent properties as they will be added as a prefix for each prop.
|
| 141 |
+
// $sep is just a preference if you want to seperate nested paths other than dot.
|
| 142 |
+
function flatten(obj, roots = [], sep = ".") {
|
| 143 |
+
return Object.keys(obj).reduce(
|
| 144 |
+
(memo, prop) =>
|
| 145 |
+
Object.assign(
|
| 146 |
+
// create a new object
|
| 147 |
+
{},
|
| 148 |
+
// include previously returned object
|
| 149 |
+
memo,
|
| 150 |
+
Object.prototype.toString.call(obj[prop]) === "[object Object]"
|
| 151 |
+
? // keep working if value is an object
|
| 152 |
+
flatten(obj[prop], roots.concat([prop]), sep)
|
| 153 |
+
: // include current prop and value and prefix prop with the roots
|
| 154 |
+
{ [roots.concat([prop]).join(sep)]: obj[prop] }
|
| 155 |
+
),
|
| 156 |
+
{}
|
| 157 |
+
);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
// Sliding window function to get possible combination groups of an array
|
| 162 |
+
function toNgrams(inputArray, size) {
|
| 163 |
+
return Array.from(
|
| 164 |
+
{ length: inputArray.length - (size - 1) }, //get the appropriate length
|
| 165 |
+
(_, index) => inputArray.slice(index, index + size) //create the windows
|
| 166 |
+
);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function escapeRegExp(string) {
|
| 170 |
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
| 171 |
+
}
|
| 172 |
+
function escapeHTML(unsafeText) {
|
| 173 |
+
let div = document.createElement('div');
|
| 174 |
+
div.textContent = unsafeText;
|
| 175 |
+
return div.innerHTML;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
// For black/whitelisting
|
| 179 |
+
function updateModelName() {
|
| 180 |
+
let sdm = gradioApp().querySelector("#setting_sd_model_checkpoint");
|
| 181 |
+
let modelDropdown = sdm?.querySelector("input") || sdm?.querySelector("select");
|
| 182 |
+
if (modelDropdown) {
|
| 183 |
+
currentModelName = modelDropdown.value;
|
| 184 |
+
} else {
|
| 185 |
+
// Fallback for intermediate versions
|
| 186 |
+
modelDropdown = sdm?.querySelector("span.single-select");
|
| 187 |
+
currentModelName = modelDropdown?.textContent || "";
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
// From https://stackoverflow.com/a/61975440, how to detect JS value changes
|
| 192 |
+
function observeElement(element, property, callback, delay = 0) {
|
| 193 |
+
let elementPrototype = Object.getPrototypeOf(element);
|
| 194 |
+
if (elementPrototype.hasOwnProperty(property)) {
|
| 195 |
+
let descriptor = Object.getOwnPropertyDescriptor(elementPrototype, property);
|
| 196 |
+
Object.defineProperty(element, property, {
|
| 197 |
+
get: function() {
|
| 198 |
+
return descriptor.get.apply(this, arguments);
|
| 199 |
+
},
|
| 200 |
+
set: function () {
|
| 201 |
+
let oldValue = this[property];
|
| 202 |
+
descriptor.set.apply(this, arguments);
|
| 203 |
+
let newValue = this[property];
|
| 204 |
+
if (typeof callback == "function") {
|
| 205 |
+
setTimeout(callback.bind(this, oldValue, newValue), delay);
|
| 206 |
+
}
|
| 207 |
+
return newValue;
|
| 208 |
+
}
|
| 209 |
+
});
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
// Sort functions
|
| 214 |
+
function getSortFunction() {
|
| 215 |
+
let criterion = TAC_CFG.modelSortOrder || "Name";
|
| 216 |
+
|
| 217 |
+
const textSort = (a, b, reverse = false) => {
|
| 218 |
+
const textHolderA = a.type === ResultType.chant ? a.aliases : a.text;
|
| 219 |
+
const textHolderB = b.type === ResultType.chant ? b.aliases : b.text;
|
| 220 |
+
|
| 221 |
+
const aKey = a.sortKey || textHolderA;
|
| 222 |
+
const bKey = b.sortKey || textHolderB;
|
| 223 |
+
return reverse ? bKey.localeCompare(aKey) : aKey.localeCompare(bKey);
|
| 224 |
+
}
|
| 225 |
+
const numericSort = (a, b, reverse = false) => {
|
| 226 |
+
const noKey = reverse ? "-1" : Number.MAX_SAFE_INTEGER;
|
| 227 |
+
let aParsed = parseFloat(a.sortKey || noKey);
|
| 228 |
+
let bParsed = parseFloat(b.sortKey || noKey);
|
| 229 |
+
|
| 230 |
+
if (aParsed === bParsed) {
|
| 231 |
+
return textSort(a, b, false);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
return reverse ? bParsed - aParsed : aParsed - bParsed;
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
return (a, b) => {
|
| 238 |
+
switch (criterion) {
|
| 239 |
+
case "Date Modified (newest first)":
|
| 240 |
+
return numericSort(a, b, true);
|
| 241 |
+
case "Date Modified (oldest first)":
|
| 242 |
+
return numericSort(a, b, false);
|
| 243 |
+
default:
|
| 244 |
+
return textSort(a, b);
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// Queue calling function to process global queues
|
| 250 |
+
async function processQueue(queue, context, ...args) {
|
| 251 |
+
for (let i = 0; i < queue.length; i++) {
|
| 252 |
+
await queue[i].call(context, ...args);
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
// The same but with return values
|
| 256 |
+
async function processQueueReturn(queue, context, ...args)
|
| 257 |
+
{
|
| 258 |
+
let qeueueReturns = [];
|
| 259 |
+
for (let i = 0; i < queue.length; i++) {
|
| 260 |
+
let returnValue = await queue[i].call(context, ...args);
|
| 261 |
+
if (returnValue)
|
| 262 |
+
qeueueReturns.push(returnValue);
|
| 263 |
+
}
|
| 264 |
+
return qeueueReturns;
|
| 265 |
+
}
|
| 266 |
+
// Specific to tag completion parsers
|
| 267 |
+
async function processParsers(textArea, prompt) {
|
| 268 |
+
// Get all parsers that have a successful trigger condition
|
| 269 |
+
let matchingParsers = PARSERS.filter(parser => parser.triggerCondition());
|
| 270 |
+
// Guard condition
|
| 271 |
+
if (matchingParsers.length === 0) {
|
| 272 |
+
return null;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
let parseFunctions = matchingParsers.map(parser => parser.parse);
|
| 276 |
+
// Process them and return the results
|
| 277 |
+
return await processQueueReturn(parseFunctions, null, textArea, prompt);
|
| 278 |
+
}
|
a1111-sd-webui-tagcomplete-main/javascript/ext_chants.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const CHANT_REGEX = /<(?!e:|h:|l:)[^,> ]*>?/g;
|
| 2 |
+
const CHANT_TRIGGER = () => TAC_CFG.chantFile && TAC_CFG.chantFile !== "None" && tagword.match(CHANT_REGEX);
|
| 3 |
+
|
| 4 |
+
class ChantParser extends BaseTagParser {
|
| 5 |
+
parse() {
|
| 6 |
+
// Show Chant
|
| 7 |
+
let tempResults = [];
|
| 8 |
+
if (tagword !== "<" && tagword !== "<c:") {
|
| 9 |
+
let searchTerm = tagword.replace("<chant:", "").replace("<c:", "").replace("<", "");
|
| 10 |
+
let filterCondition = x => x.terms.toLowerCase().includes(searchTerm) || x.name.toLowerCase().includes(searchTerm);
|
| 11 |
+
tempResults = chants.filter(x => filterCondition(x)); // Filter by tagword
|
| 12 |
+
} else {
|
| 13 |
+
tempResults = chants;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
// Add final results
|
| 17 |
+
let finalResults = [];
|
| 18 |
+
tempResults.forEach(t => {
|
| 19 |
+
let result = new AutocompleteResult(t.content.trim(), ResultType.chant)
|
| 20 |
+
result.meta = "Chant";
|
| 21 |
+
result.aliases = t.name;
|
| 22 |
+
result.category = t.color;
|
| 23 |
+
finalResults.push(result);
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
+
return finalResults;
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
async function load() {
|
| 31 |
+
if (TAC_CFG.chantFile && TAC_CFG.chantFile !== "None") {
|
| 32 |
+
try {
|
| 33 |
+
chants = await readFile(`${tagBasePath}/${TAC_CFG.chantFile}?`, true);
|
| 34 |
+
} catch (e) {
|
| 35 |
+
console.error("Error loading chants.json: " + e);
|
| 36 |
+
}
|
| 37 |
+
} else {
|
| 38 |
+
chants = [];
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function sanitize(tagType, text) {
|
| 43 |
+
if (tagType === ResultType.chant) {
|
| 44 |
+
return text.replace(/^.*?: /g, "");
|
| 45 |
+
}
|
| 46 |
+
return null;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
PARSERS.push(new ChantParser(CHANT_TRIGGER));
|
| 50 |
+
|
| 51 |
+
// Add our utility functions to their respective queues
|
| 52 |
+
QUEUE_FILE_LOAD.push(load);
|
| 53 |
+
QUEUE_SANITIZE.push(sanitize);
|
| 54 |
+
QUEUE_AFTER_CONFIG_CHANGE.push(load);
|
a1111-sd-webui-tagcomplete-main/javascript/ext_embeddings.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const EMB_REGEX = /<(?!l:|h:|c:)[^,> ]*>?/g;
|
| 2 |
+
const EMB_TRIGGER = () => TAC_CFG.useEmbeddings && (tagword.match(EMB_REGEX) || TAC_CFG.includeEmbeddingsInNormalResults);
|
| 3 |
+
|
| 4 |
+
class EmbeddingParser extends BaseTagParser {
|
| 5 |
+
parse() {
|
| 6 |
+
// Show embeddings
|
| 7 |
+
let tempResults = [];
|
| 8 |
+
if (tagword !== "<" && tagword !== "<e:") {
|
| 9 |
+
let searchTerm = tagword.replace("<e:", "").replace("<", "");
|
| 10 |
+
let versionString;
|
| 11 |
+
if (searchTerm.startsWith("v1") || searchTerm.startsWith("v2")) {
|
| 12 |
+
versionString = searchTerm.slice(0, 2);
|
| 13 |
+
searchTerm = searchTerm.slice(2);
|
| 14 |
+
} else if (searchTerm.startsWith("vxl")) {
|
| 15 |
+
versionString = searchTerm.slice(0, 3);
|
| 16 |
+
searchTerm = searchTerm.slice(3);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
let filterCondition = x => x[0].toLowerCase().includes(searchTerm) || x[0].toLowerCase().replaceAll(" ", "_").includes(searchTerm);
|
| 20 |
+
|
| 21 |
+
if (versionString)
|
| 22 |
+
tempResults = embeddings.filter(x => filterCondition(x) && x[2] && x[2].toLowerCase() === versionString.toLowerCase()); // Filter by tagword
|
| 23 |
+
else
|
| 24 |
+
tempResults = embeddings.filter(x => filterCondition(x)); // Filter by tagword
|
| 25 |
+
} else {
|
| 26 |
+
tempResults = embeddings;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// Add final results
|
| 30 |
+
let finalResults = [];
|
| 31 |
+
tempResults.forEach(t => {
|
| 32 |
+
let result = new AutocompleteResult(t[0].trim(), ResultType.embedding)
|
| 33 |
+
result.sortKey = t[1];
|
| 34 |
+
result.meta = t[2] + " Embedding";
|
| 35 |
+
finalResults.push(result);
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
return finalResults;
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
async function load() {
|
| 43 |
+
if (embeddings.length === 0) {
|
| 44 |
+
try {
|
| 45 |
+
embeddings = (await loadCSV(`${tagBasePath}/temp/emb.txt`))
|
| 46 |
+
.filter(x => x[0]?.trim().length > 0) // Remove empty lines
|
| 47 |
+
.map(x => [x[0].trim(), x[1], x[2]]); // Return name, sortKey, hash tuples
|
| 48 |
+
} catch (e) {
|
| 49 |
+
console.error("Error loading embeddings.txt: " + e);
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function sanitize(tagType, text) {
|
| 55 |
+
if (tagType === ResultType.embedding) {
|
| 56 |
+
return text.replace(/^.*?: /g, "");
|
| 57 |
+
}
|
| 58 |
+
return null;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
PARSERS.push(new EmbeddingParser(EMB_TRIGGER));
|
| 62 |
+
|
| 63 |
+
// Add our utility functions to their respective queues
|
| 64 |
+
QUEUE_FILE_LOAD.push(load);
|
| 65 |
+
QUEUE_SANITIZE.push(sanitize);
|
a1111-sd-webui-tagcomplete-main/javascript/ext_hypernets.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const HYP_REGEX = /<(?!e:|l:|c:)[^,> ]*>?/g;
|
| 2 |
+
const HYP_TRIGGER = () => TAC_CFG.useHypernetworks && tagword.match(HYP_REGEX);
|
| 3 |
+
|
| 4 |
+
class HypernetParser extends BaseTagParser {
|
| 5 |
+
parse() {
|
| 6 |
+
// Show hypernetworks
|
| 7 |
+
let tempResults = [];
|
| 8 |
+
if (tagword !== "<" && tagword !== "<h:" && tagword !== "<hypernet:") {
|
| 9 |
+
let searchTerm = tagword.replace("<hypernet:", "").replace("<h:", "").replace("<", "");
|
| 10 |
+
let filterCondition = x => x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm);
|
| 11 |
+
tempResults = hypernetworks.filter(x => filterCondition(x[0])); // Filter by tagword
|
| 12 |
+
} else {
|
| 13 |
+
tempResults = hypernetworks;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
// Add final results
|
| 17 |
+
let finalResults = [];
|
| 18 |
+
tempResults.forEach(t => {
|
| 19 |
+
let result = new AutocompleteResult(t[0].trim(), ResultType.hypernetwork)
|
| 20 |
+
result.meta = "Hypernetwork";
|
| 21 |
+
result.sortKey = t[1];
|
| 22 |
+
finalResults.push(result);
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
return finalResults;
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
async function load() {
|
| 30 |
+
if (hypernetworks.length === 0) {
|
| 31 |
+
try {
|
| 32 |
+
hypernetworks = (await loadCSV(`${tagBasePath}/temp/hyp.txt`))
|
| 33 |
+
.filter(x => x[0]?.trim().length > 0) //Remove empty lines
|
| 34 |
+
.map(x => [x[0]?.trim(), x[1]]); // Remove carriage returns and padding if it exists
|
| 35 |
+
} catch (e) {
|
| 36 |
+
console.error("Error loading hypernetworks.txt: " + e);
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
function sanitize(tagType, text) {
|
| 42 |
+
if (tagType === ResultType.hypernetwork) {
|
| 43 |
+
return `<hypernet:${text}:${TAC_CFG.extraNetworksDefaultMultiplier}>`;
|
| 44 |
+
}
|
| 45 |
+
return null;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
PARSERS.push(new HypernetParser(HYP_TRIGGER));
|
| 49 |
+
|
| 50 |
+
// Add our utility functions to their respective queues
|
| 51 |
+
QUEUE_FILE_LOAD.push(load);
|
| 52 |
+
QUEUE_SANITIZE.push(sanitize);
|
a1111-sd-webui-tagcomplete-main/javascript/ext_loras.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const LORA_REGEX = /<(?!e:|h:|c:)[^,> ]*>?/g;
|
| 2 |
+
const LORA_TRIGGER = () => TAC_CFG.useLoras && tagword.match(LORA_REGEX);
|
| 3 |
+
|
| 4 |
+
class LoraParser extends BaseTagParser {
|
| 5 |
+
parse() {
|
| 6 |
+
// Show lora
|
| 7 |
+
let tempResults = [];
|
| 8 |
+
if (tagword !== "<" && tagword !== "<l:" && tagword !== "<lora:") {
|
| 9 |
+
let searchTerm = tagword.replace("<lora:", "").replace("<l:", "").replace("<", "");
|
| 10 |
+
let filterCondition = x => x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm);
|
| 11 |
+
tempResults = loras.filter(x => filterCondition(x[0])); // Filter by tagword
|
| 12 |
+
} else {
|
| 13 |
+
tempResults = loras;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
// Add final results
|
| 17 |
+
let finalResults = [];
|
| 18 |
+
tempResults.forEach(t => {
|
| 19 |
+
const text = t[0].trim();
|
| 20 |
+
let lastDot = text.lastIndexOf(".") > -1 ? text.lastIndexOf(".") : text.length;
|
| 21 |
+
let lastSlash = text.lastIndexOf("/") > -1 ? text.lastIndexOf("/") : -1;
|
| 22 |
+
let name = text.substring(lastSlash + 1, lastDot);
|
| 23 |
+
|
| 24 |
+
let result = new AutocompleteResult(name, ResultType.lora)
|
| 25 |
+
result.meta = "Lora";
|
| 26 |
+
result.sortKey = t[1];
|
| 27 |
+
result.hash = t[2];
|
| 28 |
+
finalResults.push(result);
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
return finalResults;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
async function load() {
|
| 36 |
+
if (loras.length === 0) {
|
| 37 |
+
try {
|
| 38 |
+
loras = (await loadCSV(`${tagBasePath}/temp/lora.txt`))
|
| 39 |
+
.filter(x => x[0]?.trim().length > 0) // Remove empty lines
|
| 40 |
+
.map(x => [x[0]?.trim(), x[1], x[2]]); // Trim filenames and return the name, sortKey, hash pairs
|
| 41 |
+
} catch (e) {
|
| 42 |
+
console.error("Error loading lora.txt: " + e);
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
async function sanitize(tagType, text) {
|
| 48 |
+
if (tagType === ResultType.lora) {
|
| 49 |
+
let multiplier = TAC_CFG.extraNetworksDefaultMultiplier;
|
| 50 |
+
let info = await fetchAPI(`tacapi/v1/lora-info/${text}`)
|
| 51 |
+
if (info && info["preferred weight"]) {
|
| 52 |
+
multiplier = info["preferred weight"];
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return `<lora:${text}:${multiplier}>`;
|
| 56 |
+
}
|
| 57 |
+
return null;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
PARSERS.push(new LoraParser(LORA_TRIGGER));
|
| 61 |
+
|
| 62 |
+
// Add our utility functions to their respective queues
|
| 63 |
+
QUEUE_FILE_LOAD.push(load);
|
| 64 |
+
QUEUE_SANITIZE.push(sanitize);
|
a1111-sd-webui-tagcomplete-main/javascript/ext_lycos.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const LYCO_REGEX = /<(?!e:|h:|c:)[^,> ]*>?/g;
|
| 2 |
+
const LYCO_TRIGGER = () => TAC_CFG.useLycos && tagword.match(LYCO_REGEX);
|
| 3 |
+
|
| 4 |
+
class LycoParser extends BaseTagParser {
|
| 5 |
+
parse() {
|
| 6 |
+
// Show lyco
|
| 7 |
+
let tempResults = [];
|
| 8 |
+
if (tagword !== "<" && tagword !== "<l:" && tagword !== "<lyco:") {
|
| 9 |
+
let searchTerm = tagword.replace("<lyco:", "").replace("<l:", "").replace("<", "");
|
| 10 |
+
let filterCondition = x => x.toLowerCase().includes(searchTerm) || x.toLowerCase().replaceAll(" ", "_").includes(searchTerm);
|
| 11 |
+
tempResults = lycos.filter(x => filterCondition(x[0])); // Filter by tagword
|
| 12 |
+
} else {
|
| 13 |
+
tempResults = lycos;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
// Add final results
|
| 17 |
+
let finalResults = [];
|
| 18 |
+
tempResults.forEach(t => {
|
| 19 |
+
const text = t[0].trim();
|
| 20 |
+
let lastDot = text.lastIndexOf(".") > -1 ? text.lastIndexOf(".") : text.length;
|
| 21 |
+
let lastSlash = text.lastIndexOf("/") > -1 ? text.lastIndexOf("/") : -1;
|
| 22 |
+
let name = text.substring(lastSlash + 1, lastDot);
|
| 23 |
+
|
| 24 |
+
let result = new AutocompleteResult(name, ResultType.lyco)
|
| 25 |
+
result.meta = "Lyco";
|
| 26 |
+
result.sortKey = t[1];
|
| 27 |
+
result.hash = t[2];
|
| 28 |
+
finalResults.push(result);
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
return finalResults;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
async function load() {
|
| 36 |
+
if (lycos.length === 0) {
|
| 37 |
+
try {
|
| 38 |
+
lycos = (await loadCSV(`${tagBasePath}/temp/lyco.txt`))
|
| 39 |
+
.filter(x => x[0]?.trim().length > 0) // Remove empty lines
|
| 40 |
+
.map(x => [x[0]?.trim(), x[1], x[2]]); // Trim filenames and return the name, sortKey, hash pairs
|
| 41 |
+
} catch (e) {
|
| 42 |
+
console.error("Error loading lyco.txt: " + e);
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
async function sanitize(tagType, text) {
|
| 48 |
+
if (tagType === ResultType.lyco) {
|
| 49 |
+
let multiplier = TAC_CFG.extraNetworksDefaultMultiplier;
|
| 50 |
+
let info = await fetchAPI(`tacapi/v1/lyco-info/${text}`)
|
| 51 |
+
if (info && info["preferred weight"]) {
|
| 52 |
+
multiplier = info["preferred weight"];
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
return `<lyco:${text}:${multiplier}>`;
|
| 56 |
+
}
|
| 57 |
+
return null;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
PARSERS.push(new LycoParser(LYCO_TRIGGER));
|
| 61 |
+
|
| 62 |
+
// Add our utility functions to their respective queues
|
| 63 |
+
QUEUE_FILE_LOAD.push(load);
|
| 64 |
+
QUEUE_SANITIZE.push(sanitize);
|
a1111-sd-webui-tagcomplete-main/javascript/ext_modelKeyword.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
async function load() {
|
| 2 |
+
let modelKeywordParts = (await readFile(`tmp/modelKeywordPath.txt`)).split(",")
|
| 3 |
+
modelKeywordPath = modelKeywordParts[0];
|
| 4 |
+
let customFileExists = modelKeywordParts[1] === "True";
|
| 5 |
+
|
| 6 |
+
if (modelKeywordPath.length > 0 && modelKeywordDict.size === 0) {
|
| 7 |
+
try {
|
| 8 |
+
let csv_lines = [];
|
| 9 |
+
// Only add default keywords if wanted by the user
|
| 10 |
+
if (TAC_CFG.modelKeywordCompletion !== "Only user list")
|
| 11 |
+
csv_lines = (await loadCSV(`${modelKeywordPath}/lora-keyword.txt`));
|
| 12 |
+
// Add custom user keywords if the file exists
|
| 13 |
+
if (customFileExists)
|
| 14 |
+
csv_lines = csv_lines.concat((await loadCSV(`${modelKeywordPath}/lora-keyword-user.txt`)));
|
| 15 |
+
|
| 16 |
+
if (csv_lines.length === 0) return;
|
| 17 |
+
|
| 18 |
+
csv_lines = csv_lines.filter(x => x[0].trim().length > 0 && x[0].trim()[0] !== "#") // Remove empty lines and comments
|
| 19 |
+
|
| 20 |
+
// Add to the dict
|
| 21 |
+
csv_lines.forEach(parts => {
|
| 22 |
+
const hash = parts[0];
|
| 23 |
+
const keywords = parts[1]?.replaceAll("| ", ", ")?.replaceAll("|", ", ")?.trim();
|
| 24 |
+
const lastSepIndex = parts[2]?.lastIndexOf("/") + 1 || parts[2]?.lastIndexOf("\\") + 1 || 0;
|
| 25 |
+
const name = parts[2]?.substring(lastSepIndex).trim() || "none"
|
| 26 |
+
|
| 27 |
+
if (modelKeywordDict.has(hash) && name !== "none") {
|
| 28 |
+
// Add a new name key if the hash already exists
|
| 29 |
+
modelKeywordDict.get(hash).set(name, keywords);
|
| 30 |
+
} else {
|
| 31 |
+
// Create new hash entry
|
| 32 |
+
let map = new Map().set(name, keywords);
|
| 33 |
+
modelKeywordDict.set(hash, map);
|
| 34 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const UMI_PROMPT_REGEX = /<[^\s]*?\[[^,<>]*[\]|]?>?/gi;
|
| 2 |
+
const UMI_TAG_REGEX = /(?:\[|\||--)([^<>\[\]\-|]+)/gi;
|
| 3 |
+
|
| 4 |
+
const UMI_TRIGGER = () => TAC_CFG.useWildcards && [...tagword.matchAll(UMI_PROMPT_REGEX)].length > 0;
|
| 5 |
+
|
| 6 |
+
class UmiParser extends BaseTagParser {
|
| 7 |
+
parse(textArea, prompt) {
|
| 8 |
+
// We are in a UMI yaml tag definition, parse further
|
| 9 |
+
let umiSubPrompts = [...prompt.matchAll(UMI_PROMPT_REGEX)];
|
| 10 |
+
|
| 11 |
+
let umiTags = [];
|
| 12 |
+
let umiTagsWithOperators = []
|
| 13 |
+
|
| 14 |
+
const insertAt = (str,char,pos) => str.slice(0,pos) + char + str.slice(pos);
|
| 15 |
+
|
| 16 |
+
umiSubPrompts.forEach(umiSubPrompt => {
|
| 17 |
+
umiTags = umiTags.concat([...umiSubPrompt[0].matchAll(UMI_TAG_REGEX)].map(x => x[1].toLowerCase()));
|
| 18 |
+
|
| 19 |
+
const start = umiSubPrompt.index;
|
| 20 |
+
const end = umiSubPrompt.index + umiSubPrompt[0].length;
|
| 21 |
+
if (textArea.selectionStart >= start && textArea.selectionStart <= end) {
|
| 22 |
+
umiTagsWithOperators = insertAt(umiSubPrompt[0], '###', textArea.selectionStart - start);
|
| 23 |
+
}
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
+
// Safety check since UMI parsing sometimes seems to trigger outside of an UMI subprompt and thus fails
|
| 27 |
+
if (umiTagsWithOperators.length === 0) {
|
| 28 |
+
return null;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
const promptSplitToTags = umiTagsWithOperators.replace(']###[', '][').split("][");
|
| 32 |
+
|
| 33 |
+
const clean = (str) => str
|
| 34 |
+
.replaceAll('>', '')
|
| 35 |
+
.replaceAll('<', '')
|
| 36 |
+
.replaceAll('[', '')
|
| 37 |
+
.replaceAll(']', '')
|
| 38 |
+
.trim();
|
| 39 |
+
|
| 40 |
+
const matches = promptSplitToTags.reduce((acc, curr) => {
|
| 41 |
+
let isOptional = curr.includes("|");
|
| 42 |
+
let isNegative = curr.startsWith("--");
|
| 43 |
+
let out;
|
| 44 |
+
if (isOptional) {
|
| 45 |
+
out = {
|
| 46 |
+
hasCursor: curr.includes("###"),
|
| 47 |
+
tags: clean(curr).split('|').map(x => ({
|
| 48 |
+
hasCursor: x.includes("###"),
|
| 49 |
+
isNegative: x.startsWith("--"),
|
| 50 |
+
tag: clean(x).replaceAll("###", '').replaceAll("--", '')
|
| 51 |
+
}))
|
| 52 |
+
};
|
| 53 |
+
acc.optional.push(out);
|
| 54 |
+
acc.all.push(...out.tags.map(x => x.tag));
|
| 55 |
+
} else if (isNegative) {
|
| 56 |
+
out = {
|
| 57 |
+
hasCursor: curr.includes("###"),
|
| 58 |
+
tags: clean(curr).replaceAll("###", '').split('|'),
|
| 59 |
+
};
|
| 60 |
+
out.tags = out.tags.map(x => x.startsWith("--") ? x.substring(2) : x);
|
| 61 |
+
acc.negative.push(out);
|
| 62 |
+
acc.all.push(...out.tags);
|
| 63 |
+
} else {
|
| 64 |
+
out = {
|
| 65 |
+
hasCursor: curr.includes("###"),
|
| 66 |
+
tags: clean(curr).replaceAll("###", '').split('|'),
|
| 67 |
+
};
|
| 68 |
+
acc.positive.push(out);
|
| 69 |
+
acc.all.push(...out.tags);
|
| 70 |
+
}
|
| 71 |
+
return acc;
|
| 72 |
+
}, { positive: [], negative: [], optional: [], all: [] });
|
| 73 |
+
|
| 74 |
+
//console.log({ matches })
|
| 75 |
+
|
| 76 |
+
const filteredWildcards = (tagword) => {
|
| 77 |
+
const wildcards = umiWildcards.filter(x => {
|
| 78 |
+
let tags = x[1];
|
| 79 |
+
const matchesNeg =
|
| 80 |
+
matches.negative.length === 0
|
| 81 |
+
|| matches.negative.every(x =>
|
| 82 |
+
x.hasCursor
|
| 83 |
+
|| x.tags.every(t => !tags[t])
|
| 84 |
+
);
|
| 85 |
+
if (!matchesNeg) return false;
|
| 86 |
+
const matchesPos =
|
| 87 |
+
matches.positive.length === 0
|
| 88 |
+
|| matches.positive.every(x =>
|
| 89 |
+
x.hasCursor
|
| 90 |
+
|| x.tags.every(t => tags[t])
|
| 91 |
+
);
|
| 92 |
+
if (!matchesPos) return false;
|
| 93 |
+
const matchesOpt =
|
| 94 |
+
matches.optional.length === 0
|
| 95 |
+
|| matches.optional.some(x =>
|
| 96 |
+
x.tags.some(t =>
|
| 97 |
+
t.hasCursor
|
| 98 |
+
|| t.isNegative
|
| 99 |
+
? !tags[t.tag]
|
| 100 |
+
: tags[t.tag]
|
| 101 |
+
));
|
| 102 |
+
if (!matchesOpt) return false;
|
| 103 |
+
return true;
|
| 104 |
+
}).reduce((acc, val) => {
|
| 105 |
+
Object.keys(val[1]).forEach(tag => acc[tag] = acc[tag] + 1 || 1);
|
| 106 |
+
return acc;
|
| 107 |
+
}, {});
|
| 108 |
+
|
| 109 |
+
return Object.entries(wildcards)
|
| 110 |
+
.sort((a, b) => b[1] - a[1])
|
| 111 |
+
.filter(x =>
|
| 112 |
+
x[0] === tagword
|
| 113 |
+
|| !matches.all.includes(x[0])
|
| 114 |
+
);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
if (umiTags.length > 0) {
|
| 118 |
+
// Get difference for subprompt
|
| 119 |
+
let tagCountChange = umiTags.length - umiPreviousTags.length;
|
| 120 |
+
let diff = difference(umiTags, umiPreviousTags);
|
| 121 |
+
umiPreviousTags = umiTags;
|
| 122 |
+
|
| 123 |
+
// Show all condition
|
| 124 |
+
let showAll = tagword.endsWith("[") || tagword.endsWith("[--") || tagword.endsWith("|");
|
| 125 |
+
|
| 126 |
+
// Exit early if the user closed the bracket manually
|
| 127 |
+
if ((!diff || diff.length === 0 || (diff.length === 1 && tagCountChange < 0)) && !showAll) {
|
| 128 |
+
if (!hideBlocked) hideResults(textArea);
|
| 129 |
+
return;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
let umiTagword = tagCountChange < 0 ? '' : diff[0] || '';
|
| 133 |
+
let tempResults = [];
|
| 134 |
+
if (umiTagword && umiTagword.length > 0) {
|
| 135 |
+
umiTagword = umiTagword.toLowerCase().replace(/[\n\r]/g, "");
|
| 136 |
+
originalTagword = tagword;
|
| 137 |
+
tagword = umiTagword;
|
| 138 |
+
let filteredWildcardsSorted = filteredWildcards(umiTagword);
|
| 139 |
+
let searchRegex = new RegExp(`(^|[^a-zA-Z])${escapeRegExp(umiTagword)}`, 'i')
|
| 140 |
+
let baseFilter = x => x[0].toLowerCase().search(searchRegex) > -1;
|
| 141 |
+
let spaceIncludeFilter = x => x[0].toLowerCase().replaceAll(" ", "_").search(searchRegex) > -1;
|
| 142 |
+
tempResults = filteredWildcardsSorted.filter(x => baseFilter(x) || spaceIncludeFilter(x)) // Filter by tagword
|
| 143 |
+
|
| 144 |
+
// Add final results
|
| 145 |
+
let finalResults = [];
|
| 146 |
+
tempResults.forEach(t => {
|
| 147 |
+
let result = new AutocompleteResult(t[0].trim(), ResultType.umiWildcard)
|
| 148 |
+
result.count = t[1];
|
| 149 |
+
finalResults.push(result);
|
| 150 |
+
});
|
| 151 |
+
|
| 152 |
+
finalResults = finalResults.sort((a, b) => b.count - a.count);
|
| 153 |
+
return finalResults;
|
| 154 |
+
} else if (showAll) {
|
| 155 |
+
let filteredWildcardsSorted = filteredWildcards("");
|
| 156 |
+
|
| 157 |
+
// Add final results
|
| 158 |
+
let finalResults = [];
|
| 159 |
+
filteredWildcardsSorted.forEach(t => {
|
| 160 |
+
let result = new AutocompleteResult(t[0].trim(), ResultType.umiWildcard)
|
| 161 |
+
result.count = t[1];
|
| 162 |
+
finalResults.push(result);
|
| 163 |
+
});
|
| 164 |
+
|
| 165 |
+
originalTagword = tagword;
|
| 166 |
+
tagword = "";
|
| 167 |
+
|
| 168 |
+
finalResults = finalResults.sort((a, b) => b.count - a.count);
|
| 169 |
+
return finalResults;
|
| 170 |
+
}
|
| 171 |
+
} else {
|
| 172 |
+
let filteredWildcardsSorted = filteredWildcards("");
|
| 173 |
+
|
| 174 |
+
// Add final results
|
| 175 |
+
let finalResults = [];
|
| 176 |
+
filteredWildcardsSorted.forEach(t => {
|
| 177 |
+
let result = new AutocompleteResult(t[0].trim(), ResultType.umiWildcard)
|
| 178 |
+
result.count = t[1];
|
| 179 |
+
finalResults.push(result);
|
| 180 |
+
});
|
| 181 |
+
|
| 182 |
+
originalTagword = tagword;
|
| 183 |
+
tagword = "";
|
| 184 |
+
|
| 185 |
+
finalResults = finalResults.sort((a, b) => b.count - a.count);
|
| 186 |
+
return finalResults;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
function updateUmiTags(tagType, sanitizedText, newPrompt, textArea) {
|
| 192 |
+
// If it was a umi wildcard, also update the umiPreviousTags
|
| 193 |
+
if (tagType === ResultType.umiWildcard && originalTagword.length > 0) {
|
| 194 |
+
let umiSubPrompts = [...newPrompt.matchAll(UMI_PROMPT_REGEX)];
|
| 195 |
+
|
| 196 |
+
let umiTags = [];
|
| 197 |
+
umiSubPrompts.forEach(umiSubPrompt => {
|
| 198 |
+
umiTags = umiTags.concat([...umiSubPrompt[0].matchAll(UMI_TAG_REGEX)].map(x => x[1].toLowerCase()));
|
| 199 |
+
});
|
| 200 |
+
|
| 201 |
+
umiPreviousTags = umiTags;
|
| 202 |
+
|
| 203 |
+
hideResults(textArea);
|
| 204 |
+
|
| 205 |
+
return true;
|
| 206 |
+
}
|
| 207 |
+
return false;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
async function load() {
|
| 211 |
+
if (umiWildcards.length === 0) {
|
| 212 |
+
try {
|
| 213 |
+
let umiTags = (await readFile(`${tagBasePath}/temp/umi_tags.txt`)).split("\n");
|
| 214 |
+
// Split into tag, count pairs
|
| 215 |
+
umiWildcards = umiTags.map(x => x
|
| 216 |
+
.trim()
|
| 217 |
+
.split(","))
|
| 218 |
+
.map(([i, ...rest]) => [
|
| 219 |
+
i,
|
| 220 |
+
rest.reduce((a, b) => {
|
| 221 |
+
a[b.toLowerCase()] = true;
|
| 222 |
+
return a;
|
| 223 |
+
}, {}),
|
| 224 |
+
]);
|
| 225 |
+
} catch (e) {
|
| 226 |
+
console.error("Error loading umi wildcards: " + e);
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
function sanitize(tagType, text) {
|
| 232 |
+
// Replace underscores only if the umi tag is not using them
|
| 233 |
+
if (tagType === ResultType.umiWildcard && !umiWildcards.includes(text)) {
|
| 234 |
+
return text.replaceAll("_", " ");
|
| 235 |
+
}
|
| 236 |
+
return null;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// Add UMI parser
|
| 240 |
+
PARSERS.push(new UmiParser(UMI_TRIGGER));
|
| 241 |
+
|
| 242 |
+
// Add our utility functions to their respective queues
|
| 243 |
+
QUEUE_FILE_LOAD.push(load);
|
| 244 |
+
QUEUE_SANITIZE.push(sanitize);
|
| 245 |
+
QUEUE_AFTER_INSERT.push(updateUmiTags);
|
a1111-sd-webui-tagcomplete-main/javascript/ext_wildcards.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Regex
|
| 2 |
+
const WC_REGEX = /\b__([^,]+)__([^, ]*)\b/g;
|
| 3 |
+
|
| 4 |
+
// Trigger conditions
|
| 5 |
+
const WC_TRIGGER = () => TAC_CFG.useWildcards && [...tagword.matchAll(WC_REGEX)].length > 0;
|
| 6 |
+
const WC_FILE_TRIGGER = () => TAC_CFG.useWildcards && (tagword.startsWith("__") && !tagword.endsWith("__") || tagword === "__");
|
| 7 |
+
|
| 8 |
+
class WildcardParser extends BaseTagParser {
|
| 9 |
+
async parse() {
|
| 10 |
+
// Show wildcards from a file with that name
|
| 11 |
+
let wcMatch = [...tagword.matchAll(WC_REGEX)]
|
| 12 |
+
let wcFile = wcMatch[0][1];
|
| 13 |
+
let wcWord = wcMatch[0][2];
|
| 14 |
+
|
| 15 |
+
// Look in normal wildcard files
|
| 16 |
+
let wcFound = wildcardFiles.filter(x => x[1].toLowerCase() === wcFile);
|
| 17 |
+
if (wcFound.length === 0) wcFound = null;
|
| 18 |
+
// Use found wildcard file or look in external wildcard files
|
| 19 |
+
let wcPairs = wcFound || wildcardExtFiles.filter(x => x[1].toLowerCase() === wcFile);
|
| 20 |
+
|
| 21 |
+
if (!wcPairs) return [];
|
| 22 |
+
|
| 23 |
+
let wildcards = [];
|
| 24 |
+
for (let i = 0; i < wcPairs.length; i++) {
|
| 25 |
+
const basePath = wcPairs[i][0];
|
| 26 |
+
const fileName = wcPairs[i][1];
|
| 27 |
+
if (!basePath || !fileName) return;
|
| 28 |
+
|
| 29 |
+
// YAML wildcards are already loaded as json, so we can get the values directly.
|
| 30 |
+
// basePath is the name of the file in this case, and fileName the key
|
| 31 |
+
if (basePath.endsWith(".yaml")) {
|
| 32 |
+
const getDescendantProp = (obj, desc) => {
|
| 33 |
+
const arr = desc.split("/");
|
| 34 |
+
while (arr.length) {
|
| 35 |
+
obj = obj[arr.shift()];
|
| 36 |
+
}
|
| 37 |
+
return obj;
|
| 38 |
+
}
|
| 39 |
+
wildcards = wildcards.concat(getDescendantProp(yamlWildcards[basePath], fileName));
|
| 40 |
+
} else {
|
| 41 |
+
const fileContent = (await fetchAPI(`tacapi/v1/wildcard-contents?basepath=${basePath}&filename=${fileName}.txt`, false))
|
| 42 |
+
.split("\n")
|
| 43 |
+
.filter(x => x.trim().length > 0 && !x.startsWith('#')); // Remove empty lines and comments
|
| 44 |
+
wildcards = wildcards.concat(fileContent);
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
if (TAC_CFG.sortWildcardResults)
|
| 49 |
+
wildcards.sort((a, b) => a.localeCompare(b));
|
| 50 |
+
|
| 51 |
+
let finalResults = [];
|
| 52 |
+
let tempResults = wildcards.filter(x => (wcWord !== null && wcWord.length > 0) ? x.toLowerCase().includes(wcWord) : x) // Filter by tagword
|
| 53 |
+
tempResults.forEach(t => {
|
| 54 |
+
let result = new AutocompleteResult(t.trim(), ResultType.wildcardTag);
|
| 55 |
+
result.meta = wcFile;
|
| 56 |
+
finalResults.push(result);
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
return finalResults;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
class WildcardFileParser extends BaseTagParser {
|
| 64 |
+
parse() {
|
| 65 |
+
// Show available wildcard files
|
| 66 |
+
let tempResults = [];
|
| 67 |
+
if (tagword !== "__") {
|
| 68 |
+
let lmb = (x) => x[1].toLowerCase().includes(tagword.replace("__", ""))
|
| 69 |
+
tempResults = wildcardFiles.filter(lmb).concat(wildcardExtFiles.filter(lmb)) // Filter by tagword
|
| 70 |
+
} else {
|
| 71 |
+
tempResults = wildcardFiles.concat(wildcardExtFiles);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
let finalResults = [];
|
| 75 |
+
const alreadyAdded = new Map();
|
| 76 |
+
// Get final results
|
| 77 |
+
tempResults.forEach(wcFile => {
|
| 78 |
+
// Skip duplicate entries incase multiple files have the same name or yaml category
|
| 79 |
+
if (alreadyAdded.has(wcFile[1])) return;
|
| 80 |
+
|
| 81 |
+
let result = null;
|
| 82 |
+
if (wcFile[0].endsWith(".yaml")) {
|
| 83 |
+
result = new AutocompleteResult(wcFile[1].trim(), ResultType.yamlWildcard);
|
| 84 |
+
result.meta = "YAML wildcard collection";
|
| 85 |
+
} else {
|
| 86 |
+
result = new AutocompleteResult(wcFile[1].trim(), ResultType.wildcardFile);
|
| 87 |
+
result.meta = "Wildcard file";
|
| 88 |
+
result.sortKey = wcFile[2].trim();
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
finalResults.push(result);
|
| 92 |
+
alreadyAdded.set(wcFile[1], true);
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
finalResults.sort(getSortFunction());
|
| 96 |
+
|
| 97 |
+
return finalResults;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
async function load() {
|
| 102 |
+
if (wildcardFiles.length === 0 && wildcardExtFiles.length === 0) {
|
| 103 |
+
try {
|
| 104 |
+
let wcFileArr = await loadCSV(`${tagBasePath}/temp/wc.txt`);
|
| 105 |
+
if (wcFileArr && wcFileArr.length > 0) {
|
| 106 |
+
let wcBasePath = wcFileArr[0][0].trim(); // First line should be the base path
|
| 107 |
+
wildcardFiles = wcFileArr.slice(1)
|
| 108 |
+
.filter(x => x[0]?.trim().length > 0) //Remove empty lines
|
| 109 |
+
.map(x => [wcBasePath, x[0]?.trim().replace(".txt", ""), x[1]]); // Remove file extension & newlines
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// To support multiple sources, we need to separate them using the provided "-----" strings
|
| 113 |
+
let wcExtFileArr = await loadCSV(`${tagBasePath}/temp/wce.txt`);
|
| 114 |
+
let splitIndices = [];
|
| 115 |
+
for (let index = 0; index < wcExtFileArr.length; index++) {
|
| 116 |
+
if (wcExtFileArr[index][0].trim() === "-----") {
|
| 117 |
+
splitIndices.push(index);
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
// For each group, add them to the wildcardFiles array with the base path as the first element
|
| 121 |
+
for (let i = 0; i < splitIndices.length; i++) {
|
| 122 |
+
let start = splitIndices[i - 1] || 0;
|
| 123 |
+
if (i > 0) start++; // Skip the "-----" line
|
| 124 |
+
let end = splitIndices[i];
|
| 125 |
+
|
| 126 |
+
let wcExtFile = wcExtFileArr.slice(start, end);
|
| 127 |
+
if (wcExtFile && wcExtFile.length > 0) {
|
| 128 |
+
let base = wcExtFile[0][0].trim() + "/";
|
| 129 |
+
wcExtFile = wcExtFile.slice(1)
|
| 130 |
+
.filter(x => x[0]?.trim().length > 0) //Remove empty lines
|
| 131 |
+
.map(x => [base, x[0]?.trim().replace(base, "").replace(".txt", ""), x[1]]);
|
| 132 |
+
wildcardExtFiles.push(...wcExtFile);
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
// Load the yaml wildcard json file and append it as a wildcard file, appending each key as a path component until we reach the end
|
| 137 |
+
yamlWildcards = await readFile(`${tagBasePath}/temp/wc_yaml.json`, true);
|
| 138 |
+
|
| 139 |
+
// Append each key as a path component until we reach a leaf
|
| 140 |
+
Object.keys(yamlWildcards).forEach(file => {
|
| 141 |
+
const flattened = flatten(yamlWildcards[file], [], "/");
|
| 142 |
+
Object.keys(flattened).forEach(key => {
|
| 143 |
+
wildcardExtFiles.push([file, key]);
|
| 144 |
+
});
|
| 145 |
+
});
|
| 146 |
+
} catch (e) {
|
| 147 |
+
console.error("Error loading wildcards: " + e);
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
function sanitize(tagType, text) {
|
| 153 |
+
if (tagType === ResultType.wildcardFile || tagType === ResultType.yamlWildcard) {
|
| 154 |
+
return `__${text}__`;
|
| 155 |
+
} else if (tagType === ResultType.wildcardTag) {
|
| 156 |
+
return text.replace(/^.*?: /g, "");
|
| 157 |
+
}
|
| 158 |
+
return null;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
function keepOpenIfWildcard(tagType, sanitizedText, newPrompt, textArea) {
|
| 162 |
+
// If it's a wildcard, we want to keep the results open so the user can select another wildcard
|
| 163 |
+
if (tagType === ResultType.wildcardFile || tagType === ResultType.yamlWildcard) {
|
| 164 |
+
hideBlocked = true;
|
| 165 |
+
setTimeout(() => { hideBlocked = false; }, 450);
|
| 166 |
+
return true;
|
| 167 |
+
}
|
| 168 |
+
return false;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
// Register the parsers
|
| 172 |
+
PARSERS.push(new WildcardParser(WC_TRIGGER));
|
| 173 |
+
PARSERS.push(new WildcardFileParser(WC_FILE_TRIGGER));
|
| 174 |
+
|
| 175 |
+
// Add our utility functions to their respective queues
|
| 176 |
+
QUEUE_FILE_LOAD.push(load);
|
| 177 |
+
QUEUE_SANITIZE.push(sanitize);
|
| 178 |
+
QUEUE_AFTER_INSERT.push(keepOpenIfWildcard);
|
a1111-sd-webui-tagcomplete-main/javascript/tagAutocomplete.js
ADDED
|
@@ -0,0 +1,1431 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const styleColors = {
|
| 2 |
+
"--results-bg": ["#0b0f19", "#ffffff"],
|
| 3 |
+
"--results-border-color": ["#4b5563", "#e5e7eb"],
|
| 4 |
+
"--results-border-width": ["1px", "1.5px"],
|
| 5 |
+
"--results-bg-odd": ["#111827", "#f9fafb"],
|
| 6 |
+
"--results-hover": ["#1f2937", "#f5f6f8"],
|
| 7 |
+
"--results-selected": ["#374151", "#e5e7eb"],
|
| 8 |
+
"--meta-text-color": ["#6b6f7b", "#a2a9b4"],
|
| 9 |
+
"--embedding-v1-color": ["lightsteelblue", "#2b5797"],
|
| 10 |
+
"--embedding-v2-color": ["skyblue", "#2d89ef"],
|
| 11 |
+
"--live-translation-rt": ["whitesmoke", "#222"],
|
| 12 |
+
"--live-translation-color-1": ["lightskyblue", "#2d89ef"],
|
| 13 |
+
"--live-translation-color-2": ["palegoldenrod", "#eb5700"],
|
| 14 |
+
"--live-translation-color-3": ["darkseagreen", "darkgreen"],
|
| 15 |
+
}
|
| 16 |
+
const browserVars = {
|
| 17 |
+
"--results-overflow-y": {
|
| 18 |
+
"firefox": "scroll",
|
| 19 |
+
"other": "auto"
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
// Style for new elements. Gets appended to the Gradio root.
|
| 23 |
+
const autocompleteCSS = `
|
| 24 |
+
#quicksettings [id^=setting_tac] {
|
| 25 |
+
background-color: transparent;
|
| 26 |
+
min-width: fit-content;
|
| 27 |
+
}
|
| 28 |
+
.autocompleteParent {
|
| 29 |
+
display: flex;
|
| 30 |
+
position: absolute;
|
| 31 |
+
z-index: 999;
|
| 32 |
+
max-width: calc(100% - 1.5rem);
|
| 33 |
+
margin: 5px 0 0 0;
|
| 34 |
+
}
|
| 35 |
+
.autocompleteResults {
|
| 36 |
+
background-color: var(--results-bg) !important;
|
| 37 |
+
border: var(--results-border-width) solid var(--results-border-color) !important;
|
| 38 |
+
border-radius: 12px !important;
|
| 39 |
+
height: fit-content;
|
| 40 |
+
flex-basis: fit-content;
|
| 41 |
+
flex-shrink: 0;
|
| 42 |
+
overflow-y: var(--results-overflow-y);
|
| 43 |
+
overflow-x: hidden;
|
| 44 |
+
word-break: break-word;
|
| 45 |
+
}
|
| 46 |
+
.sideInfo {
|
| 47 |
+
display: none;
|
| 48 |
+
position: relative;
|
| 49 |
+
margin-left: 10px;
|
| 50 |
+
height: 18rem;
|
| 51 |
+
max-width: 16rem;
|
| 52 |
+
}
|
| 53 |
+
.sideInfo > img {
|
| 54 |
+
object-fit: cover;
|
| 55 |
+
height: 100%;
|
| 56 |
+
width: 100%;
|
| 57 |
+
}
|
| 58 |
+
.autocompleteResultsList > li:nth-child(odd) {
|
| 59 |
+
background-color: var(--results-bg-odd);
|
| 60 |
+
}
|
| 61 |
+
.autocompleteResultsList > li {
|
| 62 |
+
list-style-type: none;
|
| 63 |
+
padding: 10px;
|
| 64 |
+
cursor: pointer;
|
| 65 |
+
}
|
| 66 |
+
.autocompleteResultsList > li:hover {
|
| 67 |
+
background-color: var(--results-hover);
|
| 68 |
+
}
|
| 69 |
+
.autocompleteResultsList > li.selected {
|
| 70 |
+
background-color: var(--results-selected);
|
| 71 |
+
}
|
| 72 |
+
.resultsFlexContainer {
|
| 73 |
+
display: flex;
|
| 74 |
+
}
|
| 75 |
+
.acListItem {
|
| 76 |
+
white-space: break-spaces;
|
| 77 |
+
min-width: 100px;
|
| 78 |
+
}
|
| 79 |
+
.acMetaText {
|
| 80 |
+
position: relative;
|
| 81 |
+
flex-grow: 1;
|
| 82 |
+
text-align: end;
|
| 83 |
+
padding: 0 0 0 15px;
|
| 84 |
+
white-space: nowrap;
|
| 85 |
+
color: var(--meta-text-color);
|
| 86 |
+
}
|
| 87 |
+
.acWikiLink {
|
| 88 |
+
padding: 0.5rem;
|
| 89 |
+
margin: -0.5rem 0 -0.5rem -0.5rem;
|
| 90 |
+
}
|
| 91 |
+
.acWikiLink:hover {
|
| 92 |
+
text-decoration: underline;
|
| 93 |
+
}
|
| 94 |
+
.acListItem.acEmbeddingV1 {
|
| 95 |
+
color: var(--embedding-v1-color);
|
| 96 |
+
}
|
| 97 |
+
.acListItem.acEmbeddingV2 {
|
| 98 |
+
color: var(--embedding-v2-color);
|
| 99 |
+
}
|
| 100 |
+
.acRuby {
|
| 101 |
+
padding: var(--input-padding);
|
| 102 |
+
color: #888;
|
| 103 |
+
font-size: 0.8rem;
|
| 104 |
+
user-select: none;
|
| 105 |
+
}
|
| 106 |
+
.acRuby > ruby {
|
| 107 |
+
display: inline-flex;
|
| 108 |
+
flex-direction: column-reverse;
|
| 109 |
+
margin-top: 0.5rem;
|
| 110 |
+
vertical-align: bottom;
|
| 111 |
+
cursor: pointer;
|
| 112 |
+
}
|
| 113 |
+
.acRuby > ruby::hover {
|
| 114 |
+
text-decoration: underline;
|
| 115 |
+
text-shadow: 0 0 10px var(--live-translation-color-1);
|
| 116 |
+
}
|
| 117 |
+
.acRuby > :nth-child(3n+1) {
|
| 118 |
+
color: var(--live-translation-color-1);
|
| 119 |
+
}
|
| 120 |
+
.acRuby > :nth-child(3n+2) {
|
| 121 |
+
color: var(--live-translation-color-2);
|
| 122 |
+
}
|
| 123 |
+
.acRuby > :nth-child(3n+3) {
|
| 124 |
+
color: var(--live-translation-color-3);
|
| 125 |
+
}
|
| 126 |
+
.acRuby > ruby > rt {
|
| 127 |
+
line-height: 1rem;
|
| 128 |
+
padding: 0px 5px 0px 0px;
|
| 129 |
+
text-align: left;
|
| 130 |
+
font-size: 1rem;
|
| 131 |
+
color: var(--live-translation-rt);
|
| 132 |
+
}
|
| 133 |
+
.acListItem .acPathPart:nth-child(3n+1) {
|
| 134 |
+
color: var(--live-translation-color-1);
|
| 135 |
+
}
|
| 136 |
+
.acListItem .acPathPart:nth-child(3n+2) {
|
| 137 |
+
color: var(--live-translation-color-2);
|
| 138 |
+
}
|
| 139 |
+
.acListItem .acPathPart:nth-child(3n+3) {
|
| 140 |
+
color: var(--live-translation-color-3);
|
| 141 |
+
}
|
| 142 |
+
`;
|
| 143 |
+
|
| 144 |
+
async function loadTags(c) {
|
| 145 |
+
// Load main tags and aliases
|
| 146 |
+
if (allTags.length === 0 && c.tagFile && c.tagFile !== "None") {
|
| 147 |
+
try {
|
| 148 |
+
allTags = await loadCSV(`${tagBasePath}/${c.tagFile}`);
|
| 149 |
+
} catch (e) {
|
| 150 |
+
console.error("Error loading tags file: " + e);
|
| 151 |
+
return;
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
await loadExtraTags(c);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
async function loadExtraTags(c) {
|
| 158 |
+
if (c.extra.extraFile && c.extra.extraFile !== "None") {
|
| 159 |
+
try {
|
| 160 |
+
extras = await loadCSV(`${tagBasePath}/${c.extra.extraFile}`);
|
| 161 |
+
// Add translations to the main translation map for extra tags that have them
|
| 162 |
+
extras.forEach(e => {
|
| 163 |
+
if (e[4]) translations.set(e[0], e[4]);
|
| 164 |
+
});
|
| 165 |
+
} catch (e) {
|
| 166 |
+
console.error("Error loading extra file: " + e);
|
| 167 |
+
return;
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
async function loadTranslations(c) {
|
| 173 |
+
if (c.translation.translationFile && c.translation.translationFile !== "None") {
|
| 174 |
+
try {
|
| 175 |
+
let tArray = await loadCSV(`${tagBasePath}/${c.translation.translationFile}`);
|
| 176 |
+
tArray.forEach(t => {
|
| 177 |
+
if (c.translation.oldFormat && t[2]) // if 2 doesn't exist, it's probably a new format file and the setting is on by mistake
|
| 178 |
+
translations.set(t[0], t[2]);
|
| 179 |
+
else if (t[1])
|
| 180 |
+
translations.set(t[0], t[1]);
|
| 181 |
+
else
|
| 182 |
+
translations.set(t[0], "Not found");
|
| 183 |
+
});
|
| 184 |
+
} catch (e) {
|
| 185 |
+
console.error("Error loading translations file: " + e);
|
| 186 |
+
return;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
async function syncOptions() {
|
| 192 |
+
let newCFG = {
|
| 193 |
+
// Main tag file
|
| 194 |
+
tagFile: opts["tac_tagFile"],
|
| 195 |
+
// Active in settings
|
| 196 |
+
activeIn: {
|
| 197 |
+
global: opts["tac_active"],
|
| 198 |
+
txt2img: opts["tac_activeIn.txt2img"],
|
| 199 |
+
img2img: opts["tac_activeIn.img2img"],
|
| 200 |
+
negativePrompts: opts["tac_activeIn.negativePrompts"],
|
| 201 |
+
thirdParty: opts["tac_activeIn.thirdParty"],
|
| 202 |
+
modelList: opts["tac_activeIn.modelList"],
|
| 203 |
+
modelListMode: opts["tac_activeIn.modelListMode"]
|
| 204 |
+
},
|
| 205 |
+
// Results related settings
|
| 206 |
+
slidingPopup: opts["tac_slidingPopup"],
|
| 207 |
+
maxResults: opts["tac_maxResults"],
|
| 208 |
+
showAllResults: opts["tac_showAllResults"],
|
| 209 |
+
resultStepLength: opts["tac_resultStepLength"],
|
| 210 |
+
delayTime: opts["tac_delayTime"],
|
| 211 |
+
useWildcards: opts["tac_useWildcards"],
|
| 212 |
+
sortWildcardResults: opts["tac_sortWildcardResults"],
|
| 213 |
+
useEmbeddings: opts["tac_useEmbeddings"],
|
| 214 |
+
includeEmbeddingsInNormalResults: opts["tac_includeEmbeddingsInNormalResults"],
|
| 215 |
+
useHypernetworks: opts["tac_useHypernetworks"],
|
| 216 |
+
useLoras: opts["tac_useLoras"],
|
| 217 |
+
useLycos: opts["tac_useLycos"],
|
| 218 |
+
showWikiLinks: opts["tac_showWikiLinks"],
|
| 219 |
+
showExtraNetworkPreviews: opts["tac_showExtraNetworkPreviews"],
|
| 220 |
+
modelSortOrder: opts["tac_modelSortOrder"],
|
| 221 |
+
// Insertion related settings
|
| 222 |
+
replaceUnderscores: opts["tac_replaceUnderscores"],
|
| 223 |
+
escapeParentheses: opts["tac_escapeParentheses"],
|
| 224 |
+
appendComma: opts["tac_appendComma"],
|
| 225 |
+
appendSpace: opts["tac_appendSpace"],
|
| 226 |
+
alwaysSpaceAtEnd: opts["tac_alwaysSpaceAtEnd"],
|
| 227 |
+
wildcardCompletionMode: opts["tac_wildcardCompletionMode"],
|
| 228 |
+
modelKeywordCompletion: opts["tac_modelKeywordCompletion"],
|
| 229 |
+
modelKeywordLocation: opts["tac_modelKeywordLocation"],
|
| 230 |
+
// Alias settings
|
| 231 |
+
alias: {
|
| 232 |
+
searchByAlias: opts["tac_alias.searchByAlias"],
|
| 233 |
+
onlyShowAlias: opts["tac_alias.onlyShowAlias"]
|
| 234 |
+
},
|
| 235 |
+
// Translation settings
|
| 236 |
+
translation: {
|
| 237 |
+
translationFile: opts["tac_translation.translationFile"],
|
| 238 |
+
oldFormat: opts["tac_translation.oldFormat"],
|
| 239 |
+
searchByTranslation: opts["tac_translation.searchByTranslation"],
|
| 240 |
+
liveTranslation: opts["tac_translation.liveTranslation"],
|
| 241 |
+
},
|
| 242 |
+
// Extra file settings
|
| 243 |
+
extra: {
|
| 244 |
+
extraFile: opts["tac_extra.extraFile"],
|
| 245 |
+
addMode: opts["tac_extra.addMode"]
|
| 246 |
+
},
|
| 247 |
+
// Chant file settings
|
| 248 |
+
chantFile: opts["tac_chantFile"],
|
| 249 |
+
// Settings not from tac but still used by the script
|
| 250 |
+
extraNetworksDefaultMultiplier: opts["extra_networks_default_multiplier"],
|
| 251 |
+
extraNetworksSeparator: opts["extra_networks_add_text_separator"],
|
| 252 |
+
// Custom mapping settings
|
| 253 |
+
keymap: JSON.parse(opts["tac_keymap"]),
|
| 254 |
+
colorMap: JSON.parse(opts["tac_colormap"])
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
if (newCFG.alias.onlyShowAlias) {
|
| 258 |
+
newCFG.alias.searchByAlias = true; // if only show translation, enable search by translation is necessary
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Reload translations if the translation file changed
|
| 262 |
+
if (!TAC_CFG || newCFG.translation.translationFile !== TAC_CFG.translation.translationFile) {
|
| 263 |
+
translations.clear();
|
| 264 |
+
await loadTranslations(newCFG);
|
| 265 |
+
await loadExtraTags(newCFG);
|
| 266 |
+
}
|
| 267 |
+
// Reload tags if the tag file changed (after translations so extra tag translations get re-added)
|
| 268 |
+
if (!TAC_CFG || newCFG.tagFile !== TAC_CFG.tagFile || newCFG.extra.extraFile !== TAC_CFG.extra.extraFile) {
|
| 269 |
+
allTags = [];
|
| 270 |
+
await loadTags(newCFG);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
// Refresh temp files if model sort order changed
|
| 274 |
+
// Contrary to the other loads, this one shouldn't happen on a first time load
|
| 275 |
+
if (TAC_CFG && newCFG.modelSortOrder !== TAC_CFG.modelSortOrder) {
|
| 276 |
+
const dropdown = gradioApp().querySelector("#setting_tac_modelSortOrder");
|
| 277 |
+
dropdown.style.opacity = 0.5;
|
| 278 |
+
dropdown.style.pointerEvents = "none";
|
| 279 |
+
await refreshTacTempFiles(true);
|
| 280 |
+
dropdown.style.opacity = null;
|
| 281 |
+
dropdown.style.pointerEvents = null;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
// Update CSS if maxResults changed
|
| 285 |
+
if (TAC_CFG && newCFG.maxResults !== TAC_CFG.maxResults) {
|
| 286 |
+
gradioApp().querySelectorAll(".autocompleteResults").forEach(r => {
|
| 287 |
+
r.style.maxHeight = `${newCFG.maxResults * 50}px`;
|
| 288 |
+
});
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
// Remove ruby div if live preview was disabled
|
| 292 |
+
if (newCFG.translation.liveTranslation === false) {
|
| 293 |
+
[...gradioApp().querySelectorAll('.acRuby')].forEach(r => {
|
| 294 |
+
r.remove();
|
| 295 |
+
});
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
// Apply changes
|
| 299 |
+
TAC_CFG = newCFG;
|
| 300 |
+
|
| 301 |
+
// Callback
|
| 302 |
+
await processQueue(QUEUE_AFTER_CONFIG_CHANGE, null);
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// Create the result list div and necessary styling
|
| 306 |
+
function createResultsDiv(textArea) {
|
| 307 |
+
let parentDiv = document.createElement("div");
|
| 308 |
+
let resultsDiv = document.createElement("div");
|
| 309 |
+
let resultsList = document.createElement("ul");
|
| 310 |
+
let sideDiv = document.createElement("div");
|
| 311 |
+
let sideDivImg = document.createElement("img");
|
| 312 |
+
|
| 313 |
+
let textAreaId = getTextAreaIdentifier(textArea);
|
| 314 |
+
let typeClass = textAreaId.replaceAll(".", " ");
|
| 315 |
+
|
| 316 |
+
parentDiv.setAttribute("class", `autocompleteParent${typeClass}`);
|
| 317 |
+
|
| 318 |
+
resultsDiv.style.maxHeight = `${TAC_CFG.maxResults * 50}px`;
|
| 319 |
+
resultsDiv.setAttribute("class", `autocompleteResults${typeClass} notranslate`);
|
| 320 |
+
resultsDiv.setAttribute("translate", "no");
|
| 321 |
+
resultsList.setAttribute("class", "autocompleteResultsList");
|
| 322 |
+
resultsDiv.appendChild(resultsList);
|
| 323 |
+
|
| 324 |
+
sideDiv.setAttribute("class", `autocompleteResults${typeClass} sideInfo`);
|
| 325 |
+
sideDiv.appendChild(sideDivImg);
|
| 326 |
+
|
| 327 |
+
parentDiv.appendChild(resultsDiv);
|
| 328 |
+
parentDiv.appendChild(sideDiv);
|
| 329 |
+
|
| 330 |
+
return parentDiv;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
// Show or hide the results div
|
| 334 |
+
function isVisible(textArea) {
|
| 335 |
+
let textAreaId = getTextAreaIdentifier(textArea);
|
| 336 |
+
let parentDiv = gradioApp().querySelector('.autocompleteParent' + textAreaId);
|
| 337 |
+
return parentDiv.style.display === "flex";
|
| 338 |
+
}
|
| 339 |
+
function showResults(textArea) {
|
| 340 |
+
let textAreaId = getTextAreaIdentifier(textArea);
|
| 341 |
+
let parentDiv = gradioApp().querySelector('.autocompleteParent' + textAreaId);
|
| 342 |
+
parentDiv.style.display = "flex";
|
| 343 |
+
|
| 344 |
+
if (TAC_CFG.slidingPopup) {
|
| 345 |
+
let caretPosition = getCaretCoordinates(textArea, textArea.selectionEnd).left;
|
| 346 |
+
let offset = Math.min(textArea.offsetLeft - textArea.scrollLeft + caretPosition, textArea.offsetWidth - parentDiv.offsetWidth);
|
| 347 |
+
|
| 348 |
+
parentDiv.style.left = `${offset}px`;
|
| 349 |
+
} else {
|
| 350 |
+
if (parentDiv.style.left)
|
| 351 |
+
parentDiv.style.removeProperty("left");
|
| 352 |
+
}
|
| 353 |
+
// Reset here too to make absolutely sure the browser registers it
|
| 354 |
+
parentDiv.scrollTop = 0;
|
| 355 |
+
|
| 356 |
+
// Ensure preview is hidden
|
| 357 |
+
let previewDiv = gradioApp().querySelector(`.autocompleteParent${textAreaId} .sideInfo`);
|
| 358 |
+
previewDiv.style.display = "none";
|
| 359 |
+
}
|
| 360 |
+
function hideResults(textArea) {
|
| 361 |
+
let textAreaId = getTextAreaIdentifier(textArea);
|
| 362 |
+
let resultsDiv = gradioApp().querySelector('.autocompleteParent' + textAreaId);
|
| 363 |
+
|
| 364 |
+
if (!resultsDiv) return;
|
| 365 |
+
|
| 366 |
+
resultsDiv.style.display = "none";
|
| 367 |
+
selectedTag = null;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
// Function to check activation criteria
|
| 371 |
+
function isEnabled() {
|
| 372 |
+
if (TAC_CFG.activeIn.global) {
|
| 373 |
+
// Skip check if the current model was not correctly detected, since it could wrongly disable the script otherwise
|
| 374 |
+
if (!currentModelName || !currentModelHash) return true;
|
| 375 |
+
|
| 376 |
+
let modelList = TAC_CFG.activeIn.modelList
|
| 377 |
+
.split(",")
|
| 378 |
+
.map(x => x.trim())
|
| 379 |
+
.filter(x => x.length > 0);
|
| 380 |
+
|
| 381 |
+
let shortHash = currentModelHash.substring(0, 10);
|
| 382 |
+
let modelNameWithoutHash = currentModelName.replace(/\[.*\]$/g, "").trim();
|
| 383 |
+
if (TAC_CFG.activeIn.modelListMode.toLowerCase() === "blacklist") {
|
| 384 |
+
// If the current model is in the blacklist, disable
|
| 385 |
+
return modelList.filter(x => x === currentModelName || x === modelNameWithoutHash || x === currentModelHash || x === shortHash).length === 0;
|
| 386 |
+
} else {
|
| 387 |
+
// If the current model is in the whitelist, enable.
|
| 388 |
+
// An empty whitelist is ignored.
|
| 389 |
+
return modelList.length === 0 || modelList.filter(x => x === currentModelName || x === modelNameWithoutHash || x === currentModelHash || x === shortHash).length > 0;
|
| 390 |
+
}
|
| 391 |
+
} else {
|
| 392 |
+
return false;
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
const WEIGHT_REGEX = /[([]([^()[\]:|]+)(?::(?:\d+(?:\.\d+)?|\.\d+))?[)\]]/g;
|
| 397 |
+
const POINTY_REGEX = /<[^\s,<](?:[^\t\n\r,<>]*>|[^\t\n\r,> ]*)/g;
|
| 398 |
+
const COMPLETED_WILDCARD_REGEX = /__[^\s,_][^\t\n\r,_]*[^\s,_]__[^\s,_]*/g;
|
| 399 |
+
const NORMAL_TAG_REGEX = /[^\s,|<>\]:]+_\([^\s,|<>\]:]*\)?|[^\s,|<>():\]]+|</g;
|
| 400 |
+
const RUBY_TAG_REGEX = /[\w\d<][\w\d' \-?!/$%]{2,}>?/g;
|
| 401 |
+
const TAG_REGEX = new RegExp(`${POINTY_REGEX.source}|${COMPLETED_WILDCARD_REGEX.source}|${NORMAL_TAG_REGEX.source}`, "g");
|
| 402 |
+
|
| 403 |
+
// On click, insert the tag into the prompt textbox with respect to the cursor position
|
| 404 |
+
async function insertTextAtCursor(textArea, result, tagword, tabCompletedWithoutChoice = false) {
|
| 405 |
+
let text = result.text;
|
| 406 |
+
let tagType = result.type;
|
| 407 |
+
|
| 408 |
+
let cursorPos = textArea.selectionStart;
|
| 409 |
+
var sanitizedText = text
|
| 410 |
+
|
| 411 |
+
// Run sanitize queue and use first result as sanitized text
|
| 412 |
+
sanitizeResults = await processQueueReturn(QUEUE_SANITIZE, null, tagType, text);
|
| 413 |
+
|
| 414 |
+
if (sanitizeResults && sanitizeResults.length > 0) {
|
| 415 |
+
sanitizedText = sanitizeResults[0];
|
| 416 |
+
} else {
|
| 417 |
+
sanitizedText = TAC_CFG.replaceUnderscores ? text.replaceAll("_", " ") : text;
|
| 418 |
+
|
| 419 |
+
if (TAC_CFG.escapeParentheses && tagType === ResultType.tag) {
|
| 420 |
+
sanitizedText = sanitizedText
|
| 421 |
+
.replaceAll("(", "\\(")
|
| 422 |
+
.replaceAll(")", "\\)")
|
| 423 |
+
.replaceAll("[", "\\[")
|
| 424 |
+
.replaceAll("]", "\\]");
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
if ((tagType === ResultType.wildcardFile || tagType === ResultType.yamlWildcard)
|
| 429 |
+
&& tabCompletedWithoutChoice
|
| 430 |
+
&& TAC_CFG.wildcardCompletionMode !== "Always fully"
|
| 431 |
+
&& sanitizedText.includes("/")) {
|
| 432 |
+
if (TAC_CFG.wildcardCompletionMode === "To next folder level") {
|
| 433 |
+
let regexMatch = sanitizedText.match(new RegExp(`${escapeRegExp(tagword)}([^/]*\\/?)`, "i"));
|
| 434 |
+
if (regexMatch) {
|
| 435 |
+
let pathPart = regexMatch[0];
|
| 436 |
+
// In case the completion would have just added a slash, try again one level deeper
|
| 437 |
+
if (pathPart === `${tagword}/`) {
|
| 438 |
+
pathPart = sanitizedText.match(new RegExp(`${escapeRegExp(tagword)}\\/([^/]*\\/?)`, "i"))[0];
|
| 439 |
+
}
|
| 440 |
+
sanitizedText = pathPart;
|
| 441 |
+
}
|
| 442 |
+
} else if (TAC_CFG.wildcardCompletionMode === "To first difference") {
|
| 443 |
+
let firstDifference = 0;
|
| 444 |
+
let longestResult = results.map(x => x.text.length).reduce((a, b) => Math.max(a, b));
|
| 445 |
+
// Compare the results to each other to find the first point where they differ
|
| 446 |
+
for (let i = 0; i < longestResult; i++) {
|
| 447 |
+
let char = results[0].text[i];
|
| 448 |
+
if (results.every(x => x.text[i] === char)) {
|
| 449 |
+
firstDifference++;
|
| 450 |
+
} else {
|
| 451 |
+
break;
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
// Don't cut off the __ at the end if it is already the full path
|
| 455 |
+
if (firstDifference > 0 && firstDifference < longestResult) {
|
| 456 |
+
// +2 because the sanitized text already has the __ at the start but the matched text doesn't
|
| 457 |
+
sanitizedText = sanitizedText.substring(0, firstDifference + 2);
|
| 458 |
+
} else if (firstDifference === 0) {
|
| 459 |
+
sanitizedText = tagword;
|
| 460 |
+
}
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
var prompt = textArea.value;
|
| 465 |
+
|
| 466 |
+
// Edit prompt text
|
| 467 |
+
let editStart = Math.max(cursorPos - tagword.length, 0);
|
| 468 |
+
let editEnd = Math.min(cursorPos + tagword.length, prompt.length);
|
| 469 |
+
let surrounding = prompt.substring(editStart, editEnd);
|
| 470 |
+
let match = surrounding.match(new RegExp(escapeRegExp(`${tagword}`), "i"));
|
| 471 |
+
let afterInsertCursorPos = editStart + match.index + sanitizedText.length;
|
| 472 |
+
|
| 473 |
+
var optionalSeparator = "";
|
| 474 |
+
let extraNetworkTypes = [ResultType.hypernetwork, ResultType.lora];
|
| 475 |
+
let noCommaTypes = [ResultType.wildcardFile, ResultType.yamlWildcard, ResultType.umiWildcard].concat(extraNetworkTypes);
|
| 476 |
+
if (!noCommaTypes.includes(tagType)) {
|
| 477 |
+
// Append comma if enabled and not already present
|
| 478 |
+
let beforeComma = surrounding.match(new RegExp(`${escapeRegExp(tagword)}[,:]`, "i")) !== null;
|
| 479 |
+
if (TAC_CFG.appendComma)
|
| 480 |
+
optionalSeparator = beforeComma ? "" : ",";
|
| 481 |
+
// Add space if enabled
|
| 482 |
+
if (TAC_CFG.appendSpace && !beforeComma)
|
| 483 |
+
optionalSeparator += " ";
|
| 484 |
+
// If at end of prompt and enabled, override the normal setting if not already added
|
| 485 |
+
if (!TAC_CFG.appendSpace && TAC_CFG.alwaysSpaceAtEnd)
|
| 486 |
+
optionalSeparator += surrounding.match(new RegExp(`${escapeRegExp(tagword)}$`, "im")) !== null ? " " : "";
|
| 487 |
+
} else if (extraNetworkTypes.includes(tagType)) {
|
| 488 |
+
// Use the dedicated separator for extra networks if it's defined, otherwise fall back to space
|
| 489 |
+
optionalSeparator = TAC_CFG.extraNetworksSeparator || " ";
|
| 490 |
+
}
|
| 491 |
+
|
| 492 |
+
// Escape $ signs since they are special chars for the replace function
|
| 493 |
+
// We need four since we're also escaping them in replaceAll in the first place
|
| 494 |
+
sanitizedText = sanitizedText.replaceAll("$", "$$$$");
|
| 495 |
+
|
| 496 |
+
// Replace partial tag word with new text, add comma if needed
|
| 497 |
+
let insert = surrounding.replace(match, sanitizedText + optionalSeparator);
|
| 498 |
+
|
| 499 |
+
// Add back start
|
| 500 |
+
var newPrompt = prompt.substring(0, editStart) + insert + prompt.substring(editEnd);
|
| 501 |
+
|
| 502 |
+
// Add lora/lyco keywords if enabled and found
|
| 503 |
+
let keywordsLength = 0;
|
| 504 |
+
|
| 505 |
+
if (TAC_CFG.modelKeywordCompletion !== "Never" && (tagType === ResultType.lora || tagType === ResultType.lyco)) {
|
| 506 |
+
let keywords = null;
|
| 507 |
+
// Check built-in activation words first
|
| 508 |
+
if (tagType === ResultType.lora || tagType === ResultType.lyco) {
|
| 509 |
+
let info = await fetchAPI(`tacapi/v1/lora-info/${result.text}`)
|
| 510 |
+
if (info && info["activation text"]) {
|
| 511 |
+
keywords = info["activation text"];
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
if (!keywords && modelKeywordPath.length > 0 && result.hash && result.hash !== "NOFILE" && result.hash.length > 0) {
|
| 516 |
+
let nameDict = modelKeywordDict.get(result.hash);
|
| 517 |
+
let names = [result.text + ".safetensors", result.text + ".pt", result.text + ".ckpt"];
|
| 518 |
+
|
| 519 |
+
// No match, try to find a sha256 match from the cache file
|
| 520 |
+
if (!nameDict) {
|
| 521 |
+
const sha256 = await fetchAPI(`/tacapi/v1/lora-cached-hash/${result.text}`)
|
| 522 |
+
if (sha256) {
|
| 523 |
+
nameDict = modelKeywordDict.get(sha256);
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
if (nameDict) {
|
| 528 |
+
let found = false;
|
| 529 |
+
names.forEach(name => {
|
| 530 |
+
if (!found && nameDict.has(name)) {
|
| 531 |
+
found = true;
|
| 532 |
+
keywords = nameDict.get(name);
|
| 533 |
+
}
|
| 534 |
+
});
|
| 535 |
+
|
| 536 |
+
if (!found)
|
| 537 |
+
keywords = nameDict.get("none");
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
if (keywords && keywords.length > 0) {
|
| 542 |
+
textBeforeKeywordInsertion = newPrompt;
|
| 543 |
+
|
| 544 |
+
if (TAC_CFG.modelKeywordLocation === "Start of prompt")
|
| 545 |
+
newPrompt = `${keywords}, ${newPrompt}`; // Insert keywords
|
| 546 |
+
else if (TAC_CFG.modelKeywordLocation === "End of prompt")
|
| 547 |
+
newPrompt = `${newPrompt}, ${keywords}`; // Insert keywords
|
| 548 |
+
else {
|
| 549 |
+
let keywordStart = prompt[editStart - 1] === " " ? editStart - 1 : editStart;
|
| 550 |
+
newPrompt = prompt.substring(0, keywordStart) + `, ${keywords} ${insert}` + prompt.substring(editEnd);
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
textAfterKeywordInsertion = newPrompt;
|
| 555 |
+
keywordInsertionUndone = false;
|
| 556 |
+
setTimeout(() => lastEditWasKeywordInsertion = true, 200)
|
| 557 |
+
|
| 558 |
+
keywordsLength = keywords.length + 2; // +2 for the comma and space
|
| 559 |
+
}
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
// Insert into prompt textbox and reposition cursor
|
| 563 |
+
textArea.value = newPrompt;
|
| 564 |
+
textArea.selectionStart = afterInsertCursorPos + optionalSeparator.length + keywordsLength;
|
| 565 |
+
textArea.selectionEnd = textArea.selectionStart
|
| 566 |
+
|
| 567 |
+
// Since we've modified a Gradio Textbox component manually, we need to simulate an `input` DOM event to ensure it's propagated back to python.
|
| 568 |
+
// Uses a built-in method from the webui's ui.js which also already accounts for event target
|
| 569 |
+
tacSelfTrigger = true;
|
| 570 |
+
updateInput(textArea);
|
| 571 |
+
|
| 572 |
+
// Update previous tags with the edited prompt to prevent re-searching the same term
|
| 573 |
+
let weightedTags = [...newPrompt.matchAll(WEIGHT_REGEX)]
|
| 574 |
+
.map(match => match[1]);
|
| 575 |
+
let tags = newPrompt.match(TAG_REGEX)
|
| 576 |
+
if (weightedTags !== null) {
|
| 577 |
+
tags = tags.filter(tag => !weightedTags.some(weighted => tag.includes(weighted)))
|
| 578 |
+
.concat(weightedTags);
|
| 579 |
+
}
|
| 580 |
+
previousTags = tags;
|
| 581 |
+
|
| 582 |
+
// Callback
|
| 583 |
+
let returns = await processQueueReturn(QUEUE_AFTER_INSERT, null, tagType, sanitizedText, newPrompt, textArea);
|
| 584 |
+
// Return if any queue function returned true (has handled hide/show already)
|
| 585 |
+
if (returns.some(x => x === true))
|
| 586 |
+
return;
|
| 587 |
+
|
| 588 |
+
// Hide results after inserting, if it hasn't been hidden already by a queue function
|
| 589 |
+
if (!hideBlocked && isVisible(textArea)) {
|
| 590 |
+
hideResults(textArea);
|
| 591 |
+
}
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
function addResultsToList(textArea, results, tagword, resetList) {
|
| 595 |
+
let textAreaId = getTextAreaIdentifier(textArea);
|
| 596 |
+
let resultDiv = gradioApp().querySelector('.autocompleteResults' + textAreaId);
|
| 597 |
+
let resultsList = resultDiv.querySelector('ul');
|
| 598 |
+
|
| 599 |
+
// Reset list, selection and scrollTop since the list changed
|
| 600 |
+
if (resetList) {
|
| 601 |
+
resultsList.innerHTML = "";
|
| 602 |
+
selectedTag = null;
|
| 603 |
+
oldSelectedTag = null;
|
| 604 |
+
resultDiv.scrollTop = 0;
|
| 605 |
+
resultCount = 0;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
// Find right colors from config
|
| 609 |
+
let tagFileName = TAC_CFG.tagFile.split(".")[0];
|
| 610 |
+
let tagColors = TAC_CFG.colorMap;
|
| 611 |
+
let mode = (document.querySelector(".dark") || gradioApp().querySelector(".dark")) ? 0 : 1;
|
| 612 |
+
let nextLength = Math.min(results.length, resultCount + TAC_CFG.resultStepLength);
|
| 613 |
+
|
| 614 |
+
for (let i = resultCount; i < nextLength; i++) {
|
| 615 |
+
let result = results[i];
|
| 616 |
+
|
| 617 |
+
// Skip if the result is null or undefined
|
| 618 |
+
if (!result)
|
| 619 |
+
continue;
|
| 620 |
+
|
| 621 |
+
let li = document.createElement("li");
|
| 622 |
+
|
| 623 |
+
let flexDiv = document.createElement("div");
|
| 624 |
+
flexDiv.classList.add("resultsFlexContainer");
|
| 625 |
+
li.appendChild(flexDiv);
|
| 626 |
+
|
| 627 |
+
let itemText = document.createElement("div");
|
| 628 |
+
itemText.classList.add("acListItem");
|
| 629 |
+
|
| 630 |
+
let displayText = "";
|
| 631 |
+
// If the tag matches the tagword, we don't need to display the alias
|
| 632 |
+
if(result.type === ResultType.chant) {
|
| 633 |
+
displayText = escapeHTML(result.aliases);
|
| 634 |
+
} else if (result.aliases && !result.text.includes(tagword)) { // Alias
|
| 635 |
+
let splitAliases = result.aliases.split(",");
|
| 636 |
+
let bestAlias = splitAliases.find(a => a.toLowerCase().includes(tagword));
|
| 637 |
+
|
| 638 |
+
// search in translations if no alias matches
|
| 639 |
+
if (!bestAlias) {
|
| 640 |
+
let tagOrAlias = pair => pair[0] === result.text || splitAliases.includes(pair[0]);
|
| 641 |
+
var tArray = [...translations];
|
| 642 |
+
if (tArray) {
|
| 643 |
+
var translationKey = [...translations].find(pair => tagOrAlias(pair) && pair[1].includes(tagword));
|
| 644 |
+
if (translationKey)
|
| 645 |
+
bestAlias = translationKey[0];
|
| 646 |
+
}
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
displayText = escapeHTML(bestAlias);
|
| 650 |
+
|
| 651 |
+
// Append translation for alias if it exists and is not what the user typed
|
| 652 |
+
if (translations.has(bestAlias) && translations.get(bestAlias) !== bestAlias && bestAlias !== result.text)
|
| 653 |
+
displayText += `[${translations.get(bestAlias)}]`;
|
| 654 |
+
|
| 655 |
+
if (!TAC_CFG.alias.onlyShowAlias && result.text !== bestAlias)
|
| 656 |
+
displayText += " ➝ " + result.text;
|
| 657 |
+
} else { // No alias
|
| 658 |
+
displayText = escapeHTML(result.text);
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
// Append translation for result if it exists
|
| 662 |
+
if (translations.has(result.text))
|
| 663 |
+
displayText += `[${translations.get(result.text)}]`;
|
| 664 |
+
|
| 665 |
+
// Print search term bolded in result
|
| 666 |
+
itemText.innerHTML = displayText.replace(tagword, `<b>${tagword}</b>`);
|
| 667 |
+
|
| 668 |
+
const splitTypes = [ResultType.wildcardFile, ResultType.yamlWildcard]
|
| 669 |
+
if (splitTypes.includes(result.type) && itemText.innerHTML.includes("/")) {
|
| 670 |
+
let parts = itemText.innerHTML.split("/");
|
| 671 |
+
let lastPart = parts[parts.length - 1];
|
| 672 |
+
parts = parts.slice(0, parts.length - 1);
|
| 673 |
+
|
| 674 |
+
itemText.innerHTML = "<span class='acPathPart'>" + parts.join("</span><span class='acPathPart'>/") + "</span>" + "/" + lastPart;
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
// Add wiki link if the setting is enabled and a supported tag set loaded
|
| 678 |
+
if (TAC_CFG.showWikiLinks
|
| 679 |
+
&& (result.type === ResultType.tag)
|
| 680 |
+
&& (tagFileName.toLowerCase().startsWith("danbooru") || tagFileName.toLowerCase().startsWith("e621"))) {
|
| 681 |
+
let wikiLink = document.createElement("a");
|
| 682 |
+
wikiLink.classList.add("acWikiLink");
|
| 683 |
+
wikiLink.innerText = "?";
|
| 684 |
+
|
| 685 |
+
let linkPart = displayText;
|
| 686 |
+
// Only use alias result if it is one
|
| 687 |
+
if (displayText.includes("➝"))
|
| 688 |
+
linkPart = displayText.split(" ➝ ")[1];
|
| 689 |
+
|
| 690 |
+
// Remove any trailing translations
|
| 691 |
+
if (linkPart.includes("[")) {
|
| 692 |
+
linkPart = linkPart.split("[")[0]
|
| 693 |
+
}
|
| 694 |
+
|
| 695 |
+
linkPart = encodeURIComponent(linkPart);
|
| 696 |
+
|
| 697 |
+
// Set link based on selected file
|
| 698 |
+
let tagFileNameLower = tagFileName.toLowerCase();
|
| 699 |
+
if (tagFileNameLower.startsWith("danbooru")) {
|
| 700 |
+
wikiLink.href = `https://danbooru.donmai.us/wiki_pages/${linkPart}`;
|
| 701 |
+
} else if (tagFileNameLower.startsWith("e621")) {
|
| 702 |
+
wikiLink.href = `https://e621.net/wiki_pages/${linkPart}`;
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
wikiLink.target = "_blank";
|
| 706 |
+
flexDiv.appendChild(wikiLink);
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
flexDiv.appendChild(itemText);
|
| 710 |
+
|
| 711 |
+
// Add post count & color if it's a tag
|
| 712 |
+
// Wildcards & Embeds have no tag category
|
| 713 |
+
if (result.category) {
|
| 714 |
+
// Set the color of the tag
|
| 715 |
+
let cat = result.category;
|
| 716 |
+
let colorGroup = tagColors[tagFileName];
|
| 717 |
+
// Default to danbooru scheme if no matching one is found
|
| 718 |
+
if (!colorGroup)
|
| 719 |
+
colorGroup = tagColors["danbooru"];
|
| 720 |
+
|
| 721 |
+
// Set tag type to invalid if not found
|
| 722 |
+
if (!colorGroup[cat])
|
| 723 |
+
cat = "-1";
|
| 724 |
+
|
| 725 |
+
flexDiv.style = `color: ${colorGroup[cat][mode]};`;
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
// Post count
|
| 729 |
+
if (result.count && !isNaN(result.count)) {
|
| 730 |
+
let postCount = result.count;
|
| 731 |
+
let formatter;
|
| 732 |
+
|
| 733 |
+
// Danbooru formats numbers with a padded fraction for 1M or 1k, but not for 10/100k
|
| 734 |
+
if (postCount >= 1000000 || (postCount >= 1000 && postCount < 10000))
|
| 735 |
+
formatter = Intl.NumberFormat("en", { notation: "compact", minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
| 736 |
+
else
|
| 737 |
+
formatter = Intl.NumberFormat("en", {notation: "compact"});
|
| 738 |
+
|
| 739 |
+
let formattedCount = formatter.format(postCount);
|
| 740 |
+
|
| 741 |
+
let countDiv = document.createElement("div");
|
| 742 |
+
countDiv.textContent = formattedCount;
|
| 743 |
+
countDiv.classList.add("acMetaText");
|
| 744 |
+
flexDiv.appendChild(countDiv);
|
| 745 |
+
} else if (result.meta) { // Check if there is meta info to display
|
| 746 |
+
let metaDiv = document.createElement("div");
|
| 747 |
+
metaDiv.textContent = result.meta;
|
| 748 |
+
metaDiv.classList.add("acMetaText");
|
| 749 |
+
|
| 750 |
+
// Add version info classes if it is an embedding
|
| 751 |
+
if (result.type === ResultType.embedding) {
|
| 752 |
+
if (result.meta.startsWith("v1"))
|
| 753 |
+
itemText.classList.add("acEmbeddingV1");
|
| 754 |
+
else if (result.meta.startsWith("v2"))
|
| 755 |
+
itemText.classList.add("acEmbeddingV2");
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
flexDiv.appendChild(metaDiv);
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
// Add listener
|
| 762 |
+
li.addEventListener("click", function () { insertTextAtCursor(textArea, result, tagword); });
|
| 763 |
+
// Add element to list
|
| 764 |
+
resultsList.appendChild(li);
|
| 765 |
+
}
|
| 766 |
+
resultCount = nextLength;
|
| 767 |
+
|
| 768 |
+
if (resetList) {
|
| 769 |
+
selectedTag = null;
|
| 770 |
+
oldSelectedTag = null;
|
| 771 |
+
resultDiv.scrollTop = 0;
|
| 772 |
+
}
|
| 773 |
+
}
|
| 774 |
+
|
| 775 |
+
async function updateSelectionStyle(textArea, newIndex, oldIndex) {
|
| 776 |
+
let textAreaId = getTextAreaIdentifier(textArea);
|
| 777 |
+
let resultDiv = gradioApp().querySelector('.autocompleteResults' + textAreaId);
|
| 778 |
+
let resultsList = resultDiv.querySelector('ul');
|
| 779 |
+
let items = resultsList.getElementsByTagName('li');
|
| 780 |
+
|
| 781 |
+
if (oldIndex != null) {
|
| 782 |
+
items[oldIndex].classList.remove('selected');
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
// make it safer
|
| 786 |
+
if (newIndex !== null) {
|
| 787 |
+
let selected = items[newIndex];
|
| 788 |
+
selected.classList.add('selected');
|
| 789 |
+
|
| 790 |
+
// Set scrolltop to selected item
|
| 791 |
+
resultDiv.scrollTop = selected.offsetTop - resultDiv.offsetTop;
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
// Show preview if enabled and the selected type supports it
|
| 795 |
+
if (newIndex !== null) {
|
| 796 |
+
let selected = items[newIndex];
|
| 797 |
+
let previewTypes = ["v1 Embedding", "v2 Embedding", "Hypernetwork", "Lora", "Lyco"];
|
| 798 |
+
let selectedType = selected.querySelector(".acMetaText").innerText;
|
| 799 |
+
let selectedFilename = selected.querySelector(".acListItem").innerText;
|
| 800 |
+
|
| 801 |
+
let previewDiv = gradioApp().querySelector(`.autocompleteParent${textAreaId} .sideInfo`);
|
| 802 |
+
|
| 803 |
+
if (TAC_CFG.showExtraNetworkPreviews && previewTypes.includes(selectedType)) {
|
| 804 |
+
let shorthandType = "";
|
| 805 |
+
switch (selectedType) {
|
| 806 |
+
case "v1 Embedding":
|
| 807 |
+
case "v2 Embedding":
|
| 808 |
+
shorthandType = "embed";
|
| 809 |
+
break;
|
| 810 |
+
case "Hypernetwork":
|
| 811 |
+
shorthandType = "hyper";
|
| 812 |
+
break;
|
| 813 |
+
case "Lora":
|
| 814 |
+
shorthandType = "lora";
|
| 815 |
+
break;
|
| 816 |
+
case "Lyco":
|
| 817 |
+
shorthandType = "lyco";
|
| 818 |
+
break;
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
let img = previewDiv.querySelector("img");
|
| 822 |
+
|
| 823 |
+
let url = await getExtraNetworkPreviewURL(selectedFilename, shorthandType);
|
| 824 |
+
if (url) {
|
| 825 |
+
img.src = url;
|
| 826 |
+
previewDiv.style.display = "block";
|
| 827 |
+
} else {
|
| 828 |
+
previewDiv.style.display = "none";
|
| 829 |
+
}
|
| 830 |
+
} else {
|
| 831 |
+
previewDiv.style.display = "none";
|
| 832 |
+
}
|
| 833 |
+
}
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
function updateRuby(textArea, prompt) {
|
| 837 |
+
if (!TAC_CFG.translation.liveTranslation) return;
|
| 838 |
+
if (!TAC_CFG.translation.translationFile || TAC_CFG.translation.translationFile === "None") return;
|
| 839 |
+
|
| 840 |
+
let ruby = gradioApp().querySelector('.acRuby' + getTextAreaIdentifier(textArea));
|
| 841 |
+
if (!ruby) {
|
| 842 |
+
let textAreaId = getTextAreaIdentifier(textArea);
|
| 843 |
+
let typeClass = textAreaId.replaceAll(".", " ");
|
| 844 |
+
ruby = document.createElement("div");
|
| 845 |
+
ruby.setAttribute("class", `acRuby${typeClass} notranslate`);
|
| 846 |
+
textArea.parentNode.appendChild(ruby);
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
ruby.innerText = prompt;
|
| 850 |
+
|
| 851 |
+
let bracketEscapedPrompt = prompt.replaceAll("\\(", "$").replaceAll("\\)", "%");
|
| 852 |
+
|
| 853 |
+
let rubyTags = bracketEscapedPrompt.match(RUBY_TAG_REGEX);
|
| 854 |
+
if (!rubyTags) return;
|
| 855 |
+
|
| 856 |
+
rubyTags.sort((a, b) => b.length - a.length);
|
| 857 |
+
rubyTags = new Set(rubyTags);
|
| 858 |
+
|
| 859 |
+
const prepareTag = (tag) => {
|
| 860 |
+
tag = tag.replaceAll("$", "\\(").replaceAll("%", "\\)");
|
| 861 |
+
|
| 862 |
+
let unsanitizedTag = tag
|
| 863 |
+
.replaceAll(" ", "_")
|
| 864 |
+
.replaceAll("\\(", "(")
|
| 865 |
+
.replaceAll("\\)", ")");
|
| 866 |
+
|
| 867 |
+
const translation = translations?.get(tag) || translations?.get(unsanitizedTag);
|
| 868 |
+
|
| 869 |
+
let escapedTag = escapeRegExp(tag);
|
| 870 |
+
return { tag, escapedTag, translation };
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
const replaceOccurences = (text, tuple) => {
|
| 874 |
+
let { tag, escapedTag, translation } = tuple;
|
| 875 |
+
let searchRegex = new RegExp(`(?<!<ruby>)(?:\\b)${escapedTag}(?:\\b|$|(?=[,|: \\t\\n\\r]))(?!<rt>)`, "g");
|
| 876 |
+
return text.replaceAll(searchRegex, `<ruby>${escapeHTML(tag)}<rt>${translation}</rt></ruby>`);
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
let html = escapeHTML(prompt);
|
| 880 |
+
|
| 881 |
+
// First try to find direct matches
|
| 882 |
+
[...rubyTags].forEach(tag => {
|
| 883 |
+
let tuple = prepareTag(tag);
|
| 884 |
+
|
| 885 |
+
if (tuple.translation) {
|
| 886 |
+
html = replaceOccurences(html, tuple);
|
| 887 |
+
} else {
|
| 888 |
+
let subTags = tuple.tag.split(" ").filter(x => x.trim().length > 0);
|
| 889 |
+
// Return if there is only one word
|
| 890 |
+
if (subTags.length === 1) return;
|
| 891 |
+
|
| 892 |
+
let subHtml = tag.replaceAll("$", "\\(").replaceAll("%", "\\)");
|
| 893 |
+
|
| 894 |
+
let translateNgram = (windows) => {
|
| 895 |
+
windows.forEach(window => {
|
| 896 |
+
let combinedTag = window.join(" ");
|
| 897 |
+
let subTuple = prepareTag(combinedTag);
|
| 898 |
+
|
| 899 |
+
if (subTuple.tag.length <= 2) return;
|
| 900 |
+
|
| 901 |
+
if (subTuple.translation) {
|
| 902 |
+
subHtml = replaceOccurences(subHtml, subTuple);
|
| 903 |
+
}
|
| 904 |
+
});
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
// Perform n-gram sliding window search
|
| 908 |
+
translateNgram(toNgrams(subTags, 3));
|
| 909 |
+
translateNgram(toNgrams(subTags, 2));
|
| 910 |
+
translateNgram(toNgrams(subTags, 1));
|
| 911 |
+
|
| 912 |
+
let escapedTag = escapeRegExp(tuple.tag);
|
| 913 |
+
|
| 914 |
+
let searchRegex = new RegExp(`(?<!<ruby>)(?:\\b)${escapedTag}(?:\\b|$|(?=[,|: \\t\\n\\r]))(?!<rt>)`, "g");
|
| 915 |
+
html = html.replaceAll(searchRegex, subHtml);
|
| 916 |
+
}
|
| 917 |
+
});
|
| 918 |
+
|
| 919 |
+
ruby.innerHTML = html;
|
| 920 |
+
|
| 921 |
+
// Add listeners for auto selection
|
| 922 |
+
const childNodes = [...ruby.childNodes];
|
| 923 |
+
[...ruby.children].forEach(child => {
|
| 924 |
+
const textBefore = childNodes.slice(0, childNodes.indexOf(child)).map(x => x.childNodes[0]?.textContent || x.textContent).join("")
|
| 925 |
+
child.onclick = () => rubyTagClicked(child, textBefore, prompt, textArea);
|
| 926 |
+
});
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
function rubyTagClicked(node, textBefore, prompt, textArea) {
|
| 930 |
+
let selectionText = node.childNodes[0].textContent;
|
| 931 |
+
|
| 932 |
+
// Find start and end position of the tag in the prompt
|
| 933 |
+
let startPos = prompt.indexOf(textBefore) + textBefore.length;
|
| 934 |
+
let endPos = startPos + selectionText.length;
|
| 935 |
+
|
| 936 |
+
// Select in text area
|
| 937 |
+
textArea.focus();
|
| 938 |
+
textArea.setSelectionRange(startPos, endPos);
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
// Check if the last edit was the keyword insertion, and catch undo/redo in that case
|
| 942 |
+
function checkKeywordInsertionUndo(textArea, event) {
|
| 943 |
+
if (TAC_CFG.modelKeywordCompletion === "Never") return;
|
| 944 |
+
|
| 945 |
+
switch (event.inputType) {
|
| 946 |
+
case "historyUndo":
|
| 947 |
+
if (lastEditWasKeywordInsertion && !keywordInsertionUndone) {
|
| 948 |
+
keywordInsertionUndone = true;
|
| 949 |
+
textArea.value = textBeforeKeywordInsertion;
|
| 950 |
+
tacSelfTrigger = true;
|
| 951 |
+
updateInput(textArea);
|
| 952 |
+
}
|
| 953 |
+
break;
|
| 954 |
+
case "historyRedo":
|
| 955 |
+
if (lastEditWasKeywordInsertion && keywordInsertionUndone) {
|
| 956 |
+
keywordInsertionUndone = false;
|
| 957 |
+
textArea.value = textAfterKeywordInsertion;
|
| 958 |
+
tacSelfTrigger = true;
|
| 959 |
+
updateInput(textArea);
|
| 960 |
+
}
|
| 961 |
+
case undefined:
|
| 962 |
+
// undefined is caused by the updateInput event firing, so we just ignore it
|
| 963 |
+
break;
|
| 964 |
+
default:
|
| 965 |
+
// Everything else deactivates the keyword undo and returns to normal undo behavior
|
| 966 |
+
lastEditWasKeywordInsertion = false;
|
| 967 |
+
keywordInsertionUndone = false;
|
| 968 |
+
textBeforeKeywordInsertion = "";
|
| 969 |
+
textAfterKeywordInsertion = "";
|
| 970 |
+
break;
|
| 971 |
+
}
|
| 972 |
+
}
|
| 973 |
+
|
| 974 |
+
async function autocomplete(textArea, prompt, fixedTag = null) {
|
| 975 |
+
// Return if the function is deactivated in the UI
|
| 976 |
+
if (!isEnabled()) return;
|
| 977 |
+
|
| 978 |
+
// Guard for empty prompt
|
| 979 |
+
if (prompt.length === 0) {
|
| 980 |
+
hideResults(textArea);
|
| 981 |
+
previousTags = [];
|
| 982 |
+
tagword = "";
|
| 983 |
+
return;
|
| 984 |
+
}
|
| 985 |
+
|
| 986 |
+
if (fixedTag === null) {
|
| 987 |
+
// Match tags with RegEx to get the last edited one
|
| 988 |
+
// We also match for the weighting format (e.g. "tag:1.0") here, and combine the two to get the full tag word set
|
| 989 |
+
let weightedTags = [...prompt.matchAll(WEIGHT_REGEX)]
|
| 990 |
+
.map(match => match[1]);
|
| 991 |
+
let tags = prompt.match(TAG_REGEX)
|
| 992 |
+
if (weightedTags !== null && tags !== null) {
|
| 993 |
+
tags = tags.filter(tag => !weightedTags.some(weighted => tag.includes(weighted) && !tag.startsWith("<[")))
|
| 994 |
+
.concat(weightedTags);
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
// Guard for no tags
|
| 998 |
+
if (!tags || tags.length === 0) {
|
| 999 |
+
previousTags = [];
|
| 1000 |
+
tagword = "";
|
| 1001 |
+
hideResults(textArea);
|
| 1002 |
+
return;
|
| 1003 |
+
}
|
| 1004 |
+
|
| 1005 |
+
let tagCountChange = tags.length - previousTags.length;
|
| 1006 |
+
let diff = difference(tags, previousTags);
|
| 1007 |
+
previousTags = tags;
|
| 1008 |
+
|
| 1009 |
+
// Guard for no difference / only whitespace remaining / last edited tag was fully removed
|
| 1010 |
+
if (diff === null || diff.length === 0 || (diff.length === 1 && tagCountChange < 0)) {
|
| 1011 |
+
if (!hideBlocked) hideResults(textArea);
|
| 1012 |
+
return;
|
| 1013 |
+
}
|
| 1014 |
+
|
| 1015 |
+
tagword = diff[0]
|
| 1016 |
+
|
| 1017 |
+
// Guard for empty tagword
|
| 1018 |
+
if (tagword === null || tagword.length === 0) {
|
| 1019 |
+
hideResults(textArea);
|
| 1020 |
+
return;
|
| 1021 |
+
}
|
| 1022 |
+
} else {
|
| 1023 |
+
tagword = fixedTag;
|
| 1024 |
+
}
|
| 1025 |
+
|
| 1026 |
+
results = [];
|
| 1027 |
+
resultCountBeforeNormalTags = 0;
|
| 1028 |
+
tagword = tagword.toLowerCase().replace(/[\n\r]/g, "");
|
| 1029 |
+
|
| 1030 |
+
// Process all parsers
|
| 1031 |
+
let resultCandidates = (await processParsers(textArea, prompt))?.filter(x => x.length > 0);
|
| 1032 |
+
// If one ore more result candidates match, use their results
|
| 1033 |
+
if (resultCandidates && resultCandidates.length > 0) {
|
| 1034 |
+
// Flatten our candidate(s)
|
| 1035 |
+
results = resultCandidates.flat();
|
| 1036 |
+
// Sort results, but not if it's umi tags since they are sorted by count
|
| 1037 |
+
if (!(resultCandidates.length === 1 && results[0].type === ResultType.umiWildcard))
|
| 1038 |
+
results = results.sort(getSortFunction());
|
| 1039 |
+
|
| 1040 |
+
// Since some tags are kaomoji, we have to add the normal results in some cases
|
| 1041 |
+
if (tagword.startsWith("<") || tagword.startsWith("*<")) {
|
| 1042 |
+
// Create escaped search regex with support for * as a start placeholder
|
| 1043 |
+
let searchRegex;
|
| 1044 |
+
if (tagword.startsWith("*")) {
|
| 1045 |
+
tagword = tagword.slice(1);
|
| 1046 |
+
searchRegex = new RegExp(`${escapeRegExp(tagword)}`, 'i');
|
| 1047 |
+
} else {
|
| 1048 |
+
searchRegex = new RegExp(`(^|[^a-zA-Z])${escapeRegExp(tagword)}`, 'i');
|
| 1049 |
+
}
|
| 1050 |
+
let genericResults = allTags.filter(x => x[0].toLowerCase().search(searchRegex) > -1).slice(0, TAC_CFG.maxResults);
|
| 1051 |
+
|
| 1052 |
+
genericResults.forEach(g => {
|
| 1053 |
+
let result = new AutocompleteResult(g[0].trim(), ResultType.tag)
|
| 1054 |
+
result.category = g[1];
|
| 1055 |
+
result.count = g[2];
|
| 1056 |
+
result.aliases = g[3];
|
| 1057 |
+
results.push(result);
|
| 1058 |
+
});
|
| 1059 |
+
}
|
| 1060 |
+
}
|
| 1061 |
+
// Else search the normal tag list
|
| 1062 |
+
if (!resultCandidates || resultCandidates.length === 0
|
| 1063 |
+
|| (TAC_CFG.includeEmbeddingsInNormalResults && !(tagword.startsWith("<") || tagword.startsWith("*<")))
|
| 1064 |
+
) {
|
| 1065 |
+
resultCountBeforeNormalTags = results.length;
|
| 1066 |
+
|
| 1067 |
+
// Create escaped search regex with support for * as a start placeholder
|
| 1068 |
+
let searchRegex;
|
| 1069 |
+
if (tagword.startsWith("*")) {
|
| 1070 |
+
tagword = tagword.slice(1);
|
| 1071 |
+
searchRegex = new RegExp(`${escapeRegExp(tagword)}`, 'i');
|
| 1072 |
+
} else {
|
| 1073 |
+
searchRegex = new RegExp(`(^|[^a-zA-Z])${escapeRegExp(tagword)}`, 'i');
|
| 1074 |
+
}
|
| 1075 |
+
|
| 1076 |
+
// Both normal tags and aliases/translations are included depending on the config
|
| 1077 |
+
let baseFilter = (x) => x[0].toLowerCase().search(searchRegex) > -1;
|
| 1078 |
+
let aliasFilter = (x) => x[3] && x[3].toLowerCase().search(searchRegex) > -1;
|
| 1079 |
+
let translationFilter = (x) => (translations.has(x[0]) && translations.get(x[0]).toLowerCase().search(searchRegex) > -1)
|
| 1080 |
+
|| x[3] && x[3].split(",").some(y => translations.has(y) && translations.get(y).toLowerCase().search(searchRegex) > -1);
|
| 1081 |
+
|
| 1082 |
+
let fil;
|
| 1083 |
+
if (TAC_CFG.alias.searchByAlias && TAC_CFG.translation.searchByTranslation)
|
| 1084 |
+
fil = (x) => baseFilter(x) || aliasFilter(x) || translationFilter(x);
|
| 1085 |
+
else if (TAC_CFG.alias.searchByAlias && !TAC_CFG.translation.searchByTranslation)
|
| 1086 |
+
fil = (x) => baseFilter(x) || aliasFilter(x);
|
| 1087 |
+
else if (TAC_CFG.translation.searchByTranslation && !TAC_CFG.alias.searchByAlias)
|
| 1088 |
+
fil = (x) => baseFilter(x) || translationFilter(x);
|
| 1089 |
+
else
|
| 1090 |
+
fil = (x) => baseFilter(x);
|
| 1091 |
+
|
| 1092 |
+
// Add final results
|
| 1093 |
+
allTags.filter(fil).forEach(t => {
|
| 1094 |
+
let result = new AutocompleteResult(t[0].trim(), ResultType.tag)
|
| 1095 |
+
result.category = t[1];
|
| 1096 |
+
result.count = t[2];
|
| 1097 |
+
result.aliases = t[3];
|
| 1098 |
+
results.push(result);
|
| 1099 |
+
});
|
| 1100 |
+
|
| 1101 |
+
// Add extras
|
| 1102 |
+
if (TAC_CFG.extra.extraFile) {
|
| 1103 |
+
let extraResults = [];
|
| 1104 |
+
|
| 1105 |
+
extras.filter(fil).forEach(e => {
|
| 1106 |
+
let result = new AutocompleteResult(e[0].trim(), ResultType.extra)
|
| 1107 |
+
result.category = e[1] || 0; // If no category is given, use 0 as the default
|
| 1108 |
+
result.meta = e[2] || "Custom tag";
|
| 1109 |
+
result.aliases = e[3] || "";
|
| 1110 |
+
extraResults.push(result);
|
| 1111 |
+
});
|
| 1112 |
+
|
| 1113 |
+
if (TAC_CFG.extra.addMode === "Insert before") {
|
| 1114 |
+
results = extraResults.concat(results);
|
| 1115 |
+
} else {
|
| 1116 |
+
results = results.concat(extraResults);
|
| 1117 |
+
}
|
| 1118 |
+
}
|
| 1119 |
+
|
| 1120 |
+
// Slice if the user has set a max result count
|
| 1121 |
+
if (!TAC_CFG.showAllResults) {
|
| 1122 |
+
results = results.slice(0, TAC_CFG.maxResults + resultCountBeforeNormalTags);
|
| 1123 |
+
}
|
| 1124 |
+
}
|
| 1125 |
+
|
| 1126 |
+
// Guard for empty results
|
| 1127 |
+
if (!results || results.length === 0) {
|
| 1128 |
+
//console.log('No results found for "' + tagword + '"');
|
| 1129 |
+
hideResults(textArea);
|
| 1130 |
+
return;
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
addResultsToList(textArea, results, tagword, true);
|
| 1134 |
+
showResults(textArea);
|
| 1135 |
+
}
|
| 1136 |
+
|
| 1137 |
+
function navigateInList(textArea, event) {
|
| 1138 |
+
// Return if the function is deactivated in the UI or the current model is excluded due to white/blacklist settings
|
| 1139 |
+
if (!isEnabled()) return;
|
| 1140 |
+
|
| 1141 |
+
let keys = TAC_CFG.keymap;
|
| 1142 |
+
|
| 1143 |
+
// Close window if Home or End is pressed while not a keybinding, since it would break completion on leaving the original tag
|
| 1144 |
+
if ((event.key === "Home" || event.key === "End") && !Object.values(keys).includes(event.key)) {
|
| 1145 |
+
hideResults(textArea);
|
| 1146 |
+
return;
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
// All set keys that are not None or empty are valid
|
| 1150 |
+
// Default keys are: ArrowUp, ArrowDown, PageUp, PageDown, Home, End, Enter, Tab, Escape
|
| 1151 |
+
validKeys = Object.values(keys).filter(x => x !== "None" && x !== "");
|
| 1152 |
+
|
| 1153 |
+
if (!validKeys.includes(event.key)) return;
|
| 1154 |
+
if (!isVisible(textArea)) return
|
| 1155 |
+
// Return if ctrl key is pressed to not interfere with weight editing shortcut
|
| 1156 |
+
if (event.ctrlKey || event.altKey || event.shiftKey || event.metaKey) return;
|
| 1157 |
+
|
| 1158 |
+
oldSelectedTag = selectedTag;
|
| 1159 |
+
|
| 1160 |
+
switch (event.key) {
|
| 1161 |
+
case keys["MoveUp"]:
|
| 1162 |
+
if (selectedTag === null) {
|
| 1163 |
+
selectedTag = resultCount - 1;
|
| 1164 |
+
} else {
|
| 1165 |
+
selectedTag = (selectedTag - 1 + resultCount) % resultCount;
|
| 1166 |
+
}
|
| 1167 |
+
break;
|
| 1168 |
+
case keys["MoveDown"]:
|
| 1169 |
+
if (selectedTag === null) {
|
| 1170 |
+
selectedTag = 0;
|
| 1171 |
+
} else {
|
| 1172 |
+
selectedTag = (selectedTag + 1) % resultCount;
|
| 1173 |
+
}
|
| 1174 |
+
break;
|
| 1175 |
+
case keys["JumpUp"]:
|
| 1176 |
+
if (selectedTag === null || selectedTag === 0) {
|
| 1177 |
+
selectedTag = resultCount - 1;
|
| 1178 |
+
} else {
|
| 1179 |
+
selectedTag = (Math.max(selectedTag - 5, 0) + resultCount) % resultCount;
|
| 1180 |
+
}
|
| 1181 |
+
break;
|
| 1182 |
+
case keys["JumpDown"]:
|
| 1183 |
+
if (selectedTag === null || selectedTag === resultCount - 1) {
|
| 1184 |
+
selectedTag = 0;
|
| 1185 |
+
} else {
|
| 1186 |
+
selectedTag = Math.min(selectedTag + 5, resultCount - 1) % resultCount;
|
| 1187 |
+
}
|
| 1188 |
+
break;
|
| 1189 |
+
case keys["JumpToStart"]:
|
| 1190 |
+
if (TAC_CFG.includeEmbeddingsInNormalResults &&
|
| 1191 |
+
selectedTag > resultCountBeforeNormalTags &&
|
| 1192 |
+
resultCountBeforeNormalTags > 0
|
| 1193 |
+
) {
|
| 1194 |
+
selectedTag = resultCountBeforeNormalTags;
|
| 1195 |
+
} else {
|
| 1196 |
+
selectedTag = 0;
|
| 1197 |
+
}
|
| 1198 |
+
break;
|
| 1199 |
+
case keys["JumpToEnd"]:
|
| 1200 |
+
// Jump to the end of the list, or the end of embeddings if they are included in the normal results
|
| 1201 |
+
if (TAC_CFG.includeEmbeddingsInNormalResults &&
|
| 1202 |
+
selectedTag < resultCountBeforeNormalTags &&
|
| 1203 |
+
resultCountBeforeNormalTags > 0
|
| 1204 |
+
) {
|
| 1205 |
+
selectedTag = Math.min(resultCountBeforeNormalTags, resultCount - 1);
|
| 1206 |
+
} else {
|
| 1207 |
+
selectedTag = resultCount - 1;
|
| 1208 |
+
}
|
| 1209 |
+
break;
|
| 1210 |
+
case keys["ChooseSelected"]:
|
| 1211 |
+
if (selectedTag !== null) {
|
| 1212 |
+
insertTextAtCursor(textArea, results[selectedTag], tagword);
|
| 1213 |
+
} else {
|
| 1214 |
+
hideResults(textArea);
|
| 1215 |
+
return;
|
| 1216 |
+
}
|
| 1217 |
+
break;
|
| 1218 |
+
case keys["ChooseFirstOrSelected"]:
|
| 1219 |
+
let withoutChoice = false;
|
| 1220 |
+
if (selectedTag === null) {
|
| 1221 |
+
selectedTag = 0;
|
| 1222 |
+
withoutChoice = true;
|
| 1223 |
+
} else if (TAC_CFG.wildcardCompletionMode === "To next folder level") {
|
| 1224 |
+
withoutChoice = true;
|
| 1225 |
+
}
|
| 1226 |
+
insertTextAtCursor(textArea, results[selectedTag], tagword, withoutChoice);
|
| 1227 |
+
break;
|
| 1228 |
+
case keys["Close"]:
|
| 1229 |
+
hideResults(textArea);
|
| 1230 |
+
break;
|
| 1231 |
+
}
|
| 1232 |
+
let moveKeys = [keys["MoveUp"], keys["MoveDown"], keys["JumpUp"], keys["JumpDown"], keys["JumpToStart"], keys["JumpToEnd"]];
|
| 1233 |
+
if (selectedTag === resultCount - 1 && moveKeys.includes(event.key)) {
|
| 1234 |
+
addResultsToList(textArea, results, tagword, false);
|
| 1235 |
+
}
|
| 1236 |
+
// Update highlighting
|
| 1237 |
+
if (selectedTag !== null)
|
| 1238 |
+
updateSelectionStyle(textArea, selectedTag, oldSelectedTag);
|
| 1239 |
+
|
| 1240 |
+
// Prevent default behavior
|
| 1241 |
+
event.preventDefault();
|
| 1242 |
+
event.stopPropagation();
|
| 1243 |
+
}
|
| 1244 |
+
|
| 1245 |
+
async function refreshTacTempFiles(api = false) {
|
| 1246 |
+
const reload = async () => {
|
| 1247 |
+
wildcardFiles = [];
|
| 1248 |
+
wildcardExtFiles = [];
|
| 1249 |
+
umiWildcards = [];
|
| 1250 |
+
embeddings = [];
|
| 1251 |
+
hypernetworks = [];
|
| 1252 |
+
loras = [];
|
| 1253 |
+
lycos = [];
|
| 1254 |
+
modelKeywordDict.clear();
|
| 1255 |
+
await processQueue(QUEUE_FILE_LOAD, null);
|
| 1256 |
+
|
| 1257 |
+
console.log("TAC: Refreshed temp files");
|
| 1258 |
+
}
|
| 1259 |
+
|
| 1260 |
+
if (api) {
|
| 1261 |
+
await postAPI("tacapi/v1/refresh-temp-files", null);
|
| 1262 |
+
await reload();
|
| 1263 |
+
} else {
|
| 1264 |
+
setTimeout(async () => {
|
| 1265 |
+
await reload();
|
| 1266 |
+
}, 2000);
|
| 1267 |
+
}
|
| 1268 |
+
}
|
| 1269 |
+
|
| 1270 |
+
function addAutocompleteToArea(area) {
|
| 1271 |
+
// Return if autocomplete is disabled for the current area type in config
|
| 1272 |
+
let textAreaId = getTextAreaIdentifier(area);
|
| 1273 |
+
if ((!TAC_CFG.activeIn.img2img && textAreaId.includes("img2img"))
|
| 1274 |
+
|| (!TAC_CFG.activeIn.txt2img && textAreaId.includes("txt2img"))
|
| 1275 |
+
|| (!TAC_CFG.activeIn.negativePrompts && textAreaId.includes("n"))
|
| 1276 |
+
|| (!TAC_CFG.activeIn.thirdParty && textAreaId.includes("thirdParty"))) {
|
| 1277 |
+
return;
|
| 1278 |
+
}
|
| 1279 |
+
|
| 1280 |
+
// Only add listeners once
|
| 1281 |
+
if (!area.classList.contains('autocomplete')) {
|
| 1282 |
+
// Add our new element
|
| 1283 |
+
var resultsDiv = createResultsDiv(area);
|
| 1284 |
+
area.parentNode.insertBefore(resultsDiv, area.nextSibling);
|
| 1285 |
+
// Hide by default so it doesn't show up on page load
|
| 1286 |
+
hideResults(area);
|
| 1287 |
+
|
| 1288 |
+
// Add autocomplete event listener
|
| 1289 |
+
area.addEventListener('input', (e) => {
|
| 1290 |
+
updateRuby(area, area.value);
|
| 1291 |
+
|
| 1292 |
+
// Cancel autocomplete itself if the event has no inputType (e.g. because it was triggered by the updateInput() function)
|
| 1293 |
+
if (!e.inputType && !tacSelfTrigger) return;
|
| 1294 |
+
tacSelfTrigger = false;
|
| 1295 |
+
|
| 1296 |
+
debounce(autocomplete(area, area.value), TAC_CFG.delayTime);
|
| 1297 |
+
checkKeywordInsertionUndo(area, e);
|
| 1298 |
+
});
|
| 1299 |
+
// Add focusout event listener
|
| 1300 |
+
area.addEventListener('focusout', debounce(() => {
|
| 1301 |
+
if (!hideBlocked)
|
| 1302 |
+
hideResults(area);
|
| 1303 |
+
}, 400));
|
| 1304 |
+
// Add up and down arrow event listener
|
| 1305 |
+
area.addEventListener('keydown', (e) => navigateInList(area, e));
|
| 1306 |
+
// CompositionEnd fires after the user has finished IME composing
|
| 1307 |
+
// We need to block hide here to prevent the enter key from insta-closing the results
|
| 1308 |
+
area.addEventListener('compositionend', () => {
|
| 1309 |
+
hideBlocked = true;
|
| 1310 |
+
setTimeout(() => { hideBlocked = false; }, 100);
|
| 1311 |
+
});
|
| 1312 |
+
|
| 1313 |
+
// Add class so we know we've already added the listeners
|
| 1314 |
+
area.classList.add('autocomplete');
|
| 1315 |
+
}
|
| 1316 |
+
}
|
| 1317 |
+
|
| 1318 |
+
// One-time setup, triggered from onUiUpdate
|
| 1319 |
+
async function setup() {
|
| 1320 |
+
// Load external files needed by completion extensions
|
| 1321 |
+
await processQueue(QUEUE_FILE_LOAD, null);
|
| 1322 |
+
|
| 1323 |
+
// Find all textareas
|
| 1324 |
+
let textAreas = getTextAreas();
|
| 1325 |
+
|
| 1326 |
+
// Add mutation observer to accordions inside a base that has onDemand set to true
|
| 1327 |
+
addOnDemandObservers(addAutocompleteToArea);
|
| 1328 |
+
|
| 1329 |
+
// Add event listener to apply settings button so we can mirror the changes to our internal config
|
| 1330 |
+
let applySettingsButton = gradioApp().querySelector("#tab_settings #settings_submit") || gradioApp().querySelector("#tab_settings > div > .gr-button-primary");
|
| 1331 |
+
applySettingsButton?.addEventListener("click", () => {
|
| 1332 |
+
// Wait 500ms to make sure the settings have been applied to the webui opts object
|
| 1333 |
+
setTimeout(async () => {
|
| 1334 |
+
await syncOptions();
|
| 1335 |
+
}, 500);
|
| 1336 |
+
});
|
| 1337 |
+
// Add change listener to our quicksettings to change our internal config without the apply button for them
|
| 1338 |
+
let quicksettings = gradioApp().querySelector('#quicksettings');
|
| 1339 |
+
let commonQueryPart = "[id^=setting_tac] > label";
|
| 1340 |
+
quicksettings?.querySelectorAll(`${commonQueryPart} input, ${commonQueryPart} textarea, ${commonQueryPart} select`).forEach(e => {
|
| 1341 |
+
e.addEventListener("change", () => {
|
| 1342 |
+
setTimeout(async () => {
|
| 1343 |
+
await syncOptions();
|
| 1344 |
+
}, 500);
|
| 1345 |
+
});
|
| 1346 |
+
});
|
| 1347 |
+
quicksettings?.querySelectorAll(`[id^=setting_tac].gradio-dropdown input`).forEach(e => {
|
| 1348 |
+
observeElement(e, "value", () => {
|
| 1349 |
+
setTimeout(async () => {
|
| 1350 |
+
await syncOptions();
|
| 1351 |
+
}, 500);
|
| 1352 |
+
})
|
| 1353 |
+
});
|
| 1354 |
+
// Listener for internal temp files refresh button
|
| 1355 |
+
gradioApp().querySelector("#refresh_tac_refreshTempFiles")?.addEventListener("click", refreshTacTempFiles);
|
| 1356 |
+
|
| 1357 |
+
// Also add listener for external network refresh button (plus triggering python code)
|
| 1358 |
+
["#img2img_extra_refresh", "#txt2img_extra_refresh"].forEach(e => {
|
| 1359 |
+
gradioApp().querySelector(e)?.addEventListener("click", ()=>{
|
| 1360 |
+
refreshTacTempFiles(true);
|
| 1361 |
+
});
|
| 1362 |
+
})
|
| 1363 |
+
|
| 1364 |
+
// Add mutation observer for the model hash text to also allow hash-based blacklist again
|
| 1365 |
+
let modelHashText = gradioApp().querySelector("#sd_checkpoint_hash");
|
| 1366 |
+
updateModelName();
|
| 1367 |
+
if (modelHashText) {
|
| 1368 |
+
currentModelHash = modelHashText.title
|
| 1369 |
+
let modelHashObserver = new MutationObserver((mutationList, observer) => {
|
| 1370 |
+
for (const mutation of mutationList) {
|
| 1371 |
+
if (mutation.type === "attributes" && mutation.attributeName === "title") {
|
| 1372 |
+
currentModelHash = mutation.target.title;
|
| 1373 |
+
updateModelName();
|
| 1374 |
+
}
|
| 1375 |
+
}
|
| 1376 |
+
});
|
| 1377 |
+
modelHashObserver.observe(modelHashText, { attributes: true });
|
| 1378 |
+
}
|
| 1379 |
+
|
| 1380 |
+
// Not found, we're on a page without prompt textareas
|
| 1381 |
+
if (textAreas.every(v => v === null || v === undefined)) return;
|
| 1382 |
+
// Already added or unnecessary to add
|
| 1383 |
+
if (gradioApp().querySelector('.autocompleteParent.p')) {
|
| 1384 |
+
if (gradioApp().querySelector('.autocompleteParent.n') || !TAC_CFG.activeIn.negativePrompts) {
|
| 1385 |
+
return;
|
| 1386 |
+
}
|
| 1387 |
+
} else if (!TAC_CFG.activeIn.txt2img && !TAC_CFG.activeIn.img2img) {
|
| 1388 |
+
return;
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
+
textAreas.forEach(area => addAutocompleteToArea(area));
|
| 1392 |
+
|
| 1393 |
+
// Add style to dom
|
| 1394 |
+
let acStyle = document.createElement('style');
|
| 1395 |
+
let mode = (document.querySelector(".dark") || gradioApp().querySelector(".dark")) ? 0 : 1;
|
| 1396 |
+
// Check if we are on webkit
|
| 1397 |
+
let browser = navigator.userAgent.toLowerCase().indexOf('firefox') > -1 ? "firefox" : "other";
|
| 1398 |
+
|
| 1399 |
+
let css = autocompleteCSS;
|
| 1400 |
+
// Replace vars with actual values (can't use actual css vars because of the way we inject the css)
|
| 1401 |
+
Object.keys(styleColors).forEach((key) => {
|
| 1402 |
+
css = css.replaceAll(`var(${key})`, styleColors[key][mode]);
|
| 1403 |
+
})
|
| 1404 |
+
Object.keys(browserVars).forEach((key) => {
|
| 1405 |
+
css = css.replaceAll(`var(${key})`, browserVars[key][browser]);
|
| 1406 |
+
})
|
| 1407 |
+
|
| 1408 |
+
if (acStyle.styleSheet) {
|
| 1409 |
+
acStyle.styleSheet.cssText = css;
|
| 1410 |
+
} else {
|
| 1411 |
+
acStyle.appendChild(document.createTextNode(css));
|
| 1412 |
+
}
|
| 1413 |
+
gradioApp().appendChild(acStyle);
|
| 1414 |
+
|
| 1415 |
+
// Callback
|
| 1416 |
+
await processQueue(QUEUE_AFTER_SETUP, null);
|
| 1417 |
+
}
|
| 1418 |
+
var tacLoading = false;
|
| 1419 |
+
onUiUpdate(async () => {
|
| 1420 |
+
if (tacLoading) return;
|
| 1421 |
+
if (Object.keys(opts).length === 0) return;
|
| 1422 |
+
if (TAC_CFG) return;
|
| 1423 |
+
tacLoading = true;
|
| 1424 |
+
// Get our tag base path from the temp file
|
| 1425 |
+
tagBasePath = await readFile(`tmp/tagAutocompletePath.txt`);
|
| 1426 |
+
// Load config from webui opts
|
| 1427 |
+
await syncOptions();
|
| 1428 |
+
// Rest of setup
|
| 1429 |
+
setup();
|
| 1430 |
+
tacLoading = false;
|
| 1431 |
+
});
|
a1111-sd-webui-tagcomplete-main/scripts/__pycache__/model_keyword_support.cpython-310.pyc
ADDED
|
Binary file (2.46 kB). View file
|
|
|
a1111-sd-webui-tagcomplete-main/scripts/__pycache__/shared_paths.cpython-310.pyc
ADDED
|
Binary file (1.65 kB). View file
|
|
|
a1111-sd-webui-tagcomplete-main/scripts/__pycache__/tag_autocomplete_helper.cpython-310.pyc
ADDED
|
Binary file (23.8 kB). View file
|
|
|
a1111-sd-webui-tagcomplete-main/scripts/model_keyword_support.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file provides support for the model-keyword extension to add known lora keywords on completion
|
| 2 |
+
|
| 3 |
+
import csv
|
| 4 |
+
import hashlib
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from scripts.shared_paths import EXT_PATH, STATIC_TEMP_PATH, TEMP_PATH
|
| 8 |
+
|
| 9 |
+
# Set up our hash cache
|
| 10 |
+
known_hashes_file = TEMP_PATH.joinpath("known_lora_hashes.txt")
|
| 11 |
+
known_hashes_file.touch()
|
| 12 |
+
file_needs_update = False
|
| 13 |
+
|
| 14 |
+
# Load the hashes from the file
|
| 15 |
+
hash_dict = {}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def load_hash_cache():
|
| 19 |
+
with open(known_hashes_file, "r", encoding="utf-8") as file:
|
| 20 |
+
reader = csv.reader(
|
| 21 |
+
file.readlines(), delimiter=",", quotechar='"', skipinitialspace=True
|
| 22 |
+
)
|
| 23 |
+
for line in reader:
|
| 24 |
+
name, hash, mtime = line
|
| 25 |
+
hash_dict[name] = (hash, mtime)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def update_hash_cache():
|
| 29 |
+
global file_needs_update
|
| 30 |
+
if file_needs_update:
|
| 31 |
+
with open(known_hashes_file, "w", encoding="utf-8", newline='') as file:
|
| 32 |
+
writer = csv.writer(file)
|
| 33 |
+
for name, (hash, mtime) in hash_dict.items():
|
| 34 |
+
writer.writerow([name, hash, mtime])
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# Copy of the fast inaccurate hash function from the extension
|
| 38 |
+
# with some modifications to load from and write to the cache
|
| 39 |
+
def get_lora_simple_hash(path):
|
| 40 |
+
global file_needs_update
|
| 41 |
+
mtime = str(Path(path).stat().st_mtime)
|
| 42 |
+
filename = Path(path).name
|
| 43 |
+
|
| 44 |
+
if filename in hash_dict:
|
| 45 |
+
(hash, old_mtime) = hash_dict[filename]
|
| 46 |
+
if mtime == old_mtime:
|
| 47 |
+
return hash
|
| 48 |
+
try:
|
| 49 |
+
with open(path, "rb") as file:
|
| 50 |
+
m = hashlib.sha256()
|
| 51 |
+
|
| 52 |
+
file.seek(0x100000)
|
| 53 |
+
m.update(file.read(0x10000))
|
| 54 |
+
hash = m.hexdigest()[0:8]
|
| 55 |
+
|
| 56 |
+
hash_dict[filename] = (hash, mtime)
|
| 57 |
+
file_needs_update = True
|
| 58 |
+
|
| 59 |
+
return hash
|
| 60 |
+
except FileNotFoundError:
|
| 61 |
+
return "NOFILE"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# Find the path of the original model-keyword extension
|
| 65 |
+
def write_model_keyword_path():
|
| 66 |
+
# Ensure the file exists even if the extension is not installed
|
| 67 |
+
mk_path = STATIC_TEMP_PATH.joinpath("modelKeywordPath.txt")
|
| 68 |
+
mk_path.write_text("")
|
| 69 |
+
|
| 70 |
+
base_keywords = list(EXT_PATH.glob("*/lora-keyword.txt"))
|
| 71 |
+
custom_keywords = list(EXT_PATH.glob("*/lora-keyword-user.txt"))
|
| 72 |
+
custom_found = custom_keywords is not None and len(custom_keywords) > 0
|
| 73 |
+
if base_keywords is not None and len(base_keywords) > 0:
|
| 74 |
+
with open(mk_path, "w", encoding="utf-8") as f:
|
| 75 |
+
f.write(f"{base_keywords[0].parent.as_posix()},{custom_found}")
|
| 76 |
+
return True
|
| 77 |
+
else:
|
| 78 |
+
print(
|
| 79 |
+
"Tag Autocomplete: Could not locate model-keyword extension, Lora trigger word completion will be limited to those added through the extra networks menu."
|
| 80 |
+
)
|
| 81 |
+
return False
|
a1111-sd-webui-tagcomplete-main/scripts/shared_paths.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
from modules import scripts, shared
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
from modules.paths import extensions_dir, script_path
|
| 7 |
+
|
| 8 |
+
# Webui root path
|
| 9 |
+
FILE_DIR = Path(script_path)
|
| 10 |
+
|
| 11 |
+
# The extension base path
|
| 12 |
+
EXT_PATH = Path(extensions_dir)
|
| 13 |
+
except ImportError:
|
| 14 |
+
# Webui root path
|
| 15 |
+
FILE_DIR = Path().absolute()
|
| 16 |
+
# The extension base path
|
| 17 |
+
EXT_PATH = FILE_DIR.joinpath("extensions")
|
| 18 |
+
|
| 19 |
+
# Tags base path
|
| 20 |
+
TAGS_PATH = Path(scripts.basedir()).joinpath("tags")
|
| 21 |
+
|
| 22 |
+
# The path to the folder containing the wildcards and embeddings
|
| 23 |
+
WILDCARD_PATH = FILE_DIR.joinpath("scripts/wildcards")
|
| 24 |
+
EMB_PATH = Path(shared.cmd_opts.embeddings_dir)
|
| 25 |
+
HYP_PATH = Path(shared.cmd_opts.hypernetwork_dir)
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
LORA_PATH = Path(shared.cmd_opts.lora_dir)
|
| 29 |
+
except AttributeError:
|
| 30 |
+
LORA_PATH = None
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
LYCO_PATH = Path(shared.cmd_opts.lyco_dir_backcompat)
|
| 34 |
+
except AttributeError:
|
| 35 |
+
LYCO_PATH = None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def find_ext_wildcard_paths():
|
| 39 |
+
"""Returns the path to the extension wildcards folder"""
|
| 40 |
+
found = list(EXT_PATH.glob("*/wildcards/"))
|
| 41 |
+
# Try to find the wildcard path from the shared opts
|
| 42 |
+
try:
|
| 43 |
+
from modules.shared import opts
|
| 44 |
+
except ImportError: # likely not in an a1111 context
|
| 45 |
+
opts = None
|
| 46 |
+
|
| 47 |
+
# Append custom wildcard paths
|
| 48 |
+
custom_paths = [
|
| 49 |
+
getattr(shared.cmd_opts, "wildcards_dir", None), # Cmd arg from the wildcard extension
|
| 50 |
+
getattr(opts, "wildcard_dir", None), # Custom path from sd-dynamic-prompts
|
| 51 |
+
]
|
| 52 |
+
for path in [Path(p) for p in custom_paths if p is not None]:
|
| 53 |
+
if path.exists():
|
| 54 |
+
found.append(path)
|
| 55 |
+
|
| 56 |
+
return found
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# The path to the extension wildcards folder
|
| 60 |
+
WILDCARD_EXT_PATHS = find_ext_wildcard_paths()
|
| 61 |
+
|
| 62 |
+
# The path to the temporary files
|
| 63 |
+
# In the webui root, on windows it exists by default, on linux it doesn't
|
| 64 |
+
STATIC_TEMP_PATH = FILE_DIR.joinpath("tmp")
|
| 65 |
+
TEMP_PATH = TAGS_PATH.joinpath("temp") # Extension specific temp files
|
| 66 |
+
|
| 67 |
+
# Make sure these folders exist
|
| 68 |
+
if not TEMP_PATH.exists():
|
| 69 |
+
TEMP_PATH.mkdir()
|
| 70 |
+
if not STATIC_TEMP_PATH.exists():
|
| 71 |
+
STATIC_TEMP_PATH.mkdir()
|
a1111-sd-webui-tagcomplete-main/scripts/tag_autocomplete_helper.py
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This helper script scans folders for wildcards and embeddings and writes them
|
| 2 |
+
# to a temporary file to expose it to the javascript side
|
| 3 |
+
|
| 4 |
+
import glob
|
| 5 |
+
import json
|
| 6 |
+
import urllib.parse
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import gradio as gr
|
| 10 |
+
import yaml
|
| 11 |
+
from fastapi import FastAPI
|
| 12 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 13 |
+
from modules import script_callbacks, sd_hijack, shared, hashes
|
| 14 |
+
|
| 15 |
+
from scripts.model_keyword_support import (get_lora_simple_hash,
|
| 16 |
+
load_hash_cache, update_hash_cache,
|
| 17 |
+
write_model_keyword_path)
|
| 18 |
+
from scripts.shared_paths import *
|
| 19 |
+
|
| 20 |
+
# Attempt to get embedding load function, using the same call as api.
|
| 21 |
+
try:
|
| 22 |
+
load_textual_inversion_embeddings = sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings
|
| 23 |
+
except Exception as e: # Not supported.
|
| 24 |
+
load_textual_inversion_embeddings = lambda *args, **kwargs: None
|
| 25 |
+
print("Tag Autocomplete: Cannot reload embeddings instantly:", e)
|
| 26 |
+
|
| 27 |
+
# Sorting functions for extra networks / embeddings stuff
|
| 28 |
+
sort_criteria = {
|
| 29 |
+
"Name": lambda path, name, subpath: name.lower() if subpath else path.stem.lower(),
|
| 30 |
+
"Date Modified (newest first)": lambda path, name, subpath: path.stat().st_mtime,
|
| 31 |
+
"Date Modified (oldest first)": lambda path, name, subpath: path.stat().st_mtime
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
def sort_models(model_list, sort_method = None, name_has_subpath = False):
|
| 35 |
+
"""Sorts models according to the setting.
|
| 36 |
+
|
| 37 |
+
Input: list of (full_path, display_name, {hash}) models.
|
| 38 |
+
Returns models in the format of name, sort key, meta.
|
| 39 |
+
Meta is optional and can be a hash, version string or other required info.
|
| 40 |
+
"""
|
| 41 |
+
if len(model_list) == 0:
|
| 42 |
+
return model_list
|
| 43 |
+
|
| 44 |
+
if sort_method is None:
|
| 45 |
+
sort_method = getattr(shared.opts, "tac_modelSortOrder", "Name")
|
| 46 |
+
|
| 47 |
+
# Get sorting method from dictionary
|
| 48 |
+
sorter = sort_criteria.get(sort_method, sort_criteria["Name"])
|
| 49 |
+
|
| 50 |
+
# During merging on the JS side we need to re-sort anyway, so here only the sort criteria are calculated.
|
| 51 |
+
# The list itself doesn't need to get sorted at this point.
|
| 52 |
+
if len(model_list[0]) > 2:
|
| 53 |
+
results = [f'{name},"{sorter(path, name, name_has_subpath)}",{meta}' for path, name, meta in model_list]
|
| 54 |
+
else:
|
| 55 |
+
results = [f'{name},"{sorter(path, name, name_has_subpath)}"' for path, name in model_list]
|
| 56 |
+
return results
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def get_wildcards():
|
| 60 |
+
"""Returns a list of all wildcards. Works on nested folders."""
|
| 61 |
+
wildcard_files = list(WILDCARD_PATH.rglob("*.txt"))
|
| 62 |
+
resolved = [(w, w.relative_to(WILDCARD_PATH).as_posix())
|
| 63 |
+
for w in wildcard_files
|
| 64 |
+
if w.name != "put wildcards here.txt"
|
| 65 |
+
and w.is_file()]
|
| 66 |
+
return sort_models(resolved, name_has_subpath=True)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def get_ext_wildcards():
|
| 70 |
+
"""Returns a list of all extension wildcards. Works on nested folders."""
|
| 71 |
+
wildcard_files = []
|
| 72 |
+
|
| 73 |
+
for path in WILDCARD_EXT_PATHS:
|
| 74 |
+
wildcard_files.append(path.as_posix())
|
| 75 |
+
resolved = [(w, w.relative_to(path).as_posix())
|
| 76 |
+
for w in path.rglob("*.txt")
|
| 77 |
+
if w.name != "put wildcards here.txt"
|
| 78 |
+
and w.is_file()]
|
| 79 |
+
wildcard_files.extend(sort_models(resolved, name_has_subpath=True))
|
| 80 |
+
wildcard_files.append("-----")
|
| 81 |
+
|
| 82 |
+
return wildcard_files
|
| 83 |
+
|
| 84 |
+
def is_umi_format(data):
|
| 85 |
+
"""Returns True if the YAML file is in UMI format."""
|
| 86 |
+
issue_found = False
|
| 87 |
+
for item in data:
|
| 88 |
+
if not (data[item] and 'Tags' in data[item] and isinstance(data[item]['Tags'], list)):
|
| 89 |
+
issue_found = True
|
| 90 |
+
break
|
| 91 |
+
return not issue_found
|
| 92 |
+
|
| 93 |
+
count = 0
|
| 94 |
+
def parse_umi_format(umi_tags, data):
|
| 95 |
+
global count
|
| 96 |
+
for item in data:
|
| 97 |
+
umi_tags[count] = ','.join(data[item]['Tags'])
|
| 98 |
+
count += 1
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def parse_dynamic_prompt_format(yaml_wildcards, data, path):
|
| 102 |
+
# Recurse subkeys, delete those without string lists as values
|
| 103 |
+
def recurse_dict(d: dict):
|
| 104 |
+
for key, value in d.copy().items():
|
| 105 |
+
if isinstance(value, dict):
|
| 106 |
+
recurse_dict(value)
|
| 107 |
+
elif not (isinstance(value, list) and all(isinstance(v, str) for v in value)):
|
| 108 |
+
del d[key]
|
| 109 |
+
|
| 110 |
+
recurse_dict(data)
|
| 111 |
+
# Add to yaml_wildcards
|
| 112 |
+
yaml_wildcards[path.name] = data
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def get_yaml_wildcards():
|
| 116 |
+
"""Returns a list of all tags found in extension YAML files found under a Tags: key."""
|
| 117 |
+
yaml_files = []
|
| 118 |
+
for path in WILDCARD_EXT_PATHS:
|
| 119 |
+
yaml_files.extend(p for p in path.rglob("*.yml") if p.is_file())
|
| 120 |
+
yaml_files.extend(p for p in path.rglob("*.yaml") if p.is_file())
|
| 121 |
+
|
| 122 |
+
yaml_wildcards = {}
|
| 123 |
+
|
| 124 |
+
umi_tags = {} # { tag: count }
|
| 125 |
+
|
| 126 |
+
for path in yaml_files:
|
| 127 |
+
try:
|
| 128 |
+
with open(path, encoding="utf8") as file:
|
| 129 |
+
data = yaml.safe_load(file)
|
| 130 |
+
if (data):
|
| 131 |
+
if (is_umi_format(data)):
|
| 132 |
+
parse_umi_format(umi_tags, data)
|
| 133 |
+
else:
|
| 134 |
+
parse_dynamic_prompt_format(yaml_wildcards, data, path)
|
| 135 |
+
else:
|
| 136 |
+
print('No data found in ' + path.name)
|
| 137 |
+
except (yaml.YAMLError, UnicodeDecodeError) as e:
|
| 138 |
+
print(f'Issue in parsing YAML file {path.name}: {e}')
|
| 139 |
+
continue
|
| 140 |
+
|
| 141 |
+
# Sort by count
|
| 142 |
+
umi_sorted = sorted(umi_tags.items(), key=lambda item: item[1], reverse=True)
|
| 143 |
+
umi_output = []
|
| 144 |
+
for tag, count in umi_sorted:
|
| 145 |
+
umi_output.append(f"{tag},{count}")
|
| 146 |
+
|
| 147 |
+
if (len(umi_output) > 0):
|
| 148 |
+
write_to_temp_file('umi_tags.txt', umi_output)
|
| 149 |
+
|
| 150 |
+
with open(TEMP_PATH.joinpath("wc_yaml.json"), "w", encoding="utf-8") as file:
|
| 151 |
+
json.dump(yaml_wildcards, file, ensure_ascii=False)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def get_embeddings(sd_model):
|
| 155 |
+
"""Write a list of all embeddings with their version"""
|
| 156 |
+
|
| 157 |
+
# Version constants
|
| 158 |
+
V1_SHAPE = 768
|
| 159 |
+
V2_SHAPE = 1024
|
| 160 |
+
VXL_SHAPE = 2048
|
| 161 |
+
emb_v1 = []
|
| 162 |
+
emb_v2 = []
|
| 163 |
+
emb_vXL = []
|
| 164 |
+
results = []
|
| 165 |
+
|
| 166 |
+
try:
|
| 167 |
+
# Get embedding dict from sd_hijack to separate v1/v2 embeddings
|
| 168 |
+
loaded = sd_hijack.model_hijack.embedding_db.word_embeddings
|
| 169 |
+
skipped = sd_hijack.model_hijack.embedding_db.skipped_embeddings
|
| 170 |
+
|
| 171 |
+
# Add embeddings to the correct list
|
| 172 |
+
for key, emb in (loaded | skipped).items():
|
| 173 |
+
if emb.filename is None or emb.shape is None:
|
| 174 |
+
continue
|
| 175 |
+
|
| 176 |
+
if emb.shape == V1_SHAPE:
|
| 177 |
+
emb_v1.append((Path(emb.filename), key, "v1"))
|
| 178 |
+
elif emb.shape == V2_SHAPE:
|
| 179 |
+
emb_v2.append((Path(emb.filename), key, "v2"))
|
| 180 |
+
elif emb.shape == VXL_SHAPE:
|
| 181 |
+
emb_vXL.append((Path(emb.filename), key, "vXL"))
|
| 182 |
+
|
| 183 |
+
results = sort_models(emb_v1) + sort_models(emb_v2) + sort_models(emb_vXL)
|
| 184 |
+
except AttributeError:
|
| 185 |
+
print("tag_autocomplete_helper: Old webui version or unrecognized model shape, using fallback for embedding completion.")
|
| 186 |
+
# Get a list of all embeddings in the folder
|
| 187 |
+
all_embeds = [str(e.relative_to(EMB_PATH)) for e in EMB_PATH.rglob("*") if e.suffix in {".bin", ".pt", ".png",'.webp', '.jxl', '.avif'} and e.is_file()]
|
| 188 |
+
# Remove files with a size of 0
|
| 189 |
+
all_embeds = [e for e in all_embeds if EMB_PATH.joinpath(e).stat().st_size > 0]
|
| 190 |
+
# Remove file extensions
|
| 191 |
+
all_embeds = [e[:e.rfind('.')] for e in all_embeds]
|
| 192 |
+
results = [e + "," for e in all_embeds]
|
| 193 |
+
|
| 194 |
+
write_to_temp_file('emb.txt', results)
|
| 195 |
+
|
| 196 |
+
def get_hypernetworks():
|
| 197 |
+
"""Write a list of all hypernetworks"""
|
| 198 |
+
|
| 199 |
+
# Get a list of all hypernetworks in the folder
|
| 200 |
+
hyp_paths = [Path(h) for h in glob.glob(HYP_PATH.joinpath("**/*").as_posix(), recursive=True)]
|
| 201 |
+
all_hypernetworks = [(h, h.stem) for h in hyp_paths if h.suffix in {".pt"} and h.is_file()]
|
| 202 |
+
return sort_models(all_hypernetworks)
|
| 203 |
+
|
| 204 |
+
model_keyword_installed = write_model_keyword_path()
|
| 205 |
+
def get_lora():
|
| 206 |
+
"""Write a list of all lora"""
|
| 207 |
+
global model_keyword_installed
|
| 208 |
+
|
| 209 |
+
# Get a list of all lora in the folder
|
| 210 |
+
lora_paths = [Path(l) for l in glob.glob(LORA_PATH.joinpath("**/*").as_posix(), recursive=True)]
|
| 211 |
+
# Get hashes
|
| 212 |
+
valid_loras = [lf for lf in lora_paths if lf.suffix in {".safetensors", ".ckpt", ".pt"} and lf.is_file()]
|
| 213 |
+
loras_with_hash = []
|
| 214 |
+
for l in valid_loras:
|
| 215 |
+
name = l.relative_to(LORA_PATH).as_posix()
|
| 216 |
+
if model_keyword_installed:
|
| 217 |
+
hash = get_lora_simple_hash(l)
|
| 218 |
+
else:
|
| 219 |
+
hash = ""
|
| 220 |
+
loras_with_hash.append((l, name, hash))
|
| 221 |
+
# Sort
|
| 222 |
+
return sort_models(loras_with_hash)
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def get_lyco():
|
| 226 |
+
"""Write a list of all LyCORIS/LOHA from https://github.com/KohakuBlueleaf/a1111-sd-webui-lycoris"""
|
| 227 |
+
|
| 228 |
+
# Get a list of all LyCORIS in the folder
|
| 229 |
+
lyco_paths = [Path(ly) for ly in glob.glob(LYCO_PATH.joinpath("**/*").as_posix(), recursive=True)]
|
| 230 |
+
|
| 231 |
+
# Get hashes
|
| 232 |
+
valid_lycos = [lyf for lyf in lyco_paths if lyf.suffix in {".safetensors", ".ckpt", ".pt"} and lyf.is_file()]
|
| 233 |
+
lycos_with_hash = []
|
| 234 |
+
for ly in valid_lycos:
|
| 235 |
+
name = ly.relative_to(LYCO_PATH).as_posix()
|
| 236 |
+
if model_keyword_installed:
|
| 237 |
+
hash = get_lora_simple_hash(ly)
|
| 238 |
+
else:
|
| 239 |
+
hash = ""
|
| 240 |
+
lycos_with_hash.append((ly, name, hash))
|
| 241 |
+
# Sort
|
| 242 |
+
return sort_models(lycos_with_hash)
|
| 243 |
+
|
| 244 |
+
def write_tag_base_path():
|
| 245 |
+
"""Writes the tag base path to a fixed location temporary file"""
|
| 246 |
+
with open(STATIC_TEMP_PATH.joinpath('tagAutocompletePath.txt'), 'w', encoding="utf-8") as f:
|
| 247 |
+
f.write(TAGS_PATH.as_posix())
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def write_to_temp_file(name, data):
|
| 251 |
+
"""Writes the given data to a temporary file"""
|
| 252 |
+
with open(TEMP_PATH.joinpath(name), 'w', encoding="utf-8") as f:
|
| 253 |
+
f.write(('\n'.join(data)))
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
csv_files = []
|
| 257 |
+
csv_files_withnone = []
|
| 258 |
+
def update_tag_files(*args, **kwargs):
|
| 259 |
+
"""Returns a list of all potential tag files"""
|
| 260 |
+
global csv_files, csv_files_withnone
|
| 261 |
+
files = [str(t.relative_to(TAGS_PATH)) for t in TAGS_PATH.glob("*.csv") if t.is_file()]
|
| 262 |
+
csv_files = files
|
| 263 |
+
csv_files_withnone = ["None"] + files
|
| 264 |
+
|
| 265 |
+
json_files = []
|
| 266 |
+
json_files_withnone = []
|
| 267 |
+
def update_json_files(*args, **kwargs):
|
| 268 |
+
"""Returns a list of all potential json files"""
|
| 269 |
+
global json_files, json_files_withnone
|
| 270 |
+
files = [str(j.relative_to(TAGS_PATH)) for j in TAGS_PATH.glob("*.json") if j.is_file()]
|
| 271 |
+
json_files = files
|
| 272 |
+
json_files_withnone = ["None"] + files
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
# Write the tag base path to a fixed location temporary file
|
| 276 |
+
# to enable the javascript side to find our files regardless of extension folder name
|
| 277 |
+
if not STATIC_TEMP_PATH.exists():
|
| 278 |
+
STATIC_TEMP_PATH.mkdir(exist_ok=True)
|
| 279 |
+
|
| 280 |
+
write_tag_base_path()
|
| 281 |
+
update_tag_files()
|
| 282 |
+
update_json_files()
|
| 283 |
+
|
| 284 |
+
# Check if the temp path exists and create it if not
|
| 285 |
+
if not TEMP_PATH.exists():
|
| 286 |
+
TEMP_PATH.mkdir(parents=True, exist_ok=True)
|
| 287 |
+
|
| 288 |
+
# Set up files to ensure the script doesn't fail to load them
|
| 289 |
+
# even if no wildcards or embeddings are found
|
| 290 |
+
write_to_temp_file('wc.txt', [])
|
| 291 |
+
write_to_temp_file('wce.txt', [])
|
| 292 |
+
write_to_temp_file('wc_yaml.json', [])
|
| 293 |
+
write_to_temp_file('umi_tags.txt', [])
|
| 294 |
+
write_to_temp_file('hyp.txt', [])
|
| 295 |
+
write_to_temp_file('lora.txt', [])
|
| 296 |
+
write_to_temp_file('lyco.txt', [])
|
| 297 |
+
# Only reload embeddings if the file doesn't exist, since they are already re-written on model load
|
| 298 |
+
if not TEMP_PATH.joinpath("emb.txt").exists():
|
| 299 |
+
write_to_temp_file('emb.txt', [])
|
| 300 |
+
|
| 301 |
+
# Write embeddings to emb.txt if found
|
| 302 |
+
if EMB_PATH.exists():
|
| 303 |
+
# Get embeddings after the model loaded callback
|
| 304 |
+
script_callbacks.on_model_loaded(get_embeddings)
|
| 305 |
+
|
| 306 |
+
def refresh_temp_files(*args, **kwargs):
|
| 307 |
+
global WILDCARD_EXT_PATHS
|
| 308 |
+
WILDCARD_EXT_PATHS = find_ext_wildcard_paths()
|
| 309 |
+
load_textual_inversion_embeddings(force_reload = True) # Instant embedding reload.
|
| 310 |
+
write_temp_files()
|
| 311 |
+
get_embeddings(shared.sd_model)
|
| 312 |
+
|
| 313 |
+
def write_temp_files():
|
| 314 |
+
# Write wildcards to wc.txt if found
|
| 315 |
+
if WILDCARD_PATH.exists():
|
| 316 |
+
wildcards = [WILDCARD_PATH.relative_to(FILE_DIR).as_posix()] + get_wildcards()
|
| 317 |
+
if wildcards:
|
| 318 |
+
write_to_temp_file('wc.txt', wildcards)
|
| 319 |
+
|
| 320 |
+
# Write extension wildcards to wce.txt if found
|
| 321 |
+
if WILDCARD_EXT_PATHS is not None:
|
| 322 |
+
wildcards_ext = get_ext_wildcards()
|
| 323 |
+
if wildcards_ext:
|
| 324 |
+
write_to_temp_file('wce.txt', wildcards_ext)
|
| 325 |
+
# Write yaml extension wildcards to umi_tags.txt and wc_yaml.json if found
|
| 326 |
+
get_yaml_wildcards()
|
| 327 |
+
|
| 328 |
+
if HYP_PATH.exists():
|
| 329 |
+
hypernets = get_hypernetworks()
|
| 330 |
+
if hypernets:
|
| 331 |
+
write_to_temp_file('hyp.txt', hypernets)
|
| 332 |
+
|
| 333 |
+
if model_keyword_installed:
|
| 334 |
+
load_hash_cache()
|
| 335 |
+
|
| 336 |
+
lora_exists = LORA_PATH is not None and LORA_PATH.exists()
|
| 337 |
+
if lora_exists:
|
| 338 |
+
lora = get_lora()
|
| 339 |
+
if lora:
|
| 340 |
+
write_to_temp_file('lora.txt', lora)
|
| 341 |
+
|
| 342 |
+
lyco_exists = LYCO_PATH is not None and LYCO_PATH.exists()
|
| 343 |
+
if lyco_exists and not (lora_exists and LYCO_PATH.samefile(LORA_PATH)):
|
| 344 |
+
lyco = get_lyco()
|
| 345 |
+
if lyco:
|
| 346 |
+
write_to_temp_file('lyco.txt', lyco)
|
| 347 |
+
elif lyco_exists and lora_exists and LYCO_PATH.samefile(LORA_PATH):
|
| 348 |
+
print("tag_autocomplete_helper: LyCORIS path is the same as LORA path, skipping")
|
| 349 |
+
|
| 350 |
+
if model_keyword_installed:
|
| 351 |
+
update_hash_cache()
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
write_temp_files()
|
| 355 |
+
|
| 356 |
+
# Register autocomplete options
|
| 357 |
+
def on_ui_settings():
|
| 358 |
+
TAC_SECTION = ("tac", "Tag Autocomplete")
|
| 359 |
+
|
| 360 |
+
# Backwards compatibility for pre 1.3.0 webui versions
|
| 361 |
+
if not (hasattr(shared.OptionInfo, "info") and callable(getattr(shared.OptionInfo, "info"))):
|
| 362 |
+
def info(self, info):
|
| 363 |
+
self.label += f" ({info})"
|
| 364 |
+
return self
|
| 365 |
+
shared.OptionInfo.info = info
|
| 366 |
+
if not (hasattr(shared.OptionInfo, "needs_restart") and callable(getattr(shared.OptionInfo, "needs_restart"))):
|
| 367 |
+
def needs_restart(self):
|
| 368 |
+
self.label += " (Requires restart)"
|
| 369 |
+
return self
|
| 370 |
+
shared.OptionInfo.needs_restart = needs_restart
|
| 371 |
+
|
| 372 |
+
tac_options = {
|
| 373 |
+
# Main tag file
|
| 374 |
+
"tac_tagFile": shared.OptionInfo("danbooru.csv", "Tag filename", gr.Dropdown, lambda: {"choices": csv_files_withnone}, refresh=update_tag_files),
|
| 375 |
+
# Active in settings
|
| 376 |
+
"tac_active": shared.OptionInfo(True, "Enable Tag Autocompletion"),
|
| 377 |
+
"tac_activeIn.txt2img": shared.OptionInfo(True, "Active in txt2img").needs_restart(),
|
| 378 |
+
"tac_activeIn.img2img": shared.OptionInfo(True, "Active in img2img").needs_restart(),
|
| 379 |
+
"tac_activeIn.negativePrompts": shared.OptionInfo(True, "Active in negative prompts").needs_restart(),
|
| 380 |
+
"tac_activeIn.thirdParty": shared.OptionInfo(True, "Active in third party textboxes").info("See <a href=\"https://github.com/DominikDoom/a1111-sd-webui-tagcomplete#-features\" target=\"_blank\">README</a> for supported extensions").needs_restart(),
|
| 381 |
+
"tac_activeIn.modelList": shared.OptionInfo("", "Black/Whitelist models").info("Model names [with file extension] or their hashes, separated by commas"),
|
| 382 |
+
"tac_activeIn.modelListMode": shared.OptionInfo("Blacklist", "Mode to use for model list", gr.Dropdown, lambda: {"choices": ["Blacklist","Whitelist"]}),
|
| 383 |
+
# Results related settings
|
| 384 |
+
"tac_slidingPopup": shared.OptionInfo(True, "Move completion popup together with text cursor"),
|
| 385 |
+
"tac_maxResults": shared.OptionInfo(5, "Maximum results"),
|
| 386 |
+
"tac_showAllResults": shared.OptionInfo(False, "Show all results"),
|
| 387 |
+
"tac_resultStepLength": shared.OptionInfo(100, "How many results to load at once"),
|
| 388 |
+
"tac_delayTime": shared.OptionInfo(100, "Time in ms to wait before triggering completion again").needs_restart(),
|
| 389 |
+
"tac_useWildcards": shared.OptionInfo(True, "Search for wildcards"),
|
| 390 |
+
"tac_sortWildcardResults": shared.OptionInfo(True, "Sort wildcard file contents alphabetically").info("If your wildcard files have a specific custom order, disable this to keep it"),
|
| 391 |
+
"tac_useEmbeddings": shared.OptionInfo(True, "Search for embeddings"),
|
| 392 |
+
"tac_includeEmbeddingsInNormalResults": shared.OptionInfo(False, "Include embeddings in normal tag results").info("The 'JumpTo...' keybinds (End & Home key by default) will select the first non-embedding result of their direction on the first press for quick navigation in longer lists."),
|
| 393 |
+
"tac_useHypernetworks": shared.OptionInfo(True, "Search for hypernetworks"),
|
| 394 |
+
"tac_useLoras": shared.OptionInfo(True, "Search for Loras"),
|
| 395 |
+
"tac_useLycos": shared.OptionInfo(True, "Search for LyCORIS/LoHa"),
|
| 396 |
+
"tac_showWikiLinks": shared.OptionInfo(False, "Show '?' next to tags, linking to its Danbooru or e621 wiki page").info("Warning: This is an external site and very likely contains NSFW examples!"),
|
| 397 |
+
"tac_showExtraNetworkPreviews": shared.OptionInfo(True, "Show preview thumbnails for extra networks if available"),
|
| 398 |
+
"tac_modelSortOrder": shared.OptionInfo("Name", "Model sort order", gr.Dropdown, lambda: {"choices": list(sort_criteria.keys())}).info("Order for extra network models and wildcards in dropdown"),
|
| 399 |
+
# Insertion related settings
|
| 400 |
+
"tac_replaceUnderscores": shared.OptionInfo(True, "Replace underscores with spaces on insertion"),
|
| 401 |
+
"tac_escapeParentheses": shared.OptionInfo(True, "Escape parentheses on insertion"),
|
| 402 |
+
"tac_appendComma": shared.OptionInfo(True, "Append comma on tag autocompletion"),
|
| 403 |
+
"tac_appendSpace": shared.OptionInfo(True, "Append space on tag autocompletion").info("will append after comma if the above is enabled"),
|
| 404 |
+
"tac_alwaysSpaceAtEnd": shared.OptionInfo(True, "Always append space if inserting at the end of the textbox").info("takes precedence over the regular space setting for that position"),
|
| 405 |
+
"tac_modelKeywordCompletion": shared.OptionInfo("Never", "Try to add known trigger words for LORA/LyCO models", gr.Dropdown, lambda: {"choices": ["Never","Only user list","Always"]}).info("Will use & prefer the native activation keywords settable in the extra networks UI. Other functionality requires the <a href=\"https://github.com/mix1009/model-keyword\" target=\"_blank\">model-keyword</a> extension to be installed, but will work with it disabled.").needs_restart(),
|
| 406 |
+
"tac_modelKeywordLocation": shared.OptionInfo("Start of prompt", "Where to insert the trigger keyword", gr.Dropdown, lambda: {"choices": ["Start of prompt","End of prompt","Before LORA/LyCO"]}).info("Only relevant if the above option is enabled"),
|
| 407 |
+
"tac_wildcardCompletionMode": shared.OptionInfo("To next folder level", "How to complete nested wildcard paths", gr.Dropdown, lambda: {"choices": ["To next folder level","To first difference","Always fully"]}).info("e.g. \"hair/colours/light/...\""),
|
| 408 |
+
# Alias settings
|
| 409 |
+
"tac_alias.searchByAlias": shared.OptionInfo(True, "Search by alias"),
|
| 410 |
+
"tac_alias.onlyShowAlias": shared.OptionInfo(False, "Only show alias"),
|
| 411 |
+
# Translation settings
|
| 412 |
+
"tac_translation.translationFile": shared.OptionInfo("None", "Translation filename", gr.Dropdown, lambda: {"choices": csv_files_withnone}, refresh=update_tag_files),
|
| 413 |
+
"tac_translation.oldFormat": shared.OptionInfo(False, "Translation file uses old 3-column translation format instead of the new 2-column one"),
|
| 414 |
+
"tac_translation.searchByTranslation": shared.OptionInfo(True, "Search by translation"),
|
| 415 |
+
"tac_translation.liveTranslation": shared.OptionInfo(False, "Show live tag translation below prompt ").info("WIP, expect some bugs"),
|
| 416 |
+
# Extra file settings
|
| 417 |
+
"tac_extra.extraFile": shared.OptionInfo("extra-quality-tags.csv", "Extra filename", gr.Dropdown, lambda: {"choices": csv_files_withnone}, refresh=update_tag_files).info("for small sets of custom tags"),
|
| 418 |
+
"tac_extra.addMode": shared.OptionInfo("Insert before", "Mode to add the extra tags to the main tag list", gr.Dropdown, lambda: {"choices": ["Insert before","Insert after"]}),
|
| 419 |
+
# Chant settings
|
| 420 |
+
"tac_chantFile": shared.OptionInfo("demo-chants.json", "Chant filename", gr.Dropdown, lambda: {"choices": json_files_withnone}, refresh=update_json_files).info("Chants are longer prompt presets"),
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
# Add normal settings
|
| 424 |
+
for key, opt in tac_options.items():
|
| 425 |
+
opt.section = TAC_SECTION
|
| 426 |
+
shared.opts.add_option(key, opt)
|
| 427 |
+
|
| 428 |
+
# Settings that need special treatment
|
| 429 |
+
# Custom mappings
|
| 430 |
+
keymapDefault = """\
|
| 431 |
+
{
|
| 432 |
+
"MoveUp": "ArrowUp",
|
| 433 |
+
"MoveDown": "ArrowDown",
|
| 434 |
+
"JumpUp": "PageUp",
|
| 435 |
+
"JumpDown": "PageDown",
|
| 436 |
+
"JumpToStart": "Home",
|
| 437 |
+
"JumpToEnd": "End",
|
| 438 |
+
"ChooseSelected": "Enter",
|
| 439 |
+
"ChooseFirstOrSelected": "Tab",
|
| 440 |
+
"Close": "Escape"
|
| 441 |
+
}\
|
| 442 |
+
"""
|
| 443 |
+
colorDefault = """\
|
| 444 |
+
{
|
| 445 |
+
"danbooru": {
|
| 446 |
+
"-1": ["red", "maroon"],
|
| 447 |
+
"0": ["lightblue", "dodgerblue"],
|
| 448 |
+
"1": ["indianred", "firebrick"],
|
| 449 |
+
"3": ["violet", "darkorchid"],
|
| 450 |
+
"4": ["lightgreen", "darkgreen"],
|
| 451 |
+
"5": ["orange", "darkorange"]
|
| 452 |
+
},
|
| 453 |
+
"e621": {
|
| 454 |
+
"-1": ["red", "maroon"],
|
| 455 |
+
"0": ["lightblue", "dodgerblue"],
|
| 456 |
+
"1": ["gold", "goldenrod"],
|
| 457 |
+
"3": ["violet", "darkorchid"],
|
| 458 |
+
"4": ["lightgreen", "darkgreen"],
|
| 459 |
+
"5": ["tomato", "darksalmon"],
|
| 460 |
+
"6": ["red", "maroon"],
|
| 461 |
+
"7": ["whitesmoke", "black"],
|
| 462 |
+
"8": ["seagreen", "darkseagreen"]
|
| 463 |
+
}
|
| 464 |
+
}\
|
| 465 |
+
"""
|
| 466 |
+
keymapLabel = "Configure Hotkeys. For possible values, see https://www.w3.org/TR/uievents-key, or leave empty / set to 'None' to disable. Must be valid JSON."
|
| 467 |
+
colorLabel = "Configure colors. See the Settings section in the README for more info. Must be valid JSON."
|
| 468 |
+
|
| 469 |
+
try:
|
| 470 |
+
shared.opts.add_option("tac_keymap", shared.OptionInfo(keymapDefault, keymapLabel, gr.Code, lambda: {"language": "json", "interactive": True}, section=TAC_SECTION))
|
| 471 |
+
shared.opts.add_option("tac_colormap", shared.OptionInfo(colorDefault, colorLabel, gr.Code, lambda: {"language": "json", "interactive": True}, section=TAC_SECTION))
|
| 472 |
+
except AttributeError:
|
| 473 |
+
shared.opts.add_option("tac_keymap", shared.OptionInfo(keymapDefault, keymapLabel, gr.Textbox, section=TAC_SECTION))
|
| 474 |
+
shared.opts.add_option("tac_colormap", shared.OptionInfo(colorDefault, colorLabel, gr.Textbox, section=TAC_SECTION))
|
| 475 |
+
|
| 476 |
+
shared.opts.add_option("tac_refreshTempFiles", shared.OptionInfo("Refresh TAC temp files", "Refresh internal temp files", gr.HTML, {}, refresh=refresh_temp_files, section=TAC_SECTION))
|
| 477 |
+
|
| 478 |
+
script_callbacks.on_ui_settings(on_ui_settings)
|
| 479 |
+
|
| 480 |
+
def api_tac(_: gr.Blocks, app: FastAPI):
|
| 481 |
+
async def get_json_info(base_path: Path, filename: str = None):
|
| 482 |
+
if base_path is None or (not base_path.exists()):
|
| 483 |
+
return JSONResponse({}, status_code=404)
|
| 484 |
+
|
| 485 |
+
try:
|
| 486 |
+
json_candidates = glob.glob(base_path.as_posix() + f"/**/{filename}.json", recursive=True)
|
| 487 |
+
if json_candidates is not None and len(json_candidates) > 0 and Path(json_candidates[0]).is_file():
|
| 488 |
+
return FileResponse(json_candidates[0])
|
| 489 |
+
except Exception as e:
|
| 490 |
+
return JSONResponse({"error": e}, status_code=500)
|
| 491 |
+
|
| 492 |
+
async def get_preview_thumbnail(base_path: Path, filename: str = None, blob: bool = False):
|
| 493 |
+
if base_path is None or (not base_path.exists()):
|
| 494 |
+
return JSONResponse({}, status_code=404)
|
| 495 |
+
|
| 496 |
+
try:
|
| 497 |
+
img_glob = glob.glob(base_path.as_posix() + f"/**/{filename}.*", recursive=True)
|
| 498 |
+
img_candidates = [img for img in img_glob if Path(img).suffix in [".png", ".jpg", ".jpeg", ".webp", ".gif"] and Path(img).is_file()]
|
| 499 |
+
if img_candidates is not None and len(img_candidates) > 0:
|
| 500 |
+
if blob:
|
| 501 |
+
return FileResponse(img_candidates[0])
|
| 502 |
+
else:
|
| 503 |
+
return JSONResponse({"url": urllib.parse.quote(img_candidates[0])})
|
| 504 |
+
except Exception as e:
|
| 505 |
+
return JSONResponse({"error": e}, status_code=500)
|
| 506 |
+
|
| 507 |
+
@app.post("/tacapi/v1/refresh-temp-files")
|
| 508 |
+
async def api_refresh_temp_files():
|
| 509 |
+
refresh_temp_files()
|
| 510 |
+
|
| 511 |
+
@app.get("/tacapi/v1/lora-info/{lora_name}")
|
| 512 |
+
async def get_lora_info(lora_name):
|
| 513 |
+
return await get_json_info(LORA_PATH, lora_name)
|
| 514 |
+
|
| 515 |
+
@app.get("/tacapi/v1/lyco-info/{lyco_name}")
|
| 516 |
+
async def get_lyco_info(lyco_name):
|
| 517 |
+
return await get_json_info(LYCO_PATH, lyco_name)
|
| 518 |
+
|
| 519 |
+
@app.get("/tacapi/v1/lora-cached-hash/{lora_name}")
|
| 520 |
+
async def get_lora_cached_hash(lora_name: str):
|
| 521 |
+
path_glob = glob.glob(LORA_PATH.as_posix() + f"/**/{lora_name}.*", recursive=True)
|
| 522 |
+
paths = [lora for lora in path_glob if Path(lora).suffix in [".safetensors", ".ckpt", ".pt"] and Path(lora).is_file()]
|
| 523 |
+
if paths is not None and len(paths) > 0:
|
| 524 |
+
path = paths[0]
|
| 525 |
+
hash = hashes.sha256_from_cache(path, f"lora/{lora_name}", path.endswith(".safetensors"))
|
| 526 |
+
if hash is not None:
|
| 527 |
+
return hash
|
| 528 |
+
|
| 529 |
+
return None
|
| 530 |
+
|
| 531 |
+
def get_path_for_type(type):
|
| 532 |
+
if type == "lora":
|
| 533 |
+
return LORA_PATH
|
| 534 |
+
elif type == "lyco":
|
| 535 |
+
return LYCO_PATH
|
| 536 |
+
elif type == "hyper":
|
| 537 |
+
return HYP_PATH
|
| 538 |
+
elif type == "embed":
|
| 539 |
+
return EMB_PATH
|
| 540 |
+
else:
|
| 541 |
+
return None
|
| 542 |
+
|
| 543 |
+
@app.get("/tacapi/v1/thumb-preview/{filename}")
|
| 544 |
+
async def get_thumb_preview(filename, type):
|
| 545 |
+
return await get_preview_thumbnail(get_path_for_type(type), filename, False)
|
| 546 |
+
|
| 547 |
+
@app.get("/tacapi/v1/thumb-preview-blob/{filename}")
|
| 548 |
+
async def get_thumb_preview_blob(filename, type):
|
| 549 |
+
return await get_preview_thumbnail(get_path_for_type(type), filename, True)
|
| 550 |
+
|
| 551 |
+
@app.get("/tacapi/v1/wildcard-contents")
|
| 552 |
+
async def get_wildcard_contents(basepath: str, filename: str):
|
| 553 |
+
if basepath is None or basepath == "":
|
| 554 |
+
return JSONResponse({}, status_code=404)
|
| 555 |
+
|
| 556 |
+
base = Path(basepath)
|
| 557 |
+
if base is None or (not base.exists()):
|
| 558 |
+
return JSONResponse({}, status_code=404)
|
| 559 |
+
|
| 560 |
+
try:
|
| 561 |
+
wildcard_path = base.joinpath(filename)
|
| 562 |
+
if wildcard_path.exists() and wildcard_path.is_file():
|
| 563 |
+
return FileResponse(wildcard_path)
|
| 564 |
+
else:
|
| 565 |
+
return JSONResponse({}, status_code=404)
|
| 566 |
+
except Exception as e:
|
| 567 |
+
return JSONResponse({"error": e}, status_code=500)
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
script_callbacks.on_app_started(api_tac)
|
a1111-sd-webui-tagcomplete-main/tags/danbooru.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
a1111-sd-webui-tagcomplete-main/tags/demo-chants.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"name": "Basic-NegativePrompt",
|
| 4 |
+
"terms": "Basic,Negative,Low,Quality",
|
| 5 |
+
"content": "(worst quality, low quality, normal quality)",
|
| 6 |
+
"color": 3
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"name": "Basic-HighQuality",
|
| 10 |
+
"terms": "Basic,Best,High,Quality",
|
| 11 |
+
"content": "(masterpiece, best quality, high quality, highres, ultra-detailed)",
|
| 12 |
+
"color": 1
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"name": "Basic-Start",
|
| 16 |
+
"terms": "Basic, Start, Simple, Demo",
|
| 17 |
+
"content": "(masterpiece, best quality, high quality, highres), 1girl, extremely beautiful detailed face, short curly hair, light smile, flower dress, outdoors, leaf, tree, best shadow",
|
| 18 |
+
"color": 5
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"name": "Fancy-FireMagic",
|
| 22 |
+
"terms": "Fire, Magic, Fancy",
|
| 23 |
+
"content": "(extremely detailed CG unity 8k wallpaper), (masterpiece), (best quality), (ultra-detailed), (best illustration),(best shadow), (an extremely delicate and beautiful), dynamic angle, floating, fine detail, (bloom), (shine), glinting stars, classic, (painting), (sketch),\n\na girl, solo, bare shoulders, flat_chest, diamond and glaring eyes, beautiful detailed cold face, very long blue and sliver hair, floating black feathers, wavy hair, extremely delicate and beautiful girls, beautiful detailed eyes, glowing eyes,\n\npalace, the best building, ((Fire butterflies, Flying sparks, Flames))",
|
| 24 |
+
"color": 5
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"name": "Fancy-WaterMagic",
|
| 28 |
+
"terms": "Water, Magic, Fancy",
|
| 29 |
+
"content": "(extremely detailed CG unity 8k wallpaper), (masterpiece), (best quality), (ultra-detailed), (best illustration),(best shadow), (an extremely delicate and beautiful), classic, dynamic angle, floating, fine detail, Depth of field, classic, (painting), (sketch), (bloom), (shine), glinting stars,\n\na girl, solo, bare shoulders, flat chest, diamond and glaring eyes, beautiful detailed cold face, very long blue and sliver hair, floating black feathers, wavy hair, extremely delicate and beautiful girls, beautiful detailed eyes, glowing eyes,\n\nriver, (forest),palace, (fairyland,feather,flowers, nature),(sunlight),Hazy fog, mist",
|
| 30 |
+
"color": 5
|
| 31 |
+
}
|
| 32 |
+
]
|
a1111-sd-webui-tagcomplete-main/tags/e621.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
a1111-sd-webui-tagcomplete-main/tags/e621_sfw.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
a1111-sd-webui-tagcomplete-main/tags/extra-quality-tags.csv
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
masterpiece,5,Quality tag,,
|
| 2 |
+
best_quality,5,Quality tag,,
|
| 3 |
+
high_quality,5,Quality tag,,
|
| 4 |
+
normal_quality,5,Quality tag,,
|
| 5 |
+
low_quality,5,Quality tag,,
|
| 6 |
+
worst_quality,5,Quality tag,,
|
a1111-sd-webui-tagcomplete-main/tags/temp/emb.txt
ADDED
|
File without changes
|
a1111-sd-webui-tagcomplete-main/tags/temp/hyp.txt
ADDED
|
File without changes
|
a1111-sd-webui-tagcomplete-main/tags/temp/known_lora_hashes.txt
ADDED
|
File without changes
|
a1111-sd-webui-tagcomplete-main/tags/temp/lora.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
AoDaiCuoi-v1.0.safetensors,"aodaicuoi-v1.0",
|
| 2 |
+
DETAIL_SLIDER_BY_STABLE_YOGI.safetensors,"detail_slider_by_stable_yogi",
|
| 3 |
+
hakama.safetensors,"hakama",
|
| 4 |
+
Lora_mat_the_anh-10.safetensors,"lora_mat_the_anh-10",
|
| 5 |
+
nzshs-10.safetensors,"nzshs-10",
|
| 6 |
+
zshs-10.safetensors,"zshs-10",
|
a1111-sd-webui-tagcomplete-main/tags/temp/lyco.txt
ADDED
|
File without changes
|
a1111-sd-webui-tagcomplete-main/tags/temp/umi_tags.txt
ADDED
|
File without changes
|
a1111-sd-webui-tagcomplete-main/tags/temp/wc.txt
ADDED
|
File without changes
|
a1111-sd-webui-tagcomplete-main/tags/temp/wc_yaml.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{}
|
a1111-sd-webui-tagcomplete-main/tags/temp/wce.txt
ADDED
|
File without changes
|
put extensions here.txt
ADDED
|
File without changes
|
sd-webui-controlnet-main/.github/ISSUE_TEMPLATE/bug_report.yml
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Bug Report
|
| 2 |
+
description: Create a report
|
| 3 |
+
title: "[Bug]: "
|
| 4 |
+
labels: ["bug-report"]
|
| 5 |
+
|
| 6 |
+
body:
|
| 7 |
+
- type: checkboxes
|
| 8 |
+
attributes:
|
| 9 |
+
label: Is there an existing issue for this?
|
| 10 |
+
description: Please search to see if an issue already exists for the bug you encountered, and that it hasn't been fixed in a recent build/commit.
|
| 11 |
+
options:
|
| 12 |
+
- label: I have searched the existing issues and checked the recent builds/commits of both this extension and the webui
|
| 13 |
+
required: true
|
| 14 |
+
- type: markdown
|
| 15 |
+
attributes:
|
| 16 |
+
value: |
|
| 17 |
+
*Please fill this form with as much information as possible, don't forget to fill "What OS..." and "What browsers" and *provide screenshots if possible**
|
| 18 |
+
- type: textarea
|
| 19 |
+
id: what-did
|
| 20 |
+
attributes:
|
| 21 |
+
label: What happened?
|
| 22 |
+
description: Tell us what happened in a very clear and simple way
|
| 23 |
+
validations:
|
| 24 |
+
required: true
|
| 25 |
+
- type: textarea
|
| 26 |
+
id: steps
|
| 27 |
+
attributes:
|
| 28 |
+
label: Steps to reproduce the problem
|
| 29 |
+
description: Please provide us with precise step by step information on how to reproduce the bug
|
| 30 |
+
value: |
|
| 31 |
+
1. Go to ....
|
| 32 |
+
2. Press ....
|
| 33 |
+
3. ...
|
| 34 |
+
validations:
|
| 35 |
+
required: true
|
| 36 |
+
- type: textarea
|
| 37 |
+
id: what-should
|
| 38 |
+
attributes:
|
| 39 |
+
label: What should have happened?
|
| 40 |
+
description: Tell what you think the normal behavior should be
|
| 41 |
+
validations:
|
| 42 |
+
required: true
|
| 43 |
+
- type: textarea
|
| 44 |
+
id: commits
|
| 45 |
+
attributes:
|
| 46 |
+
label: Commit where the problem happens
|
| 47 |
+
description: Which commit of the extension are you running on? Please include the commit of both the extension and the webui (Do not write *Latest version/repo/commit*, as this means nothing and will have changed by the time we read your issue. Rather, copy the **Commit** link at the bottom of the UI, or from the cmd/terminal if you can't launch it.)
|
| 48 |
+
value: |
|
| 49 |
+
webui:
|
| 50 |
+
controlnet:
|
| 51 |
+
validations:
|
| 52 |
+
required: true
|
| 53 |
+
- type: dropdown
|
| 54 |
+
id: browsers
|
| 55 |
+
attributes:
|
| 56 |
+
label: What browsers do you use to access the UI ?
|
| 57 |
+
multiple: true
|
| 58 |
+
options:
|
| 59 |
+
- Mozilla Firefox
|
| 60 |
+
- Google Chrome
|
| 61 |
+
- Brave
|
| 62 |
+
- Apple Safari
|
| 63 |
+
- Microsoft Edge
|
| 64 |
+
- type: textarea
|
| 65 |
+
id: cmdargs
|
| 66 |
+
attributes:
|
| 67 |
+
label: Command Line Arguments
|
| 68 |
+
description: Are you using any launching parameters/command line arguments (modified webui-user .bat/.sh) ? If yes, please write them below. Write "No" otherwise.
|
| 69 |
+
render: Shell
|
| 70 |
+
validations:
|
| 71 |
+
required: true
|
| 72 |
+
- type: textarea
|
| 73 |
+
id: extensions
|
| 74 |
+
attributes:
|
| 75 |
+
label: List of enabled extensions
|
| 76 |
+
description: Please provide a full list of enabled extensions or screenshots of your "Extensions" tab.
|
| 77 |
+
validations:
|
| 78 |
+
required: true
|
| 79 |
+
- type: textarea
|
| 80 |
+
id: logs
|
| 81 |
+
attributes:
|
| 82 |
+
label: Console logs
|
| 83 |
+
description: Please provide full cmd/terminal logs from the moment you started UI to the end of it, after your bug happened. If it's very long, provide a link to pastebin or similar service.
|
| 84 |
+
render: Shell
|
| 85 |
+
validations:
|
| 86 |
+
required: true
|
| 87 |
+
- type: textarea
|
| 88 |
+
id: misc
|
| 89 |
+
attributes:
|
| 90 |
+
label: Additional information
|
| 91 |
+
description: Please provide us with any relevant additional info or context.
|
sd-webui-controlnet-main/.github/ISSUE_TEMPLATE/config.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
blank_issues_enabled: true
|
sd-webui-controlnet-main/.github/workflows/tests.yml
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Run basic features tests on CPU
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
- push
|
| 5 |
+
- pull_request
|
| 6 |
+
|
| 7 |
+
jobs:
|
| 8 |
+
build:
|
| 9 |
+
runs-on: ubuntu-latest
|
| 10 |
+
steps:
|
| 11 |
+
- name: Checkout Code
|
| 12 |
+
uses: actions/checkout@v3
|
| 13 |
+
with:
|
| 14 |
+
repository: 'AUTOMATIC1111/stable-diffusion-webui'
|
| 15 |
+
path: 'stable-diffusion-webui'
|
| 16 |
+
ref: '4afaaf8a020c1df457bcf7250cb1c7f609699fa7'
|
| 17 |
+
- name: Checkout Code
|
| 18 |
+
uses: actions/checkout@v3
|
| 19 |
+
with:
|
| 20 |
+
repository: 'Mikubill/sd-webui-controlnet'
|
| 21 |
+
path: 'stable-diffusion-webui/extensions/sd-webui-controlnet'
|
| 22 |
+
- name: Set up Python 3.10
|
| 23 |
+
uses: actions/setup-python@v4
|
| 24 |
+
with:
|
| 25 |
+
python-version: 3.10.6
|
| 26 |
+
cache: pip
|
| 27 |
+
cache-dependency-path: |
|
| 28 |
+
**/requirements*txt
|
| 29 |
+
launch.py
|
| 30 |
+
- name: Install test dependencies
|
| 31 |
+
run: |
|
| 32 |
+
pip install wait-for-it
|
| 33 |
+
pip install -r requirements-test.txt
|
| 34 |
+
working-directory: stable-diffusion-webui
|
| 35 |
+
env:
|
| 36 |
+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
| 37 |
+
PIP_PROGRESS_BAR: "off"
|
| 38 |
+
- name: Setup environment
|
| 39 |
+
run: python launch.py --skip-torch-cuda-test --exit
|
| 40 |
+
working-directory: stable-diffusion-webui
|
| 41 |
+
env:
|
| 42 |
+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
|
| 43 |
+
PIP_PROGRESS_BAR: "off"
|
| 44 |
+
TORCH_INDEX_URL: https://download.pytorch.org/whl/cpu
|
| 45 |
+
WEBUI_LAUNCH_LIVE_OUTPUT: "1"
|
| 46 |
+
PYTHONUNBUFFERED: "1"
|
| 47 |
+
- name: Cache ControlNet models
|
| 48 |
+
uses: actions/cache@v3
|
| 49 |
+
with:
|
| 50 |
+
path: stable-diffusion-webui/extensions/sd-webui-controlnet/models/
|
| 51 |
+
key: controlnet-models-v2
|
| 52 |
+
- name: Cache Preprocessor models
|
| 53 |
+
uses: actions/cache@v3
|
| 54 |
+
with:
|
| 55 |
+
path: stable-diffusion-webui/extensions/sd-webui-controlnet/annotator/downloads/
|
| 56 |
+
key: preprocessor-models-v1
|
| 57 |
+
- name: Download controlnet model for testing
|
| 58 |
+
run: |
|
| 59 |
+
declare -a urls=(
|
| 60 |
+
"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth"
|
| 61 |
+
"https://huggingface.co/h94/IP-Adapter/resolve/main/models/ip-adapter-full-face_sd15.safetensors"
|
| 62 |
+
"https://huggingface.co/h94/IP-Adapter/resolve/main/models/ip-adapter-plus-face_sd15.safetensors"
|
| 63 |
+
"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_canny_sd15v2.pth"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
for url in "${urls[@]}"; do
|
| 67 |
+
filename="extensions/sd-webui-controlnet/models/${url##*/}" # Extracts the last part of the URL
|
| 68 |
+
if [ ! -f "$filename" ]; then
|
| 69 |
+
curl -Lo "$filename" "$url"
|
| 70 |
+
fi
|
| 71 |
+
done
|
| 72 |
+
working-directory: stable-diffusion-webui
|
| 73 |
+
- name: Start test server
|
| 74 |
+
run: >
|
| 75 |
+
python -m coverage run
|
| 76 |
+
--data-file=.coverage.server
|
| 77 |
+
launch.py
|
| 78 |
+
--skip-prepare-environment
|
| 79 |
+
--skip-torch-cuda-test
|
| 80 |
+
--test-server
|
| 81 |
+
--do-not-download-clip
|
| 82 |
+
--no-half
|
| 83 |
+
--disable-opt-split-attention
|
| 84 |
+
--use-cpu all
|
| 85 |
+
--api-server-stop
|
| 86 |
+
2>&1 | tee output.txt &
|
| 87 |
+
working-directory: stable-diffusion-webui
|
| 88 |
+
- name: Run tests
|
| 89 |
+
run: |
|
| 90 |
+
wait-for-it --service 127.0.0.1:7860 -t 600
|
| 91 |
+
python -m pytest -vv --junitxml=test/results.xml --cov ./extensions/sd-webui-controlnet --cov-report=xml --verify-base-url ./extensions/sd-webui-controlnet/tests
|
| 92 |
+
working-directory: stable-diffusion-webui
|
| 93 |
+
- name: Kill test server
|
| 94 |
+
if: always()
|
| 95 |
+
run: curl -vv -XPOST http://127.0.0.1:7860/sdapi/v1/server-stop && sleep 10
|
| 96 |
+
- name: Show coverage
|
| 97 |
+
run: |
|
| 98 |
+
python -m coverage combine .coverage*
|
| 99 |
+
python -m coverage report -i
|
| 100 |
+
python -m coverage html -i
|
| 101 |
+
working-directory: stable-diffusion-webui
|
| 102 |
+
- name: Upload main app output
|
| 103 |
+
uses: actions/upload-artifact@v3
|
| 104 |
+
if: always()
|
| 105 |
+
with:
|
| 106 |
+
name: output
|
| 107 |
+
path: stable-diffusion-webui/output.txt
|
| 108 |
+
- name: Upload coverage HTML
|
| 109 |
+
uses: actions/upload-artifact@v3
|
| 110 |
+
if: always()
|
| 111 |
+
with:
|
| 112 |
+
name: htmlcov
|
| 113 |
+
path: stable-diffusion-webui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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Byte-compiled / optimized / DLL files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# poetry
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 102 |
+
#poetry.lock
|
| 103 |
+
|
| 104 |
+
# pdm
|
| 105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 106 |
+
#pdm.lock
|
| 107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 108 |
+
# in version control.
|
| 109 |
+
# https://pdm.fming.dev/#use-with-ide
|
| 110 |
+
.pdm.toml
|
| 111 |
+
|
| 112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 113 |
+
__pypackages__/
|
| 114 |
+
|
| 115 |
+
# Celery stuff
|
| 116 |
+
celerybeat-schedule
|
| 117 |
+
celerybeat.pid
|
| 118 |
+
|
| 119 |
+
# SageMath parsed files
|
| 120 |
+
*.sage.py
|
| 121 |
+
|
| 122 |
+
# Environments
|
| 123 |
+
.env
|
| 124 |
+
.venv
|
| 125 |
+
env/
|
| 126 |
+
venv/
|
| 127 |
+
ENV/
|
| 128 |
+
env.bak/
|
| 129 |
+
venv.bak/
|
| 130 |
+
|
| 131 |
+
# Spyder project settings
|
| 132 |
+
.spyderproject
|
| 133 |
+
.spyproject
|
| 134 |
+
|
| 135 |
+
# Rope project settings
|
| 136 |
+
.ropeproject
|
| 137 |
+
|
| 138 |
+
# mkdocs documentation
|
| 139 |
+
/site
|
| 140 |
+
|
| 141 |
+
# mypy
|
| 142 |
+
.mypy_cache/
|
| 143 |
+
.dmypy.json
|
| 144 |
+
dmypy.json
|
| 145 |
+
|
| 146 |
+
# Pyre type checker
|
| 147 |
+
.pyre/
|
| 148 |
+
|
| 149 |
+
# pytype static type analyzer
|
| 150 |
+
.pytype/
|
| 151 |
+
|
| 152 |
+
# Cython debug symbols
|
| 153 |
+
cython_debug/
|
| 154 |
+
|
| 155 |
+
# PyCharm
|
| 156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
+
#.idea
|
| 161 |
+
*.pt
|
| 162 |
+
*.pth
|
| 163 |
+
*.ckpt
|
| 164 |
+
*.bin
|
| 165 |
+
*.safetensors
|
| 166 |
+
|
| 167 |
+
# Editor setting metadata
|
| 168 |
+
.idea/
|
| 169 |
+
.vscode/
|
| 170 |
+
detected_maps/
|
| 171 |
+
annotator/downloads/
|
| 172 |
+
|
| 173 |
+
# test results and expectations
|
| 174 |
+
web_tests/results/
|
| 175 |
+
web_tests/expectations/
|
| 176 |
+
*_diff.png
|
| 177 |
+
|
| 178 |
+
# Presets
|
| 179 |
+
presets/
|
sd-webui-controlnet-main/LICENSE
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
GNU GENERAL PUBLIC LICENSE
|
| 2 |
+
Version 3, 29 June 2007
|
| 3 |
+
|
| 4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
| 5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 6 |
+
of this license document, but changing it is not allowed.
|
| 7 |
+
|
| 8 |
+
Preamble
|
| 9 |
+
|
| 10 |
+
The GNU General Public License is a free, copyleft license for
|
| 11 |
+
software and other kinds of works.
|
| 12 |
+
|
| 13 |
+
The licenses for most software and other practical works are designed
|
| 14 |
+
to take away your freedom to share and change the works. By contrast,
|
| 15 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 16 |
+
share and change all versions of a program--to make sure it remains free
|
| 17 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 18 |
+
GNU General Public License for most of our software; it applies also to
|
| 19 |
+
any other work released this way by its authors. You can apply it to
|
| 20 |
+
your programs, too.
|
| 21 |
+
|
| 22 |
+
When we speak of free software, we are referring to freedom, not
|
| 23 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 24 |
+
have the freedom to distribute copies of free software (and charge for
|
| 25 |
+
them if you wish), that you receive source code or can get it if you
|
| 26 |
+
want it, that you can change the software or use pieces of it in new
|
| 27 |
+
free programs, and that you know you can do these things.
|
| 28 |
+
|
| 29 |
+
To protect your rights, we need to prevent others from denying you
|
| 30 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 31 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 32 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 33 |
+
|
| 34 |
+
For example, if you distribute copies of such a program, whether
|
| 35 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 36 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 37 |
+
or can get the source code. And you must show them these terms so they
|
| 38 |
+
know their rights.
|
| 39 |
+
|
| 40 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 41 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 42 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 43 |
+
|
| 44 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 45 |
+
that there is no warranty for this free software. For both users' and
|
| 46 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 47 |
+
changed, so that their problems will not be attributed erroneously to
|
| 48 |
+
authors of previous versions.
|
| 49 |
+
|
| 50 |
+
Some devices are designed to deny users access to install or run
|
| 51 |
+
modified versions of the software inside them, although the manufacturer
|
| 52 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 53 |
+
protecting users' freedom to change the software. The systematic
|
| 54 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 55 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 56 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 57 |
+
products. If such problems arise substantially in other domains, we
|
| 58 |
+
stand ready to extend this provision to those domains in future versions
|
| 59 |
+
of the GPL, as needed to protect the freedom of users.
|
| 60 |
+
|
| 61 |
+
Finally, every program is threatened constantly by software patents.
|
| 62 |
+
States should not allow patents to restrict development and use of
|
| 63 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 64 |
+
avoid the special danger that patents applied to a free program could
|
| 65 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 66 |
+
patents cannot be used to render the program non-free.
|
| 67 |
+
|
| 68 |
+
The precise terms and conditions for copying, distribution and
|
| 69 |
+
modification follow.
|
| 70 |
+
|
| 71 |
+
TERMS AND CONDITIONS
|
| 72 |
+
|
| 73 |
+
0. Definitions.
|
| 74 |
+
|
| 75 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 76 |
+
|
| 77 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 78 |
+
works, such as semiconductor masks.
|
| 79 |
+
|
| 80 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 81 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 82 |
+
"recipients" may be individuals or organizations.
|
| 83 |
+
|
| 84 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 85 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 86 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 87 |
+
earlier work or a work "based on" the earlier work.
|
| 88 |
+
|
| 89 |
+
A "covered work" means either the unmodified Program or a work based
|
| 90 |
+
on the Program.
|
| 91 |
+
|
| 92 |
+
To "propagate" a work means to do anything with it that, without
|
| 93 |
+
permission, would make you directly or secondarily liable for
|
| 94 |
+
infringement under applicable copyright law, except executing it on a
|
| 95 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 96 |
+
distribution (with or without modification), making available to the
|
| 97 |
+
public, and in some countries other activities as well.
|
| 98 |
+
|
| 99 |
+
To "convey" a work means any kind of propagation that enables other
|
| 100 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 101 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 102 |
+
|
| 103 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 104 |
+
to the extent that it includes a convenient and prominently visible
|
| 105 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 106 |
+
tells the user that there is no warranty for the work (except to the
|
| 107 |
+
extent that warranties are provided), that licensees may convey the
|
| 108 |
+
work under this License, and how to view a copy of this License. If
|
| 109 |
+
the interface presents a list of user commands or options, such as a
|
| 110 |
+
menu, a prominent item in the list meets this criterion.
|
| 111 |
+
|
| 112 |
+
1. Source Code.
|
| 113 |
+
|
| 114 |
+
The "source code" for a work means the preferred form of the work
|
| 115 |
+
for making modifications to it. "Object code" means any non-source
|
| 116 |
+
form of a work.
|
| 117 |
+
|
| 118 |
+
A "Standard Interface" means an interface that either is an official
|
| 119 |
+
standard defined by a recognized standards body, or, in the case of
|
| 120 |
+
interfaces specified for a particular programming language, one that
|
| 121 |
+
is widely used among developers working in that language.
|
| 122 |
+
|
| 123 |
+
The "System Libraries" of an executable work include anything, other
|
| 124 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 125 |
+
packaging a Major Component, but which is not part of that Major
|
| 126 |
+
Component, and (b) serves only to enable use of the work with that
|
| 127 |
+
Major Component, or to implement a Standard Interface for which an
|
| 128 |
+
implementation is available to the public in source code form. A
|
| 129 |
+
"Major Component", in this context, means a major essential component
|
| 130 |
+
(kernel, window system, and so on) of the specific operating system
|
| 131 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 132 |
+
produce the work, or an object code interpreter used to run it.
|
| 133 |
+
|
| 134 |
+
The "Corresponding Source" for a work in object code form means all
|
| 135 |
+
the source code needed to generate, install, and (for an executable
|
| 136 |
+
work) run the object code and to modify the work, including scripts to
|
| 137 |
+
control those activities. However, it does not include the work's
|
| 138 |
+
System Libraries, or general-purpose tools or generally available free
|
| 139 |
+
programs which are used unmodified in performing those activities but
|
| 140 |
+
which are not part of the work. For example, Corresponding Source
|
| 141 |
+
includes interface definition files associated with source files for
|
| 142 |
+
the work, and the source code for shared libraries and dynamically
|
| 143 |
+
linked subprograms that the work is specifically designed to require,
|
| 144 |
+
such as by intimate data communication or control flow between those
|
| 145 |
+
subprograms and other parts of the work.
|
| 146 |
+
|
| 147 |
+
The Corresponding Source need not include anything that users
|
| 148 |
+
can regenerate automatically from other parts of the Corresponding
|
| 149 |
+
Source.
|
| 150 |
+
|
| 151 |
+
The Corresponding Source for a work in source code form is that
|
| 152 |
+
same work.
|
| 153 |
+
|
| 154 |
+
2. Basic Permissions.
|
| 155 |
+
|
| 156 |
+
All rights granted under this License are granted for the term of
|
| 157 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 158 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 159 |
+
permission to run the unmodified Program. The output from running a
|
| 160 |
+
covered work is covered by this License only if the output, given its
|
| 161 |
+
content, constitutes a covered work. This License acknowledges your
|
| 162 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 163 |
+
|
| 164 |
+
You may make, run and propagate covered works that you do not
|
| 165 |
+
convey, without conditions so long as your license otherwise remains
|
| 166 |
+
in force. You may convey covered works to others for the sole purpose
|
| 167 |
+
of having them make modifications exclusively for you, or provide you
|
| 168 |
+
with facilities for running those works, provided that you comply with
|
| 169 |
+
the terms of this License in conveying all material for which you do
|
| 170 |
+
not control copyright. Those thus making or running the covered works
|
| 171 |
+
for you must do so exclusively on your behalf, under your direction
|
| 172 |
+
and control, on terms that prohibit them from making any copies of
|
| 173 |
+
your copyrighted material outside their relationship with you.
|
| 174 |
+
|
| 175 |
+
Conveying under any other circumstances is permitted solely under
|
| 176 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 177 |
+
makes it unnecessary.
|
| 178 |
+
|
| 179 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 180 |
+
|
| 181 |
+
No covered work shall be deemed part of an effective technological
|
| 182 |
+
measure under any applicable law fulfilling obligations under article
|
| 183 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 184 |
+
similar laws prohibiting or restricting circumvention of such
|
| 185 |
+
measures.
|
| 186 |
+
|
| 187 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 188 |
+
circumvention of technological measures to the extent such circumvention
|
| 189 |
+
is effected by exercising rights under this License with respect to
|
| 190 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 191 |
+
modification of the work as a means of enforcing, against the work's
|
| 192 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 193 |
+
technological measures.
|
| 194 |
+
|
| 195 |
+
4. Conveying Verbatim Copies.
|
| 196 |
+
|
| 197 |
+
You may convey verbatim copies of the Program's source code as you
|
| 198 |
+
receive it, in any medium, provided that you conspicuously and
|
| 199 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 200 |
+
keep intact all notices stating that this License and any
|
| 201 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 202 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 203 |
+
recipients a copy of this License along with the Program.
|
| 204 |
+
|
| 205 |
+
You may charge any price or no price for each copy that you convey,
|
| 206 |
+
and you may offer support or warranty protection for a fee.
|
| 207 |
+
|
| 208 |
+
5. Conveying Modified Source Versions.
|
| 209 |
+
|
| 210 |
+
You may convey a work based on the Program, or the modifications to
|
| 211 |
+
produce it from the Program, in the form of source code under the
|
| 212 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 213 |
+
|
| 214 |
+
a) The work must carry prominent notices stating that you modified
|
| 215 |
+
it, and giving a relevant date.
|
| 216 |
+
|
| 217 |
+
b) The work must carry prominent notices stating that it is
|
| 218 |
+
released under this License and any conditions added under section
|
| 219 |
+
7. This requirement modifies the requirement in section 4 to
|
| 220 |
+
"keep intact all notices".
|
| 221 |
+
|
| 222 |
+
c) You must license the entire work, as a whole, under this
|
| 223 |
+
License to anyone who comes into possession of a copy. This
|
| 224 |
+
License will therefore apply, along with any applicable section 7
|
| 225 |
+
additional terms, to the whole of the work, and all its parts,
|
| 226 |
+
regardless of how they are packaged. This License gives no
|
| 227 |
+
permission to license the work in any other way, but it does not
|
| 228 |
+
invalidate such permission if you have separately received it.
|
| 229 |
+
|
| 230 |
+
d) If the work has interactive user interfaces, each must display
|
| 231 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 232 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 233 |
+
work need not make them do so.
|
| 234 |
+
|
| 235 |
+
A compilation of a covered work with other separate and independent
|
| 236 |
+
works, which are not by their nature extensions of the covered work,
|
| 237 |
+
and which are not combined with it such as to form a larger program,
|
| 238 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 239 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 240 |
+
used to limit the access or legal rights of the compilation's users
|
| 241 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 242 |
+
in an aggregate does not cause this License to apply to the other
|
| 243 |
+
parts of the aggregate.
|
| 244 |
+
|
| 245 |
+
6. Conveying Non-Source Forms.
|
| 246 |
+
|
| 247 |
+
You may convey a covered work in object code form under the terms
|
| 248 |
+
of sections 4 and 5, provided that you also convey the
|
| 249 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 250 |
+
in one of these ways:
|
| 251 |
+
|
| 252 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 253 |
+
(including a physical distribution medium), accompanied by the
|
| 254 |
+
Corresponding Source fixed on a durable physical medium
|
| 255 |
+
customarily used for software interchange.
|
| 256 |
+
|
| 257 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 258 |
+
(including a physical distribution medium), accompanied by a
|
| 259 |
+
written offer, valid for at least three years and valid for as
|
| 260 |
+
long as you offer spare parts or customer support for that product
|
| 261 |
+
model, to give anyone who possesses the object code either (1) a
|
| 262 |
+
copy of the Corresponding Source for all the software in the
|
| 263 |
+
product that is covered by this License, on a durable physical
|
| 264 |
+
medium customarily used for software interchange, for a price no
|
| 265 |
+
more than your reasonable cost of physically performing this
|
| 266 |
+
conveying of source, or (2) access to copy the
|
| 267 |
+
Corresponding Source from a network server at no charge.
|
| 268 |
+
|
| 269 |
+
c) Convey individual copies of the object code with a copy of the
|
| 270 |
+
written offer to provide the Corresponding Source. This
|
| 271 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 272 |
+
only if you received the object code with such an offer, in accord
|
| 273 |
+
with subsection 6b.
|
| 274 |
+
|
| 275 |
+
d) Convey the object code by offering access from a designated
|
| 276 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 277 |
+
Corresponding Source in the same way through the same place at no
|
| 278 |
+
further charge. You need not require recipients to copy the
|
| 279 |
+
Corresponding Source along with the object code. If the place to
|
| 280 |
+
copy the object code is a network server, the Corresponding Source
|
| 281 |
+
may be on a different server (operated by you or a third party)
|
| 282 |
+
that supports equivalent copying facilities, provided you maintain
|
| 283 |
+
clear directions next to the object code saying where to find the
|
| 284 |
+
Corresponding Source. Regardless of what server hosts the
|
| 285 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 286 |
+
available for as long as needed to satisfy these requirements.
|
| 287 |
+
|
| 288 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 289 |
+
you inform other peers where the object code and Corresponding
|
| 290 |
+
Source of the work are being offered to the general public at no
|
| 291 |
+
charge under subsection 6d.
|
| 292 |
+
|
| 293 |
+
A separable portion of the object code, whose source code is excluded
|
| 294 |
+
from the Corresponding Source as a System Library, need not be
|
| 295 |
+
included in conveying the object code work.
|
| 296 |
+
|
| 297 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 298 |
+
tangible personal property which is normally used for personal, family,
|
| 299 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 300 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 301 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 302 |
+
product received by a particular user, "normally used" refers to a
|
| 303 |
+
typical or common use of that class of product, regardless of the status
|
| 304 |
+
of the particular user or of the way in which the particular user
|
| 305 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 306 |
+
is a consumer product regardless of whether the product has substantial
|
| 307 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 308 |
+
the only significant mode of use of the product.
|
| 309 |
+
|
| 310 |
+
"Installation Information" for a User Product means any methods,
|
| 311 |
+
procedures, authorization keys, or other information required to install
|
| 312 |
+
and execute modified versions of a covered work in that User Product from
|
| 313 |
+
a modified version of its Corresponding Source. The information must
|
| 314 |
+
suffice to ensure that the continued functioning of the modified object
|
| 315 |
+
code is in no case prevented or interfered with solely because
|
| 316 |
+
modification has been made.
|
| 317 |
+
|
| 318 |
+
If you convey an object code work under this section in, or with, or
|
| 319 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 320 |
+
part of a transaction in which the right of possession and use of the
|
| 321 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 322 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 323 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 324 |
+
by the Installation Information. But this requirement does not apply
|
| 325 |
+
if neither you nor any third party retains the ability to install
|
| 326 |
+
modified object code on the User Product (for example, the work has
|
| 327 |
+
been installed in ROM).
|
| 328 |
+
|
| 329 |
+
The requirement to provide Installation Information does not include a
|
| 330 |
+
requirement to continue to provide support service, warranty, or updates
|
| 331 |
+
for a work that has been modified or installed by the recipient, or for
|
| 332 |
+
the User Product in which it has been modified or installed. Access to a
|
| 333 |
+
network may be denied when the modification itself materially and
|
| 334 |
+
adversely affects the operation of the network or violates the rules and
|
| 335 |
+
protocols for communication across the network.
|
| 336 |
+
|
| 337 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 338 |
+
in accord with this section must be in a format that is publicly
|
| 339 |
+
documented (and with an implementation available to the public in
|
| 340 |
+
source code form), and must require no special password or key for
|
| 341 |
+
unpacking, reading or copying.
|
| 342 |
+
|
| 343 |
+
7. Additional Terms.
|
| 344 |
+
|
| 345 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 346 |
+
License by making exceptions from one or more of its conditions.
|
| 347 |
+
Additional permissions that are applicable to the entire Program shall
|
| 348 |
+
be treated as though they were included in this License, to the extent
|
| 349 |
+
that they are valid under applicable law. If additional permissions
|
| 350 |
+
apply only to part of the Program, that part may be used separately
|
| 351 |
+
under those permissions, but the entire Program remains governed by
|
| 352 |
+
this License without regard to the additional permissions.
|
| 353 |
+
|
| 354 |
+
When you convey a copy of a covered work, you may at your option
|
| 355 |
+
remove any additional permissions from that copy, or from any part of
|
| 356 |
+
it. (Additional permissions may be written to require their own
|
| 357 |
+
removal in certain cases when you modify the work.) You may place
|
| 358 |
+
additional permissions on material, added by you to a covered work,
|
| 359 |
+
for which you have or can give appropriate copyright permission.
|
| 360 |
+
|
| 361 |
+
Notwithstanding any other provision of this License, for material you
|
| 362 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 363 |
+
that material) supplement the terms of this License with terms:
|
| 364 |
+
|
| 365 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 366 |
+
terms of sections 15 and 16 of this License; or
|
| 367 |
+
|
| 368 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 369 |
+
author attributions in that material or in the Appropriate Legal
|
| 370 |
+
Notices displayed by works containing it; or
|
| 371 |
+
|
| 372 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 373 |
+
requiring that modified versions of such material be marked in
|
| 374 |
+
reasonable ways as different from the original version; or
|
| 375 |
+
|
| 376 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 377 |
+
authors of the material; or
|
| 378 |
+
|
| 379 |
+
e) Declining to grant rights under trademark law for use of some
|
| 380 |
+
trade names, trademarks, or service marks; or
|
| 381 |
+
|
| 382 |
+
f) Requiring indemnification of licensors and authors of that
|
| 383 |
+
material by anyone who conveys the material (or modified versions of
|
| 384 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 385 |
+
any liability that these contractual assumptions directly impose on
|
| 386 |
+
those licensors and authors.
|
| 387 |
+
|
| 388 |
+
All other non-permissive additional terms are considered "further
|
| 389 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 390 |
+
received it, or any part of it, contains a notice stating that it is
|
| 391 |
+
governed by this License along with a term that is a further
|
| 392 |
+
restriction, you may remove that term. If a license document contains
|
| 393 |
+
a further restriction but permits relicensing or conveying under this
|
| 394 |
+
License, you may add to a covered work material governed by the terms
|
| 395 |
+
of that license document, provided that the further restriction does
|
| 396 |
+
not survive such relicensing or conveying.
|
| 397 |
+
|
| 398 |
+
If you add terms to a covered work in accord with this section, you
|
| 399 |
+
must place, in the relevant source files, a statement of the
|
| 400 |
+
additional terms that apply to those files, or a notice indicating
|
| 401 |
+
where to find the applicable terms.
|
| 402 |
+
|
| 403 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 404 |
+
form of a separately written license, or stated as exceptions;
|
| 405 |
+
the above requirements apply either way.
|
| 406 |
+
|
| 407 |
+
8. Termination.
|
| 408 |
+
|
| 409 |
+
You may not propagate or modify a covered work except as expressly
|
| 410 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 411 |
+
modify it is void, and will automatically terminate your rights under
|
| 412 |
+
this License (including any patent licenses granted under the third
|
| 413 |
+
paragraph of section 11).
|
| 414 |
+
|
| 415 |
+
However, if you cease all violation of this License, then your
|
| 416 |
+
license from a particular copyright holder is reinstated (a)
|
| 417 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 418 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 419 |
+
holder fails to notify you of the violation by some reasonable means
|
| 420 |
+
prior to 60 days after the cessation.
|
| 421 |
+
|
| 422 |
+
Moreover, your license from a particular copyright holder is
|
| 423 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 424 |
+
violation by some reasonable means, this is the first time you have
|
| 425 |
+
received notice of violation of this License (for any work) from that
|
| 426 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 427 |
+
your receipt of the notice.
|
| 428 |
+
|
| 429 |
+
Termination of your rights under this section does not terminate the
|
| 430 |
+
licenses of parties who have received copies or rights from you under
|
| 431 |
+
this License. If your rights have been terminated and not permanently
|
| 432 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 433 |
+
material under section 10.
|
| 434 |
+
|
| 435 |
+
9. Acceptance Not Required for Having Copies.
|
| 436 |
+
|
| 437 |
+
You are not required to accept this License in order to receive or
|
| 438 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 439 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 440 |
+
to receive a copy likewise does not require acceptance. However,
|
| 441 |
+
nothing other than this License grants you permission to propagate or
|
| 442 |
+
modify any covered work. These actions infringe copyright if you do
|
| 443 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 444 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 445 |
+
|
| 446 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 447 |
+
|
| 448 |
+
Each time you convey a covered work, the recipient automatically
|
| 449 |
+
receives a license from the original licensors, to run, modify and
|
| 450 |
+
propagate that work, subject to this License. You are not responsible
|
| 451 |
+
for enforcing compliance by third parties with this License.
|
| 452 |
+
|
| 453 |
+
An "entity transaction" is a transaction transferring control of an
|
| 454 |
+
organization, or substantially all assets of one, or subdividing an
|
| 455 |
+
organization, or merging organizations. If propagation of a covered
|
| 456 |
+
work results from an entity transaction, each party to that
|
| 457 |
+
transaction who receives a copy of the work also receives whatever
|
| 458 |
+
licenses to the work the party's predecessor in interest had or could
|
| 459 |
+
give under the previous paragraph, plus a right to possession of the
|
| 460 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 461 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 462 |
+
|
| 463 |
+
You may not impose any further restrictions on the exercise of the
|
| 464 |
+
rights granted or affirmed under this License. For example, you may
|
| 465 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 466 |
+
rights granted under this License, and you may not initiate litigation
|
| 467 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 468 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 469 |
+
sale, or importing the Program or any portion of it.
|
| 470 |
+
|
| 471 |
+
11. Patents.
|
| 472 |
+
|
| 473 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 474 |
+
License of the Program or a work on which the Program is based. The
|
| 475 |
+
work thus licensed is called the contributor's "contributor version".
|
| 476 |
+
|
| 477 |
+
A contributor's "essential patent claims" are all patent claims
|
| 478 |
+
owned or controlled by the contributor, whether already acquired or
|
| 479 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 480 |
+
by this License, of making, using, or selling its contributor version,
|
| 481 |
+
but do not include claims that would be infringed only as a
|
| 482 |
+
consequence of further modification of the contributor version. For
|
| 483 |
+
purposes of this definition, "control" includes the right to grant
|
| 484 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 485 |
+
this License.
|
| 486 |
+
|
| 487 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 488 |
+
patent license under the contributor's essential patent claims, to
|
| 489 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 490 |
+
propagate the contents of its contributor version.
|
| 491 |
+
|
| 492 |
+
In the following three paragraphs, a "patent license" is any express
|
| 493 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 494 |
+
(such as an express permission to practice a patent or covenant not to
|
| 495 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 496 |
+
party means to make such an agreement or commitment not to enforce a
|
| 497 |
+
patent against the party.
|
| 498 |
+
|
| 499 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 500 |
+
and the Corresponding Source of the work is not available for anyone
|
| 501 |
+
to copy, free of charge and under the terms of this License, through a
|
| 502 |
+
publicly available network server or other readily accessible means,
|
| 503 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 504 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 505 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 506 |
+
consistent with the requirements of this License, to extend the patent
|
| 507 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 508 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 509 |
+
covered work in a country, or your recipient's use of the covered work
|
| 510 |
+
in a country, would infringe one or more identifiable patents in that
|
| 511 |
+
country that you have reason to believe are valid.
|
| 512 |
+
|
| 513 |
+
If, pursuant to or in connection with a single transaction or
|
| 514 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 515 |
+
covered work, and grant a patent license to some of the parties
|
| 516 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 517 |
+
or convey a specific copy of the covered work, then the patent license
|
| 518 |
+
you grant is automatically extended to all recipients of the covered
|
| 519 |
+
work and works based on it.
|
| 520 |
+
|
| 521 |
+
A patent license is "discriminatory" if it does not include within
|
| 522 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 523 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 524 |
+
specifically granted under this License. You may not convey a covered
|
| 525 |
+
work if you are a party to an arrangement with a third party that is
|
| 526 |
+
in the business of distributing software, under which you make payment
|
| 527 |
+
to the third party based on the extent of your activity of conveying
|
| 528 |
+
the work, and under which the third party grants, to any of the
|
| 529 |
+
parties who would receive the covered work from you, a discriminatory
|
| 530 |
+
patent license (a) in connection with copies of the covered work
|
| 531 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 532 |
+
for and in connection with specific products or compilations that
|
| 533 |
+
contain the covered work, unless you entered into that arrangement,
|
| 534 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 535 |
+
|
| 536 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 537 |
+
any implied license or other defenses to infringement that may
|
| 538 |
+
otherwise be available to you under applicable patent law.
|
| 539 |
+
|
| 540 |
+
12. No Surrender of Others' Freedom.
|
| 541 |
+
|
| 542 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 543 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 544 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 545 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 546 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 547 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 548 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 549 |
+
the Program, the only way you could satisfy both those terms and this
|
| 550 |
+
License would be to refrain entirely from conveying the Program.
|
| 551 |
+
|
| 552 |
+
13. Use with the GNU Affero General Public License.
|
| 553 |
+
|
| 554 |
+
Notwithstanding any other provision of this License, you have
|
| 555 |
+
permission to link or combine any covered work with a work licensed
|
| 556 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 557 |
+
combined work, and to convey the resulting work. The terms of this
|
| 558 |
+
License will continue to apply to the part which is the covered work,
|
| 559 |
+
but the special requirements of the GNU Affero General Public License,
|
| 560 |
+
section 13, concerning interaction through a network will apply to the
|
| 561 |
+
combination as such.
|
| 562 |
+
|
| 563 |
+
14. Revised Versions of this License.
|
| 564 |
+
|
| 565 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 566 |
+
the GNU General Public License from time to time. Such new versions will
|
| 567 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 568 |
+
address new problems or concerns.
|
| 569 |
+
|
| 570 |
+
Each version is given a distinguishing version number. If the
|
| 571 |
+
Program specifies that a certain numbered version of the GNU General
|
| 572 |
+
Public License "or any later version" applies to it, you have the
|
| 573 |
+
option of following the terms and conditions either of that numbered
|
| 574 |
+
version or of any later version published by the Free Software
|
| 575 |
+
Foundation. If the Program does not specify a version number of the
|
| 576 |
+
GNU General Public License, you may choose any version ever published
|
| 577 |
+
by the Free Software Foundation.
|
| 578 |
+
|
| 579 |
+
If the Program specifies that a proxy can decide which future
|
| 580 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 581 |
+
public statement of acceptance of a version permanently authorizes you
|
| 582 |
+
to choose that version for the Program.
|
| 583 |
+
|
| 584 |
+
Later license versions may give you additional or different
|
| 585 |
+
permissions. However, no additional obligations are imposed on any
|
| 586 |
+
author or copyright holder as a result of your choosing to follow a
|
| 587 |
+
later version.
|
| 588 |
+
|
| 589 |
+
15. Disclaimer of Warranty.
|
| 590 |
+
|
| 591 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 592 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 593 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 594 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 595 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 596 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 597 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 598 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 599 |
+
|
| 600 |
+
16. Limitation of Liability.
|
| 601 |
+
|
| 602 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 603 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 604 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 605 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 606 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 607 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 608 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 609 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 610 |
+
SUCH DAMAGES.
|
| 611 |
+
|
| 612 |
+
17. Interpretation of Sections 15 and 16.
|
| 613 |
+
|
| 614 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 615 |
+
above cannot be given local legal effect according to their terms,
|
| 616 |
+
reviewing courts shall apply local law that most closely approximates
|
| 617 |
+
an absolute waiver of all civil liability in connection with the
|
| 618 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 619 |
+
copy of the Program in return for a fee.
|
| 620 |
+
|
| 621 |
+
END OF TERMS AND CONDITIONS
|
| 622 |
+
|
| 623 |
+
How to Apply These Terms to Your New Programs
|
| 624 |
+
|
| 625 |
+
If you develop a new program, and you want it to be of the greatest
|
| 626 |
+
possible use to the public, the best way to achieve this is to make it
|
| 627 |
+
free software which everyone can redistribute and change under these terms.
|
| 628 |
+
|
| 629 |
+
To do so, attach the following notices to the program. It is safest
|
| 630 |
+
to attach them to the start of each source file to most effectively
|
| 631 |
+
state the exclusion of warranty; and each file should have at least
|
| 632 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 633 |
+
|
| 634 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 635 |
+
Copyright (C) <year> <name of author>
|
| 636 |
+
|
| 637 |
+
This program is free software: you can redistribute it and/or modify
|
| 638 |
+
it under the terms of the GNU General Public License as published by
|
| 639 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 640 |
+
(at your option) any later version.
|
| 641 |
+
|
| 642 |
+
This program is distributed in the hope that it will be useful,
|
| 643 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 644 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 645 |
+
GNU General Public License for more details.
|
| 646 |
+
|
| 647 |
+
You should have received a copy of the GNU General Public License
|
| 648 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 649 |
+
|
| 650 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 651 |
+
|
| 652 |
+
If the program does terminal interaction, make it output a short
|
| 653 |
+
notice like this when it starts in an interactive mode:
|
| 654 |
+
|
| 655 |
+
<program> Copyright (C) <year> <name of author>
|
| 656 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 657 |
+
This is free software, and you are welcome to redistribute it
|
| 658 |
+
under certain conditions; type `show c' for details.
|
| 659 |
+
|
| 660 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 661 |
+
parts of the General Public License. Of course, your program's commands
|
| 662 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 663 |
+
|
| 664 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 665 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 666 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 667 |
+
<https://www.gnu.org/licenses/>.
|
| 668 |
+
|
| 669 |
+
The GNU General Public License does not permit incorporating your program
|
| 670 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 671 |
+
may consider it more useful to permit linking proprietary applications with
|
| 672 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 673 |
+
Public License instead of this License. But first, please read
|
| 674 |
+
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
sd-webui-controlnet-main/README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ControlNet for Stable Diffusion WebUI
|
| 2 |
+
|
| 3 |
+
The WebUI extension for ControlNet and other injection-based SD controls.
|
| 4 |
+
|
| 5 |
+

|
| 6 |
+
|
| 7 |
+
This extension is for AUTOMATIC1111's [Stable Diffusion web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui), allows the Web UI to add [ControlNet](https://github.com/lllyasviel/ControlNet) to the original Stable Diffusion model to generate images. The addition is on-the-fly, the merging is not required.
|
| 8 |
+
|
| 9 |
+
# Installation
|
| 10 |
+
|
| 11 |
+
1. Open "Extensions" tab.
|
| 12 |
+
2. Open "Install from URL" tab in the tab.
|
| 13 |
+
3. Enter `https://github.com/Mikubill/sd-webui-controlnet.git` to "URL for extension's git repository".
|
| 14 |
+
4. Press "Install" button.
|
| 15 |
+
5. Wait for 5 seconds, and you will see the message "Installed into stable-diffusion-webui\extensions\sd-webui-controlnet. Use Installed tab to restart".
|
| 16 |
+
6. Go to "Installed" tab, click "Check for updates", and then click "Apply and restart UI". (The next time you can also use these buttons to update ControlNet.)
|
| 17 |
+
7. Completely restart A1111 webui including your terminal. (If you do not know what is a "terminal", you can reboot your computer to achieve the same effect.)
|
| 18 |
+
8. Download models (see below).
|
| 19 |
+
9. After you put models in the correct folder, you may need to refresh to see the models. The refresh button is right to your "Model" dropdown.
|
| 20 |
+
|
| 21 |
+
# Download Models
|
| 22 |
+
|
| 23 |
+
Right now all the 14 models of ControlNet 1.1 are in the beta test.
|
| 24 |
+
|
| 25 |
+
Download the models from ControlNet 1.1: https://huggingface.co/lllyasviel/ControlNet-v1-1/tree/main
|
| 26 |
+
|
| 27 |
+
You need to download model files ending with ".pth" .
|
| 28 |
+
|
| 29 |
+
Put models in your "stable-diffusion-webui\extensions\sd-webui-controlnet\models". You only need to download "pth" files.
|
| 30 |
+
|
| 31 |
+
Do not right-click the filenames in HuggingFace website to download. Some users right-clicked those HuggingFace HTML websites and saved those HTML pages as PTH/YAML files. They are not downloading correct files. Instead, please click the small download arrow “↓” icon in HuggingFace to download.
|
| 32 |
+
|
| 33 |
+
# Download Models for SDXL
|
| 34 |
+
|
| 35 |
+
See instructions [here](https://github.com/Mikubill/sd-webui-controlnet/discussions/2039).
|
| 36 |
+
|
| 37 |
+
# Features in ControlNet 1.1
|
| 38 |
+
|
| 39 |
+
### Perfect Support for All ControlNet 1.0/1.1 and T2I Adapter Models.
|
| 40 |
+
|
| 41 |
+
Now we have perfect support all available models and preprocessors, including perfect support for T2I style adapter and ControlNet 1.1 Shuffle. (Make sure that your YAML file names and model file names are same, see also YAML files in "stable-diffusion-webui\extensions\sd-webui-controlnet\models".)
|
| 42 |
+
|
| 43 |
+
### Perfect Support for A1111 High-Res. Fix
|
| 44 |
+
|
| 45 |
+
Now if you turn on High-Res Fix in A1111, each controlnet will output two different control images: a small one and a large one. The small one is for your basic generating, and the big one is for your High-Res Fix generating. The two control images are computed by a smart algorithm called "super high-quality control image resampling". This is turned on by default, and you do not need to change any setting.
|
| 46 |
+
|
| 47 |
+
### Perfect Support for All A1111 Img2Img or Inpaint Settings and All Mask Types
|
| 48 |
+
|
| 49 |
+
Now ControlNet is extensively tested with A1111's different types of masks, including "Inpaint masked"/"Inpaint not masked", and "Whole picture"/"Only masked", and "Only masked padding"&"Mask blur". The resizing perfectly matches A1111's "Just resize"/"Crop and resize"/"Resize and fill". This means you can use ControlNet in nearly everywhere in your A1111 UI without difficulty!
|
| 50 |
+
|
| 51 |
+
### The New "Pixel-Perfect" Mode
|
| 52 |
+
|
| 53 |
+
Now if you turn on pixel-perfect mode, you do not need to set preprocessor (annotator) resolutions manually. The ControlNet will automatically compute the best annotator resolution for you so that each pixel perfectly matches Stable Diffusion.
|
| 54 |
+
|
| 55 |
+
### User-Friendly GUI and Preprocessor Preview
|
| 56 |
+
|
| 57 |
+
We reorganized some previously confusing UI like "canvas width/height for new canvas" and it is in the 📝 button now. Now the preview GUI is controlled by the "allow preview" option and the trigger button 💥. The preview image size is better than before, and you do not need to scroll up and down - your a1111 GUI will not be messed up anymore!
|
| 58 |
+
|
| 59 |
+
### Support for Almost All Upscaling Scripts
|
| 60 |
+
|
| 61 |
+
Now ControlNet 1.1 can support almost all Upscaling/Tile methods. ControlNet 1.1 support the script "Ultimate SD upscale" and almost all other tile-based extensions. Please do not confuse ["Ultimate SD upscale"](https://github.com/Coyote-A/ultimate-upscale-for-automatic1111) with "SD upscale" - they are different scripts. Note that the most recommended upscaling method is ["Tiled VAE/Diffusion"](https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111) but we test as many methods/extensions as possible. Note that "SD upscale" is supported since 1.1.117, and if you use it, you need to leave all ControlNet images as blank (We do not recommend "SD upscale" since it is somewhat buggy and cannot be maintained - use the "Ultimate SD upscale" instead).
|
| 62 |
+
|
| 63 |
+
### More Control Modes (previously called Guess Mode)
|
| 64 |
+
|
| 65 |
+
We have fixed many bugs in previous 1.0’s Guess Mode and now it is called Control Mode
|
| 66 |
+
|
| 67 |
+

|
| 68 |
+
|
| 69 |
+
Now you can control which aspect is more important (your prompt or your ControlNet):
|
| 70 |
+
|
| 71 |
+
* "Balanced": ControlNet on both sides of CFG scale, same as turning off "Guess Mode" in ControlNet 1.0
|
| 72 |
+
|
| 73 |
+
* "My prompt is more important": ControlNet on both sides of CFG scale, with progressively reduced SD U-Net injections (layer_weight*=0.825**I, where 0<=I <13, and the 13 means ControlNet injected SD 13 times). In this way, you can make sure that your prompts are perfectly displayed in your generated images.
|
| 74 |
+
|
| 75 |
+
* "ControlNet is more important": ControlNet only on the Conditional Side of CFG scale (the cond in A1111's batch-cond-uncond). This means the ControlNet will be X times stronger if your cfg-scale is X. For example, if your cfg-scale is 7, then ControlNet is 7 times stronger. Note that here the X times stronger is different from "Control Weights" since your weights are not modified. This "stronger" effect usually has less artifact and give ControlNet more room to guess what is missing from your prompts (and in the previous 1.0, it is called "Guess Mode").
|
| 76 |
+
|
| 77 |
+
<table width="100%">
|
| 78 |
+
<tr>
|
| 79 |
+
<td width="25%" style="text-align: center">Input (depth+canny+hed)</td>
|
| 80 |
+
<td width="25%" style="text-align: center">"Balanced"</td>
|
| 81 |
+
<td width="25%" style="text-align: center">"My prompt is more important"</td>
|
| 82 |
+
<td width="25%" style="text-align: center">"ControlNet is more important"</td>
|
| 83 |
+
</tr>
|
| 84 |
+
<tr>
|
| 85 |
+
<td width="25%" style="text-align: center"><img src="samples/cm1.png"></td>
|
| 86 |
+
<td width="25%" style="text-align: center"><img src="samples/cm2.png"></td>
|
| 87 |
+
<td width="25%" style="text-align: center"><img src="samples/cm3.png"></td>
|
| 88 |
+
<td width="25%" style="text-align: center"><img src="samples/cm4.png"></td>
|
| 89 |
+
</tr>
|
| 90 |
+
</table>
|
| 91 |
+
|
| 92 |
+
### Reference-Only Control
|
| 93 |
+
|
| 94 |
+
Now we have a `reference-only` preprocessor that does not require any control models. It can guide the diffusion directly using images as references.
|
| 95 |
+
|
| 96 |
+
(Prompt "a dog running on grassland, best quality, ...")
|
| 97 |
+
|
| 98 |
+

|
| 99 |
+
|
| 100 |
+
This method is similar to inpaint-based reference but it does not make your image disordered.
|
| 101 |
+
|
| 102 |
+
Many professional A1111 users know a trick to diffuse image with references by inpaint. For example, if you have a 512x512 image of a dog, and want to generate another 512x512 image with the same dog, some users will connect the 512x512 dog image and a 512x512 blank image into a 1024x512 image, send to inpaint, and mask out the blank 512x512 part to diffuse a dog with similar appearance. However, that method is usually not very satisfying since images are connected and many distortions will appear.
|
| 103 |
+
|
| 104 |
+
This `reference-only` ControlNet can directly link the attention layers of your SD to any independent images, so that your SD will read arbitary images for reference. You need at least ControlNet 1.1.153 to use it.
|
| 105 |
+
|
| 106 |
+
To use, just select `reference-only` as preprocessor and put an image. Your SD will just use the image as reference.
|
| 107 |
+
|
| 108 |
+
*Note that this method is as "non-opinioned" as possible. It only contains very basic connection codes, without any personal preferences, to connect the attention layers with your reference images. However, even if we tried best to not include any opinioned codes, we still need to write some subjective implementations to deal with weighting, cfg-scale, etc - tech report is on the way.*
|
| 109 |
+
|
| 110 |
+
More examples [here](https://github.com/Mikubill/sd-webui-controlnet/discussions/1236).
|
| 111 |
+
|
| 112 |
+
# Technical Documents
|
| 113 |
+
|
| 114 |
+
See also the documents of ControlNet 1.1:
|
| 115 |
+
|
| 116 |
+
https://github.com/lllyasviel/ControlNet-v1-1-nightly#model-specification
|
| 117 |
+
|
| 118 |
+
# Default Setting
|
| 119 |
+
|
| 120 |
+
This is my setting. If you run into any problem, you can use this setting as a sanity check
|
| 121 |
+
|
| 122 |
+

|
| 123 |
+
|
| 124 |
+
# Use Previous Models
|
| 125 |
+
|
| 126 |
+
### Use ControlNet 1.0 Models
|
| 127 |
+
|
| 128 |
+
https://huggingface.co/lllyasviel/ControlNet/tree/main/models
|
| 129 |
+
|
| 130 |
+
You can still use all previous models in the previous ControlNet 1.0. Now, the previous "depth" is now called "depth_midas", the previous "normal" is called "normal_midas", the previous "hed" is called "softedge_hed". And starting from 1.1, all line maps, edge maps, lineart maps, boundary maps will have black background and white lines.
|
| 131 |
+
|
| 132 |
+
### Use T2I-Adapter Models
|
| 133 |
+
|
| 134 |
+
(From TencentARC/T2I-Adapter)
|
| 135 |
+
|
| 136 |
+
To use T2I-Adapter models:
|
| 137 |
+
|
| 138 |
+
1. Download files from https://huggingface.co/TencentARC/T2I-Adapter/tree/main/models
|
| 139 |
+
2. Put them in "stable-diffusion-webui\extensions\sd-webui-controlnet\models".
|
| 140 |
+
3. Make sure that the file names of pth files and yaml files are consistent.
|
| 141 |
+
|
| 142 |
+
*Note that "CoAdapter" is not implemented yet.*
|
| 143 |
+
|
| 144 |
+
# Gallery
|
| 145 |
+
|
| 146 |
+
The below results are from ControlNet 1.0.
|
| 147 |
+
|
| 148 |
+
| Source | Input | Output |
|
| 149 |
+
|:-------------------------:|:-------------------------:|:-------------------------:|
|
| 150 |
+
| (no preprocessor) | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/bal-source.png?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/bal-gen.png?raw=true"> |
|
| 151 |
+
| (no preprocessor) | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/dog_rel.jpg?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/dog_rel.png?raw=true"> |
|
| 152 |
+
|<img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/mahiro_input.png?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/mahiro_canny.png?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/mahiro-out.png?raw=true"> |
|
| 153 |
+
|<img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/evt_source.jpg?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/evt_hed.png?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/evt_gen.png?raw=true"> |
|
| 154 |
+
|<img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/an-source.jpg?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/an-pose.png?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/an-gen.png?raw=true"> |
|
| 155 |
+
|<img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/sk-b-src.png?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/sk-b-dep.png?raw=true"> | <img width="256" alt="" src="https://github.com/Mikubill/sd-webui-controlnet/blob/main/samples/sk-b-out.png?raw=true"> |
|
| 156 |
+
|
| 157 |
+
The below examples are from T2I-Adapter.
|
| 158 |
+
|
| 159 |
+
From `t2iadapter_color_sd14v1.pth` :
|
| 160 |
+
|
| 161 |
+
| Source | Input | Output |
|
| 162 |
+
|:-------------------------:|:-------------------------:|:-------------------------:|
|
| 163 |
+
| <img width="256" alt="" src="https://user-images.githubusercontent.com/31246794/222947416-ec9e52a4-a1d0-48d8-bb81-736bf636145e.jpeg"> | <img width="256" alt="" src="https://user-images.githubusercontent.com/31246794/222947435-1164e7d8-d857-42f9-ab10-2d4a4b25f33a.png"> | <img width="256" alt="" src="https://user-images.githubusercontent.com/31246794/222947557-5520d5f8-88b4-474d-a576-5c9cd3acac3a.png"> |
|
| 164 |
+
|
| 165 |
+
From `t2iadapter_style_sd14v1.pth` :
|
| 166 |
+
|
| 167 |
+
| Source | Input | Output |
|
| 168 |
+
|:-------------------------:|:-------------------------:|:-------------------------:|
|
| 169 |
+
| <img width="256" alt="" src="https://user-images.githubusercontent.com/31246794/222947416-ec9e52a4-a1d0-48d8-bb81-736bf636145e.jpeg"> | (clip, non-image) | <img width="256" alt="" src="https://user-images.githubusercontent.com/31246794/222965711-7b884c9e-7095-45cb-a91c-e50d296ba3a2.png"> |
|
| 170 |
+
|
| 171 |
+
# Minimum Requirements
|
| 172 |
+
|
| 173 |
+
* (Windows) (NVIDIA: Ampere) 4gb - with `--xformers` enabled, and `Low VRAM` mode ticked in the UI, goes up to 768x832
|
| 174 |
+
|
| 175 |
+
# Multi-ControlNet
|
| 176 |
+
|
| 177 |
+
This option allows multiple ControlNet inputs for a single generation. To enable this option, change `Multi ControlNet: Max models amount (requires restart)` in the settings. Note that you will need to restart the WebUI for changes to take effect.
|
| 178 |
+
|
| 179 |
+
<table width="100%">
|
| 180 |
+
<tr>
|
| 181 |
+
<td width="25%" style="text-align: center">Source A</td>
|
| 182 |
+
<td width="25%" style="text-align: center">Source B</td>
|
| 183 |
+
<td width="25%" style="text-align: center">Output</td>
|
| 184 |
+
</tr>
|
| 185 |
+
<tr>
|
| 186 |
+
<td width="25%" style="text-align: center"><img src="https://user-images.githubusercontent.com/31246794/220448620-cd3ede92-8d3f-43d5-b771-32dd8417618f.png"></td>
|
| 187 |
+
<td width="25%" style="text-align: center"><img src="https://user-images.githubusercontent.com/31246794/220448619-beed9bdb-f6bb-41c2-a7df-aa3ef1f653c5.png"></td>
|
| 188 |
+
<td width="25%" style="text-align: center"><img src="https://user-images.githubusercontent.com/31246794/220448613-c99a9e04-0450-40fd-bc73-a9122cefaa2c.png"></td>
|
| 189 |
+
</tr>
|
| 190 |
+
</table>
|
| 191 |
+
|
| 192 |
+
# Control Weight/Start/End
|
| 193 |
+
|
| 194 |
+
Weight is the weight of the controlnet "influence". It's analogous to prompt attention/emphasis. E.g. (myprompt: 1.2). Technically, it's the factor by which to multiply the ControlNet outputs before merging them with original SD Unet.
|
| 195 |
+
|
| 196 |
+
Guidance Start/End is the percentage of total steps the controlnet applies (guidance strength = guidance end). It's analogous to prompt editing/shifting. E.g. \[myprompt::0.8\] (It applies from the beginning until 80% of total steps)
|
| 197 |
+
|
| 198 |
+
# Batch Mode
|
| 199 |
+
|
| 200 |
+
Put any unit into batch mode to activate batch mode for all units. Specify a batch directory for each unit, or use the new textbox in the img2img batch tab as a fallback. Although the textbox is located in the img2img batch tab, you can use it to generate images in the txt2img tab as well.
|
| 201 |
+
|
| 202 |
+
Note that this feature is only available in the gradio user interface. Call the APIs as many times as you want for custom batch scheduling.
|
| 203 |
+
|
| 204 |
+
# API and Script Access
|
| 205 |
+
|
| 206 |
+
This extension can accept txt2img or img2img tasks via API or external extension call. Note that you may need to enable `Allow other scripts to control this extension` in settings for external calls.
|
| 207 |
+
|
| 208 |
+
To use the API: start WebUI with argument `--api` and go to `http://webui-address/docs` for documents or checkout [examples](https://github.com/Mikubill/sd-webui-controlnet/blob/main/example/api_txt2img.ipynb).
|
| 209 |
+
|
| 210 |
+
To use external call: Checkout [Wiki](https://github.com/Mikubill/sd-webui-controlnet/wiki/API)
|
| 211 |
+
|
| 212 |
+
# Command Line Arguments
|
| 213 |
+
|
| 214 |
+
This extension adds these command line arguments to the webui:
|
| 215 |
+
|
| 216 |
+
```
|
| 217 |
+
--controlnet-dir <path to directory with controlnet models> ADD a controlnet models directory
|
| 218 |
+
--controlnet-annotator-models-path <path to directory with annotator model directories> SET the directory for annotator models
|
| 219 |
+
--no-half-controlnet load controlnet models in full precision
|
| 220 |
+
--controlnet-preprocessor-cache-size Cache size for controlnet preprocessor results
|
| 221 |
+
--controlnet-loglevel Log level for the controlnet extension
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
# MacOS Support
|
| 225 |
+
|
| 226 |
+
Tested with pytorch nightly: https://github.com/Mikubill/sd-webui-controlnet/pull/143#issuecomment-1435058285
|
| 227 |
+
|
| 228 |
+
To use this extension with mps and normal pytorch, currently you may need to start WebUI with `--no-half`.
|
| 229 |
+
|
| 230 |
+
# Archive of Deprecated Versions
|
| 231 |
+
|
| 232 |
+
The previous version (sd-webui-controlnet 1.0) is archived in
|
| 233 |
+
|
| 234 |
+
https://github.com/lllyasviel/webui-controlnet-v1-archived
|
| 235 |
+
|
| 236 |
+
Using this version is not a temporary stop of updates. You will stop all updates forever.
|
| 237 |
+
|
| 238 |
+
Please consider this version if you work with professional studios that requires 100% reproducing of all previous results pixel by pixel.
|
| 239 |
+
|
| 240 |
+
# Thanks
|
| 241 |
+
|
| 242 |
+
This implementation is inspired by kohya-ss/sd-webui-additional-networks
|
sd-webui-controlnet-main/__pycache__/preload.cpython-310.pyc
ADDED
|
Binary file (1.02 kB). View file
|
|
|
sd-webui-controlnet-main/annotator/__pycache__/annotator_path.cpython-310.pyc
ADDED
|
Binary file (736 Bytes). View file
|
|
|