Git Product home page Git Product logo

a1111-sd-webui-tagcomplete's Introduction

tag_autocomplete_light

SD WebUI Tag Autocomplete

English • 简体中文日本語

Booru style tag autocompletion for the AUTOMATIC1111 Stable Diffusion WebUI

Github Release stargazers contributors forks issues

ChangelogKnown IssuesReport BugRequest Feature


📄 Description

Tag Autocomplete is an 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 and many of the NAI-descendant models or merges, using exact tags in prompts can often improve composition and consistency.

You can install it using the inbuilt available extensions list, clone the files manually as described below, or use a pre-packaged version from Releases.


✨ Features

  • 🚀 Instant completion hints while typing (under normal circumstances)
  • ⌨️ Keyboard navigation
  • 🌒 Dark & Light mode support
  • 🛠️ Many settings and customizability
  • 🌍 Translation support for tags, with optional live preview for the full prompt
    • Note: Translation files are provided by the community, see here for a list of translations I know of.

Tag autocomplete supports built-in completion for:

  • 🏷️ Danbooru & e621 tags (Top 100k by post count, as of November 2022)
  • ✳️ Wildcards
  • Extra network filenames, including
    • Textual Inversion embeddings [(jump to readme section)]
    • Hypernetworks
    • LoRA
    • LyCORIS / LoHA
  • 🪄 Chants (custom format for longer prompt presets)
  • 🏷️ "Extra file", one set of customizable extra tags

Additionally, some support for other third party extensions exists:

Click to expand

🖼️ Screenshots & Demo videos

Click to expand Basic usage (with keyboard navigation):
demo_basic.mp4

Wildcard script support:

demo_wildcards.mp4

Dark and Light mode supported, including tag colors:

results_dark results_light


📦 Installation

Using the built-in extension list

  1. Open the Extensions tab
  2. Open the Available sub-tab
  3. Click Load from
  4. Find Booru tag autocompletion in the list
    • The extension was one of the first available, so selecting "oldest first" will show it high up in the list.
    • Alternatively, use CRTL + F to search for the text on the page
  5. Click Install on the right side

Load from index Order by oldest Install

Manual clone

git clone "https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git" extensions/tag-autocomplete

(The second argument specifies the name of the folder, you can choose whatever you like).


❇️ Additional completion support

Wildcards

Autocompletion also works with wildcard files used by https://github.com/AUTOMATIC1111/stable-diffusion-webui-wildcards or other similar scripts/extensions. 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. 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.

Wildcard files Wildcard replacements

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.

Extra networks (Embeddings, Hypernets, LoRA, ...)

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:

  • <e: will only show embeddings
  • <l: will only show LoRA and LyCORIS
    • Or <lora: and <lyco: respectively for the long form
  • <h: or <hypernet: will only show Hypernetworks

Embedding type filtering

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.

For example:

Embedding version filter

Chants

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.

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:

(masterpiece, best quality, high quality, highres, ultra-detailed),

Chants can be added in JSON files following this format:

Chant format (click to expand)
[
    {
        "name": "Basic-NegativePrompt",
        "terms": "Negative,Low,Quality",
        "content": "(worst quality, low quality, normal quality)",
        "color": 3
    },
    {
        "name": "Basic-HighQuality",
        "terms": "Best,High,Quality",
        "content": "(masterpiece, best quality, high quality, highres, ultra-detailed)",
        "color": 1
    },
    {
        "name": "Basic-Start",
        "terms": "Basic, Start, Simple, Demo",
        "content": "(masterpiece, best quality, high quality, highres), 1girl, extremely beautiful detailed face, ...",
        "color": 5
    }
]

The file can then be selected using the "Chant file" settings dropdown if it is located inside the extension's tags folder.

A chant object has four fields:

  • name - Display name
  • terms - Search terms
  • content - The actual prompt content
  • color - Color, using the same category color system as normal tags

Umi AI tags

https://github.com/Klokinator/Umi-AI is a feature-rich wildcard extension similar to Unprompted or Dynamic Wildcards. 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 >.

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. 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.

Most of the credit goes to @ctwrs here, they contributed a lot as one of the Umi developers.

🛠️ Settings

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.

Tag filename

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.

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.

tagfile

"Active in" settings

Specifies where tag autocomplete should attach itself to and listen for changes. Negative prompts follow the settings for txt2img & img2img, so they will only be active if their "parent" is active.

activeIn

Black / Whitelist

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).

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).

blacklist

Move completion popup with cursor

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.

movePopup

movePopup_on movePopup_off

Result count

Settings for the amount of results to show at once. 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).

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.

resultsCount

Completion delay

Depending on the configuration, real time tag completion can get computationally expensive. 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.

delay

"Search for" settings

Pretty self explanatory, enables or disables certain completion types.

Umi AI wildcards are included in the normal wildcard option here, although they use a different format, since their usage intention is similar.

searchFor

"?" Wiki links

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.

⚠️ Warning:

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.

wikiLink

Completion settings

These settings specify how the text will be inserted.

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.

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.

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.

insertEscape

Alias settings

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.

Only show alias sets if you want to see only the alias or also the tag it maps to (shown as <alias> ➝ <actual>)

alias

Translation settings

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.

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.

For more details, see the section on translations below.

translation

Extra file settings

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.)

If you want completion for longer presets or even whole prompts, have a look at Chants instead.

extraFile

Chant filename

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.

For more info, see the section on Chants above.

chants

Hotkeys

You can specify the hotkeys for most keyboard navigation features here. Should be one of the key names specified in https://www.w3.org/TR/uievents-key/#named-key-attribute-value.

Function explanation:

  • Move Up / Down: Select the next tag
  • Jump Up / Down: Move by five places at once
  • Jump to Start / End: Jump to the top or bottom of the list
  • ChooseSelected: Select the highlighted tag, or close popup if nothing was selected
  • ChooseSelectedOrFirst: Same as above, but default to the first result if nothing was selected
  • Close: Closes the popup

hotkeys

Colors

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.

The format is standard JSON

  • The object names correspond to the tag filename they should be used for.
  • The numbers are specifying the tag type, which is dependent on the tag source. For more info, see CSV tag data.
  • The first value in the square brackets is for dark, the second for light mode. HTML color names and hex codes should both work.

This can also be used to add new color sets for custom tag files.

colors

Refresh TAC temp files

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.

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.

You can also add this to your quicksettings bar to have the refresh button available at all times.

fakeRefresh


Translations

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. This file needs to be a CSV in the format <English tag/alias>,<Translation>, but for backwards compatibility with older files that used a three column format, you can turn on Translation file uses old 3-column translation format instead of the new 2-column one to support them. In that case, the second column will be unused and skipped during parsing.

Example with Chinese translation:

IME-input english-input

List of translations

🫵 I need your help!

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. Please make sure the quality is alright though, machine translation gets a lot of stuff wrong even for the most common tags.

Live preview

⚠️ Warning:

This feature is still experimental, you might encounter some bugs when using it.

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.

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).

The option defaults to off, but you can activate it by choosing a translation file and checking "Show live tag translation below prompt". It will not affect the normal functionality if it is off.

Example with Chinese translation:

image

Clicking on a detected tag will also select it in the prompt for quick editing.

image

⚠️ Known issues with live translation:

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.

Extra file

An extra file can be used to add new / custom tags not included in the main set. The format is identical to the normal tag format shown in CSV tag data below, with one exception: 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. If left empty, it will instead show "Custom tag".

An example with the included (very basic) extra-quality-tags.csv file:

image

Whether the custom tags should be added before or after the normal tags can be chosen in the settings.

CSV tag data

The script expects a CSV file with tags saved in the following way:

<name>,<type>,<postCount>,"<aliases>"

Example:

1girl,0,4114588,"1girls,sole_female"
solo,0,3426446,"female_solo,solo_female"
highres,5,3008413,"high_res,high_resolution,hires"
long_hair,0,2898315,longhair
commentary_request,5,2610959,

Notably, it does not expect column names in the first row and both count and aliases are technically optional, 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.

The numbering system follows the tag API docs of Danbooru:

Value Description
0 General
1 Artist
3 Copyright
4 Character
5 Meta

or similarly for 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.

⚠️ Common Problems & Known Issues:

  • Depending on your browser settings, sometimes an old version of the script can get cached. Try CTRL + F5 to force-reload the site without cache if e.g. a new feature doesn't appear for you after an update.
  • If the prompt popup has broken styling for you or doesn't appear at all (like this), 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.

a1111-sd-webui-tagcomplete's People

Contributors

batvbs avatar ctwrs avatar derrian-distro avatar dominikdoom avatar for-acgn avatar halfmai avatar kamilowaty122 avatar kinsmir avatar mmaker-gh avatar mulet-j avatar re-unknown avatar sgmklp avatar shinshin86 avatar space-nuko avatar viyiviyi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.