# ComfyUI-BooruGacha

ComfyUI custom nodes for generating and normalizing booru-style tags for image generation. Ships with curated datasets covering ~54k categorized Danbooru tags across 45+ categories.

## Nodes

### Booru Gacha Search

Normalizes comma-separated user input to matching Danbooru tags. Handles typos, spacing differences, and natural-language variations via string matching with semantic search fallback. Weight syntax `(tag:1.2)` is preserved through normalization.

### Booru Gacha Roll

Randomly generates Danbooru tags from selected categories with a dynamic UI. Add categories (hair color, location, pose, artist, etc.) via a hierarchical menu, configure count and weight per category, and control how much tag popularity influences selection. Seed-controlled for reproducible results.

### Booru Gacha Ban List

Builds a ban list from user-specified concepts by expanding them via token overlap and co-occurrence statistics. For example, banning `cum` automatically catches `cum_in_pussy`, `cum_on_body`, etc. The `expansion` slider controls how aggressively related tags are included. The `same_category` toggle (on by default) prevents cross-category leaks — banning `3d` (art style) won't accidentally ban `super_mario_3d_world` (copyright). Connect the output to the `ban_list` input on Search, Roll, or Combine nodes.

### Booru Gacha Tag Expand

Expands input tags into related tags to reinforce a concept. For example, `catgirl` expands into `cat_ears`, `cat_tail`, `animal_ear_fluff`, etc. Uses a hybrid approach: token overlap provides the conceptual link, while co-occurrence statistics rank and supplement with contextually relevant tags (e.g. `beach` → `ocean`, `sand`, `bikini`). Three scoring modes control ranking: Similarity (Jaccard), Association (PMI), and Weighted (LMI). A `scope` dropdown restricts expansions to the same group, subgroup, or category. Weight decays by rank so the most related expansions carry the most influence. Accepts an optional `BANLIST` to exclude unwanted expansions.

### Booru Gacha Combine

Merges multiple tag string inputs into a single deduplicated list. Dynamic "Add Input" / "Remove Last" buttons let you wire as many sources as needed. Earlier inputs take priority when duplicates are found (preserving weight). Accepts an optional `BANLIST` connection for final-stage hard filtering.

### Booru Gacha Combine Bans

Merges multiple `BANLIST` inputs into one unified ban set. Dynamic inputs like the Combine node. Useful when you have several Ban List nodes targeting different concepts and want to feed a single combined ban into your workflow.

## Install

```bash
cd ComfyUI/custom_nodes
git clone <this-repo> ComfyUI-BooruGacha
pip install -r ComfyUI-BooruGacha/requirements.txt
```

Restart ComfyUI. The sentence-transformer model (`all-MiniLM-L6-v2`) is downloaded automatically on first use and embeddings are cached locally.
