feat: 目录层级变更
This commit is contained in:
@@ -265,76 +265,30 @@ class Handler(BaseHTTPRequestHandler):
|
||||
try:
|
||||
body = json.loads(self.rfile.read(length) or b"{}")
|
||||
path = body.get("path", "")
|
||||
threshold = float(body.get("threshold", 0.5))
|
||||
if not path:
|
||||
return self._send({"ok": False, "error": "缺少图片路径"})
|
||||
result = _executor.submit(_infer, path).result()
|
||||
except Exception as exc:
|
||||
return self._send({"ok": False, "error": str(exc)})
|
||||
|
||||
# NSFW 判定逻辑:
|
||||
# 只返回评分,不做阈值判定
|
||||
# WD Tagger v3 的 rating 是独立 sigmoid(不归一化),四个值可以同时很高。
|
||||
# 对于某些动漫图,rating 没有区分度(都在 0.5-0.6 之间)。
|
||||
#
|
||||
# 判定策略:
|
||||
# 1. 检查 top_tags 中是否有明确的色情标签(nude、genitals 等)
|
||||
# 2. 如果有,判定为 NSFW
|
||||
# 3. 否则,用 rating 辅助判断(explicit - general >= 0.1)
|
||||
|
||||
|
||||
ratings = result["ratings"]
|
||||
top_tags = result["top_tags"]
|
||||
explicit = ratings["explicit"]
|
||||
questionable = ratings["questionable"]
|
||||
general = ratings["general"]
|
||||
|
||||
|
||||
# 打印 top_tags 到日志(调试用)
|
||||
if top_tags:
|
||||
tag_str = ", ".join([f"{t['tag']}:{t['score']:.2f}" for t in top_tags[:5]])
|
||||
print(f"=== AnimeNSFW 标签: {tag_str}", flush=True)
|
||||
|
||||
# 定义明确的色情标签
|
||||
NSFW_TAGS = {
|
||||
"nude", "naked", "genitals", "penis", "vagina", "breasts",
|
||||
"nipples", "areola", "pubic_hair", "anus", "testicles",
|
||||
"erection", "ejaculation", "orgasm", "masturbation",
|
||||
"fellatio", "cunnilingus", "intercourse", "sex",
|
||||
"pussy", "cock", "dick", "boobs", "tits", "ass",
|
||||
"butt", "thighs", "legs", "feet", "toes",
|
||||
}
|
||||
|
||||
# 检查 top_tags 中是否有明确的色情标签
|
||||
nsfw_by_tags = False
|
||||
nsfw_tag_score = 0.0
|
||||
for tag_info in top_tags:
|
||||
tag_name = tag_info["tag"].lower()
|
||||
tag_score = tag_info["score"]
|
||||
# 检查标签名是否包含色情关键词
|
||||
for nsfw_keyword in NSFW_TAGS:
|
||||
if nsfw_keyword in tag_name and tag_score > 0.5:
|
||||
nsfw_by_tags = True
|
||||
nsfw_tag_score = max(nsfw_tag_score, tag_score)
|
||||
break
|
||||
if nsfw_by_tags:
|
||||
break
|
||||
|
||||
# 判定逻辑
|
||||
# nsfw_score 始终返回 max(explicit, questionable) 的最高分,
|
||||
# 这样 Go 侧可以通过 score > 0 判断检测器是否运行过。
|
||||
# nsfw 标记才表示是否真正判定为色情。
|
||||
nsfw_score = max(explicit, questionable)
|
||||
|
||||
if nsfw_by_tags:
|
||||
# 标签检测到明确的色情内容
|
||||
nsfw = True
|
||||
elif nsfw_score >= threshold and (nsfw_score - general) >= 0.1:
|
||||
# rating 辅助判断:最高分 >= 阈值 且 明显高于 general
|
||||
nsfw = True
|
||||
else:
|
||||
nsfw = False
|
||||
# nsfw_score 返回 max(explicit, questionable) 的最高分
|
||||
nsfw_score = max(explicit, questionable)
|
||||
|
||||
self._send({
|
||||
"ok": True,
|
||||
"nsfw": nsfw,
|
||||
"score": nsfw_score,
|
||||
"ratings": ratings,
|
||||
"top_tags": result["top_tags"],
|
||||
|
||||
Reference in New Issue
Block a user