Qwen3.5-4B-Danbooru-Prompt-Generator
Expand a few Danbooru seed tags into a full image-generation prompt. Ships as a merged text-only Qwen3.5 model (BF16 + GGUF) and a ComfyUI node that talks to a model server over HTTP. The node is built for LM Studio: load the model there and the node handles the rest.
Key features
- Semantic negation. Prefix a concept with
-(e.g.-nude) and the model avoids that concept and related tags. - Danbooru tag output. Tags go in as a user chat message, comma-separated tags with underscores come out (
looking_at_viewer). - Rating control. Write
rating:generalorrating:explicit, exactly like that. - Chat template. Use the supplied template with thinking/reasoning off. With thinking on, the model writes the tags inside its reasoning block and the final answer comes out empty.
Prompt format
Separate tags with , , use underscores in multi-word tags, prefer tags that exist on Danbooru.
1girl, long_hair, school_uniform, -nude, rating:general
| Syntax | Meaning |
|---|---|
1girl, blue_hair | seed tags to expand |
looking_at_viewer | multi-word tags use underscores |
-nude | semantically avoid this concept and related tags |
rating:general / rating:explicit | requested content rating |
Training data was mostly NSFW, so the model biases toward explicit content. For SFW output, include rating:general and negatives like -nude, then review the generated tags. These instructions do not guarantee SFW output.
Files
| Path | Contents |
|---|---|
model/ | Merged BF16 Safetensors, tokenizer and chat template (Transformers) |
gguf/Qwen3.5-4B-anime.gguf | GGUF build, about 2.7 GB |
comfyui-prompt-generator/ | ComfyUI node folder — copy into ComfyUI/custom_nodes/ |
checksums.json | SHA-256 hashes of the supplied model files |
Text-only model — it does not take images as input. Base: techwithsergiu/Qwen3.5-text-4B-bnb-4bit, derived from Qwen/Qwen3.5-4B.
ComfyUI
-
Copy
comfyui-prompt-generator/intoComfyUI/custom_nodes/, then install its dependency with ComfyUI's Python and restart:python -m pip install -r custom_nodes/comfyui-prompt-generator/requirements.txtWindows portable, from its root folder:
.\python_embeded\python.exe -m pip install -r .\ComfyUI\custom_nodes\comfyui-prompt-generator\requirements.txt -
Load the GGUF (or
model/) in LM Studio, enable the local server, and use the supplied chat template with thinking off. The model files do not have to sit inside ComfyUI; the server can run on the same machine or another one reachable over the network. -
Set
hostto the server's API base URL including/v1(LM Studio default:http://127.0.0.1:1234/v1) andmodelto the identifier your server exposes.
Required API contract (LM Studio provides it out of the box) — an OpenAI-compatible chat endpoint alone is not enough:
POST /v1/chat/completions— OpenAI-compatible chat.GET /api/v1/models— JSON with amodelslist; entries exposekey/display_nameandloaded_instanceswith instanceids.POST /api/v1/models/load—{"model": "<identifier>"}, returns theinstance_idused for chat requests.
Node interface
| Input | Default | Notes |
|---|---|---|
host | http://127.0.0.1:1234/v1 | API base URL, including /v1 |
model | qwen3.5-4b-anime | Model identifier exposed by the server |
tags | long hair, pink hair | Seed tags, sent as one user message |
prefix | score_9, score_8, score_7, ... | Prepended locally, not sent to the model |
suffix | Empty | Appended locally |
temperature | 1.0 | Sampling temperature |
seed | 0 | 0 omits the seed; positive values are forwarded if supported |
Outputs: generated_prompt (generated tags after rating conversion and cleanup) and formatted_prompt (prefix + prompt + suffix joined with , ). Connect formatted_prompt to your positive prompt encoder.
The node maps rating:general → safe and rating:explicit → nsfw, explicit; other tags pass through. It requests at most 1,024 output tokens and drops the final fragment if the server reports a length cutoff. Rating conversion only rewrites output text — it does not filter content.
Transformers inference
python -m pip install "transformers>=5.5.0" accelerate safetensors
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("./model")
model = AutoModelForCausalLM.from_pretrained(
"./model", dtype=torch.bfloat16, device_map="auto"
).eval()
messages = [{"role": "user", "content": "1girl, red_hair, -nude, rating:general"}]
text = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True, enable_thinking=False
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.inference_mode():
outputs = model.generate(**inputs, max_new_tokens=1024, do_sample=True, temperature=1.0)
print(tokenizer.decode(outputs[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip())
This returns the raw response, including any rating: tag; the node's rating conversion and prefix/suffix are separate post-processing. BF16 needs roughly 8.4 GB of weights plus KV cache — use the GGUF build for lower memory.
Troubleshooting
- Node missing: install
requestsinto the Python env that runs ComfyUI, restart, check the startup log. - Connection refused:
hostmust end in/v1; check address, port and network reachability (note127.0.0.1is local to where ComfyUI runs). - 404 or model-load error: the weight path is not the model identifier; match the server's model-management API.
- Empty response: disable thinking in the server's chat-template settings. With thinking on, the tags end up inside the reasoning block and the final answer is empty.
- Slow first request: the node allows up to 300 s for model loading and generation; reduce context or GPU offload on memory errors.
License
Apache-2.0. See the Apache License 2.0 and the upstream Qwen license.