Extensions/Soda 提示词 SFW/NSFW 分类
ComfyUI Extension

Soda 提示词 SFW/NSFW 分类

Offline keyword-based SFW/NSFW prompt classification for ComfyUI.

By cOkieeman·Created a day ago·Updated a day ago· 0
cOkieeman/ComfyUI-Soda-Prompt-Classifier
Nodes—
On cloudLocal install
Stars0
Updateda day ago
Readme

Soda 提示词 SFW/NSFW 分类(无模型)

根据正面提示词中的中英文关键词自动分类,仅使用 Python 标准库。不下载模型、不联网、不需要 pip 安装任何包,也不依赖 LogicUtils、WD14 或 ONNX Runtime。

安装

把整个 ComfyUI-Soda-Prompt-Classifier 文件夹放到 ComfyUI/custom_nodes/,重启 ComfyUI。在节点搜索中输入 SodaPromptContentClassifier 或 Soda 提示词分类。

分享时发送本插件 ZIP,接收方解压到上述目录。工作流 JSON 本身不包含插件代码。

也可以在 custom_nodes 目录执行:

git clone https://github.com/cOkieeman/ComfyUI-Soda-Prompt-Classifier.git

支持“Install via Git URL”的 ComfyUI-Manager 也可粘贴同一仓库地址安装,具体取决于其安全配置。Comfy Registry 节点 ID 为 comfyui-soda-prompt-classifier,发布者为 cokieeman;版本审核和索引完成前,Manager 搜索或“安装缺失节点”可能暂时无法定位它。

examples/提示词分类-示例.json 是独立测试工作流,只需要本插件和 ComfyUI 自带的文字预览节点。加载后把提示词从普通人物描述改成 nsfw,即可观察分类及命中词变化,无需生成图片。

接线

将最终用于生成的正面提示词连接到 positive_prompt;使用通配符时,应连接展开后的文本。不要把负面提示词、LoRA 文件名或参数记录接进来。

四个输出:

| 输出 | 内容 | 用法 | | --- | --- | --- | | 分类 | SFW / NSFW | 拼接文件名或目录名 | | 规则评级 | general / explicit | 接原来的 explicit → NSFW,否则 SFW 比较节点 | | 是否NSFW | 布尔值 | 接字符串开关 | | 命中关键词 | 命中的词,逗号分隔 | 接文字预览,检查分类原因 |

extra_keywords 可以补充普通关键词,用逗号或换行分隔。特殊字符按字面匹配,不执行正则表达式。

规则边界

词表由 Codex 按常见的中英文裸体、性行为标签整理,完整内容在 __init__.py 的 DEFAULT_KEYWORDS 中。它不是官方 SFW/NSFW 标准,也没有经过标注图片集的准确率验证。任何一个未被简单否定规则排除的关键词命中,即输出 NSFW;没有评分模型或置信度阈值。

  • 内置裸体、明确性行为等中英文关键词;没有命中时输出 SFW。
  • 英文不区分大小写,按词边界匹配;nude 不会命中 denuded,sex 不会命中 sextant。
  • 支持 bare_breasts 等下划线标签及 (nude:1.2) 权重格式。
  • 忽略紧邻关键词的简单否定,如 no nudity、non-nude、没有裸体;不是完整的自然语言否定分析。
  • nude color、nude lipstick 等常见裸色表述不触发 nude。
  • 泳装、内衣等词默认不触发;需要时可加入额外关键词。

这不是图片评级器。提示词未命中,不代表图片没有敏感内容;医学描述、复杂否定、隐喻和未收录词汇也可能误分。规则评级只是为了连接已有保存逻辑,不是 WD14 模型预测值。

连接已有分类工作流

如果已有 WD14 评级 → explicit 比较 → 文件名选择 分支,可以把本节点的“规则评级”接到比较输入,删除 WD14 评级节点。输入改接合并并展开通配符后的正面提示词,输出的 explicit/general 只作为该分支的文字选择依据。

测试

用 Python 标准库测试即可:

python -m unittest discover -s tests -v

English

An offline, model-free ComfyUI node that classifies positive prompt text with English and Chinese keyword rules. No external Python dependencies, network calls, or model downloads. Node ID: SodaPromptContentClassifier.

Outputs are a label (SFW / NSFW), a compatibility value (general / explicit), a boolean, and the matched keywords. Connect expanded positive prompts, not negative prompts or LoRA filenames. Add literal custom keywords with extra_keywords.

These are Codex-authored heuristic rules, not image predictions, an official rating standard, or a classifier with measured accuracy. An unmatched prompt is labeled SFW by convention; it does not certify the generated image. See DEFAULT_KEYWORDS in __init__.py for the full list. Simple negation and common nude-color phrases are excluded, but ambiguous language can still be misclassified.