6.2 KiB
Booru tag autocompletion for A1111
This custom script serves as a drop-in extension for the popular AUTOMATIC1111 web UI for Stable Diffusion.
It displays autocompletion hints for recognized tags from "image booru" boards such as Danbooru, which are primarily used for browsing Anime-style illustrations. Since some Stable Diffusion models were trained using this information, for example Waifu Diffusion, using exact tags in prompts can often improve composition and help to achieve a wanted look.
I created this script as a convenience tool since it reduces the need of switching back and forth between the web UI and a booru site to copy-paste tags.
You can either download the files manually as described below, or use a pre-packaged version from Releases.
NEW - Wildcard support
Autocompletion also works with wildcard files used by this script of the same name (demo video further down). This enables you to either insert categories to be replaced by the script, or event replace them with the actual wildcard file content in the same step.
Important:
Since not everyone has the script, it is disabled by default. Edit the config to enable it and uncomment / add the filenames you use in wildcardNames.txt.
As per the instructions of the wildcard script, the files are expected in /scripts/wildcards/, it will likely fail if you have another folder structure.
Known Issues:
If replaceUnderscores is active, the script will currently only partly replace edited tags containing multiple words in brackets.
For example, editing atago (azur lane), it would be replaced with e.g. taihou (azur lane), lane), since the script currently doesn't see the second part of the bracket as the same tag. So in those cases you should delete the old tag beforehand.
Also, at least for now there's no way to turn the script off from the ui, but I plan to get around to that eventually.
Screenshots
Demo video (with keyboard navigation):
Wildcard script support:
Dark and Light mode supported, including tag colors:
Installation
Simply put tagAutocomplete.js into the javascript folder of your web UI installation. It will run automatically the next time the web UI is started.
For the script to work, you also need to download the tags folder from this repo and paste it and its contents into the web UI root, or create them there manually.
The tags folder contains config.json and the tag data the script uses for autocompletion. By default, Danbooru and e621 tags are included.
Config
The config contains the following settings and defaults:
{
"tagFile": "danbooru.csv",
"activeIn": {
"txt2img": true,
"img2img": true,
"negativePrompts": true
},
"maxResults": 5,
"replaceUnderscores": true,
"escapeParentheses": true,
"useWildcards": false,
"colors": {
"danbooru": {
"0": ["lightblue", "dodgerblue"],
"1": ["indianred", "firebrick"],
"3": ["violet", "darkorchid"],
"4": ["lightgreen", "darkgreen"],
"5": ["orange", "darkorange"]
},
"e621": {
"-1": ["red", "maroon"],
"0": ["lightblue", "dodgerblue"],
"1": ["gold", "goldenrod"],
"3": ["violet", "darkorchid"],
"4": ["lightgreen", "darkgreen"],
"5": ["tomato", "darksalmon"],
"6": ["red", "maroon"],
"7": ["whitesmoke", "black"],
"8": ["seagreen", "darkseagreen"]
}
}
}
| Setting | Description |
|---|---|
| tagFile | Specifies the tag file to use. You can provide a custom tag database of your liking, but since the script was developed with Danbooru tags in mind, it might not work properly with other configurations. |
| activeIn | Allows to selectively (de)activate the script for txt2img, img2img, and the negative prompts for both. |
| maxResults | How many results to show max. For the default tag set, the results are ordered by occurence count. |
| replaceUnderscores | If true, undescores are replaced with spaces on clicking a tag. Might work better for some models. |
| escapeParentheses | If true, escapes tags containing () so they don't contribute to the web UI's prompt weighting functionality. |
| useWildcards | Used to toggle the recently added wildcard completion functionality. Also needs wildcardNames.txt to contain proper file names for your wildcard files. |
| colors | Contains customizable colors for the tag types, you can add new ones here for custom tag files (same name as filename, without the .csv). The first value is for dark, the second for light mode. Color names and hex codes should both work. |
CSV tag data
The script expects a CSV file with tags saved in the following way:
1girl,0
solo,0
highres,5
long_hair,0
Notably, it does not expect column names in the first row. The first value needs to be the tag name, while the second value specifies the tag type. The numbering system follows the tag API docs of Danbooru:
| Value | Description |
|---|---|
| 0 | General |
| 1 | Artist |
| 3 | Copyright |
| 4 | Character |
| 5 | Meta |
or of e621:
| Value | Description |
|---|---|
| -1 | Invalid |
| 0 | General |
| 1 | Artist |
| 3 | Copyright |
| 4 | Character |
| 5 | Species |
| 6 | Invalid |
| 7 | Meta |
| 8 | Lore |
The tag type is used for coloring entries in the result list.

