feat: hard reject political, sexual, violent, and gory content

This commit is contained in:
2026-02-28 19:48:58 +08:00
parent c284d79f83
commit 52da73a07f

View File

@@ -248,6 +248,14 @@ class ImageAnalyzer:
"多人", "多人脸", "人群", "群像", "合照", "集体照", "全家福", "毕业照", "婚礼合影", "大合照", "多人", "多人脸", "人群", "群像", "合照", "集体照", "全家福", "毕业照", "婚礼合影", "大合照",
"crowd", "group photo", "many faces", "crowd", "group photo", "many faces",
) )
FORBIDDEN_CONTENT_KEYWORDS = (
# 党政/涉政
"党政", "涉政", "政治人物", "领导人", "国旗", "国徽", "党徽", "党旗", "时政宣传",
# 黄暴血腥
"黄色", "擦边", "裸露", "色情", "性暗示", "暴力", "凶杀", "打斗", "枪击", "血腥", "尸体", "虐待",
# 英文兜底
"political", "government propaganda", "nsfw", "porn", "nude", "violence", "bloody", "gore",
)
async def analyze(self, image_path: str) -> dict: async def analyze(self, image_path: str) -> dict:
""" """
@@ -556,9 +564,11 @@ class ImageAnalyzer:
if perspective not in ("no", "mild", "strong"): if perspective not in ("no", "mild", "strong"):
perspective = "no" perspective = "no"
scene_text = ((subject or "") + " " + (proc_type or "") + " " + (reason or "") + " " + (note or "")).lower()
# 识别“密集文字场景”关键词(中文 + 英文兜底) # 识别“密集文字场景”关键词(中文 + 英文兜底)
dense_text_scene = any( dense_text_scene = any(
kw in ((subject or "") + " " + (proc_type or "") + " " + (reason or "")).lower() kw in scene_text
for kw in self.DENSE_TEXT_SUBJECT_KEYWORDS for kw in self.DENSE_TEXT_SUBJECT_KEYWORDS
) )
@@ -638,7 +648,7 @@ class ImageAnalyzer:
price_suggest = 0 price_suggest = 0
# 硬规则2多人脸不接1-2 人脸可做 # 硬规则2多人脸不接1-2 人脸可做
many_faces_scene = any(k in (subject_raw + " " + reason_raw + " " + note_raw).lower() for k in self.MANY_FACES_SUBJECT_KEYWORDS) many_faces_scene = any(k in scene_text for k in self.MANY_FACES_SUBJECT_KEYWORDS)
if has_face == "yes" and many_faces_scene: if has_face == "yes" and many_faces_scene:
feasibility = "no" feasibility = "no"
risk = "high" risk = "high"
@@ -646,12 +656,19 @@ class ImageAnalyzer:
reason = (reason or "多人脸") + " | 多人脸场景不接单" reason = (reason or "多人脸") + " | 多人脸场景不接单"
price_suggest = 0 price_suggest = 0
# 硬规则3党政/涉黄/暴力/血腥内容不接单
forbidden_scene = any(k in scene_text for k in self.FORBIDDEN_CONTENT_KEYWORDS)
sensitive_hit = str(sensitive or "").strip().lower() in ("yes", "true", "1", "")
if forbidden_scene or sensitive_hit:
feasibility = "no"
risk = "high"
note = "含党政/涉黄/暴力/血腥等敏感内容,不接单"
reason = (reason or "敏感内容") + " | 敏感内容不接单"
price_suggest = 0
# 确保是 5 的倍数 # 确保是 5 的倍数
price_suggest = round(price_suggest / 5) * 5 price_suggest = round(price_suggest / 5) * 5
if sensitive == "yes":
feasibility = "no"
note = "图片含敏感内容,不接单"
risk_label = {"none": "无风险", "low": "低风险", "high": "高风险"}.get(risk, "") risk_label = {"none": "无风险", "low": "低风险", "high": "高风险"}.get(risk, "")
sens_tag = " | 敏感:是" if sensitive == "yes" else "" sens_tag = " | 敏感:是" if sensitive == "yes" else ""
print(f"[ImageAnalyzer] 识别结果: {complexity} | {reason} | 建议报价: {price_suggest}{sens_tag}") print(f"[ImageAnalyzer] 识别结果: {complexity} | {reason} | 建议报价: {price_suggest}{sens_tag}")