Skip to content

PRINTFILM: AI short-video marketing and AI short-drama creation platform

fix(drama): soften Seedream input text that trips content filters

yicba99438f054
diff --git a/backend/app/services/ark.py b/backend/app/services/ark.py
index 94cf002..88a296d 100644
--- a/backend/app/services/ark.py
+++ b/backend/app/services/ark.py
@@ -39,6 +39,12 @@ def _raise_seedream_http_error(status_code: int, body: str) -> None:
raise RuntimeError(
"上游 Seedream 账户欠费(AccountOverdueError),生图暂不可用,请联系管理员充值火山方舟账户"
)
+ if "InputTextSensitive" in snippet or "InputTextSensitiveContentDetected" in snippet:
+ raise RuntimeError(
+ "生图文案未通过内容审核(含未成年人、酒精等敏感表述),"
+ "请修改提示词后重试。"
+ f" 详情:{snippet[:240]}"
+ )
raise RuntimeError(f"Seedream error {status_code}: {snippet}")
@@ -588,7 +594,11 @@ class ArkGateway:
size: str | None = None,
model: str | None = None,
) -> ImageResult:
- """调用 Seedream 生图;策略拦截直接失败,不改写/软化提示词兜底。"""
+ """调用 Seedream 生图。
+
+ 发送前仅软化易触发文本审核的措辞;不做空主体 / CG 厚涂兜底。
+ 策略拦截仍直接失败。
+ """
if self.mock:
local = await asyncio.to_thread(self._write_mock_image, prompt, size)
# _write_mock_image returns /static/...; publish to OSS when enabled
@@ -596,7 +606,17 @@ class ArkGateway:
url = storage.publish_local(path) if path and path.exists() else local
return ImageResult(local_url=url, remote_url=None)
- current = (prompt or "").strip()
+ from app.services.seedream_text_soften import soften_seedream_input_text
+
+ # 发送前软化易触发文本审核的措辞(保留主体,非空场景/CG 兜底)
+ current = soften_seedream_input_text((prompt or "").strip())
+ if current != (prompt or "").strip():
+ logger.info(
+ "Seedream input softened shot=%s before=%s after=%s",
+ shot_no,
+ len(prompt or ""),
+ len(current),
+ )
full_prompt = f"{current}。避免:{negative}" if negative else current
try:
return await self._seedream_once(
diff --git a/backend/app/services/seedream_text_soften.py b/backend/app/services/seedream_text_soften.py
new file mode 100644
index 0000000..a53bf0e
--- /dev/null
+++ b/backend/app/services/seedream_text_soften.py
@@ -0,0 +1,34 @@
+"""Seedream 输入文案软化:保留主体语义,降低 InputTextSensitive 误杀。
+
+不做空主体 / CG 厚涂兜底;仅替换易触发审核的未成年人、酒精等表述。
+"""
+
+from __future__ import annotations
+
+# 长词优先,避免短词先替换破坏短语
+_SEEDREAM_TEXT_SOFTEN: list[tuple[str, str]] = [
+ ("腰悬酒葫芦", "腰佩葫芦形饰物"),
+ ("酒葫芦", "葫芦形佩饰"),
+ ("小学男生", "少年学子"),
+ ("小学女生", "少年学子"),
+ ("小学生", "少年学子"),
+ ("婴幼儿", "幼龄角色"),
+ ("幼童", "少年"),
+ ("儿童", "少年"),
+ ("童声", "清亮稚气嗓音"),
+ ("童真", "天真好奇"),
+ ("顶流", "名士"),
+ ("醉酒", "微醺神态"),
+ ("饮酒", "持盏"),
+]
+
+
+# 软化易触发 Seedream 文本审核的措辞;无变化则原样返回
+def soften_seedream_input_text(prompt: str) -> str:
+ out = prompt or ""
+ if not out:
+ return out
+ for src, dst in _SEEDREAM_TEXT_SOFTEN:
+ if src in out:
+ out = out.replace(src, dst)
+ return out
diff --git a/backend/tests/test_seedream_text_soften.py b/backend/tests/test_seedream_text_soften.py
new file mode 100644
index 0000000..5124966
--- /dev/null
+++ b/backend/tests/test_seedream_text_soften.py
@@ -0,0 +1,29 @@
+"""seedream_text_soften 单元测试。"""
+from __future__ import annotations
+
+from app.services.seedream_text_soften import soften_seedream_input_text
+
+
+def test_soften_xiaoxuesheng_and_child_terms() -> None:
+ raw = "毛毡教室,小学生穿着校服,标签:传承+童声+童真"
+ out = soften_seedream_input_text(raw)
+ assert "小学生" not in out
+ assert "童声" not in out
+ assert "童真" not in out
+ assert "少年学子" in out
+ assert "校服" in out
+
+
+def test_soften_libai_alcohol_and_celeb_slang() -> None:
+ raw = "盛唐顶流,白衣佩剑,腰悬酒葫芦,身份:诗仙"
+ out = soften_seedream_input_text(raw)
+ assert "酒葫芦" not in out
+ assert "顶流" not in out
+ assert "葫芦形" in out or "葫芦" in out
+ assert "佩剑" in out
+ assert "诗仙" in out
+
+
+def test_soften_noop_when_clean() -> None:
+ raw = "白衣诗人,月白大袖,羊毛毡手作风格"
+ assert soften_seedream_input_text(raw) == raw