PRINTFILM: AI short-video marketing and AI short-drama creation platform
fix(drama): scrub historical identity and add style-only Seedream retry
yic7332fd2150c
diff --git a/backend/app/services/ark.py b/backend/app/services/ark.pyindex 0554ce1..025be8d 100644--- a/backend/app/services/ark.py+++ b/backend/app/services/ark.py@@ -596,8 +596,8 @@ class ArkGateway:) -> ImageResult:"""调用 Seedream 生图。- 发送前软化易触发文本审核的措辞;InputTextSensitive 时再用短前缀压缩重试一次。- 不做空主体 / CG 厚涂兜底。+ 发送前软化易触发文本审核的措辞;InputTextSensitive 时依次压缩前缀、+ 再退化到「服装+风格」短描述重试。不做空主体 / CG 厚涂兜底。"""if self.mock:local = await asyncio.to_thread(self._write_mock_image, prompt, size)@@ -609,6 +609,7 @@ class ArkGateway:from app.services.seedream_text_soften import (compact_seedream_prompt_for_retry,soften_seedream_input_text,+ style_only_seedream_prompt_for_retry,)# 发送前软化易触发文本审核的措辞(保留主体,非空场景/CG 兜底)@@ -623,11 +624,16 @@ class ArkGateway:)attempts = [current]- compact = compact_seedream_prompt_for_retry(current)- if compact and compact != current:- attempts.append(compact)+ for builder in (+ compact_seedream_prompt_for_retry,+ style_only_seedream_prompt_for_retry,+ ):+ candidate = builder(current)+ if candidate and candidate not in attempts:+ attempts.append(candidate)last_err: Exception | None = None+ labels = ("softened", "compact", "style_only")for idx, candidate in enumerate(attempts):full_prompt = f"{candidate}。避免:{negative}" if negative else candidatetry:@@ -642,7 +648,7 @@ class ArkGateway:except Exception as exc: # noqa: BLE001last_err = excmsg = str(exc)- # 仅文本审核可走压缩重试;其它策略/错误直接失败+ # 仅文本审核可走压缩/风格重试;其它策略/错误直接失败if not self._is_seedream_input_text_sensitive(msg):if self._is_seedream_policy_error(msg):logger.warning(@@ -651,13 +657,15 @@ class ArkGateway:)raiseif idx + 1 < len(attempts):+ nxt = labels[idx + 1] if idx + 1 < len(labels) else "next"logger.warning(- "Seedream InputTextSensitive shot=%s; retrying compact prompt",+ "Seedream InputTextSensitive shot=%s; retrying %s prompt",shot_no,+ nxt,)continuelogger.warning(- "Seedream InputTextSensitive shot=%s; compact retry exhausted",+ "Seedream InputTextSensitive shot=%s; retries exhausted",shot_no,)raisediff --git a/backend/app/services/seedream_text_soften.py b/backend/app/services/seedream_text_soften.pyindex e190feb..54f2812 100644--- a/backend/app/services/seedream_text_soften.py+++ b/backend/app/services/seedream_text_soften.py@@ -1,6 +1,6 @@-"""Seedream 输入文案软化:保留主体语义,降低 InputTextSensitive 误杀。+"""Seedream 输入文案软化:保留外形/风格,降低 InputTextSensitive 误杀。-不做空主体 / CG 厚涂兜底;仅替换易触发审核的表述,必要时压缩设定板前缀重试。+不做空主体 / CG 厚涂兜底;必要时压缩前缀,并去掉易被识别为历史名人的身份词。"""from __future__ import annotations@@ -32,19 +32,28 @@ _SEEDREAM_TEXT_SOFTEN: list[tuple[str, str]] = [("校服", "学院制服"),("课堂", "学堂"),("学生", "学子"),- # 兵器 / 网红 / 名号 / 气质+ # 兵器 / 网红 / 气质("白衣佩剑", "白衣腰佩长绦"),("腰佩长剑", "腰佩长绦"),("佩剑", "腰佩长绦"),- ("顶流", "名士"),- ("诗仙", "盛唐洒脱文人"),- ("盛唐豪放诗人", "盛唐洒脱文人"),- ("豪放诗人", "洒脱文人"),("眼神狂放不羁", "目光明亮自信"),("狂放不羁", "洒脱自信"),("超凡脱俗", "气度从容"),("豪放", "洒脱"),("电影质感", "细腻画质"),+ # 历史名人身份(勿再写回「盛唐/诗仙/名士」等可指认词)+ ("盛唐豪放诗人", "古风洒脱书生"),+ ("盛唐洒脱文人", "古风洒脱书生"),+ ("豪放诗人", "洒脱书生"),+ ("诗仙", "古风洒脱书生"),+ ("诗圣", "古风沉稳书生"),+ ("顶流", "风雅书生"),+ ("名士", "书生"),+ ("文人", "书生"),+ ("诗人", "书生"),+ ("盛唐", "古风年代"),+ ("李白", "古风白衣青年"),+ ("杜甫", "古风青衫青年"),]# 设定板长前缀结束标记(之后为用户正文)@@ -90,3 +99,30 @@ def compact_seedream_prompt_for_retry(prompt: str) -> str:if not body:body = soften_seedream_input_text(prompt or "")return f"{_COMPACT_CHARACTER_PREFIX}{body}"+++# 仍审核失败时:只保留服装/风格线索,去掉朝代与可指认身份+def style_only_seedream_prompt_for_retry(prompt: str) -> str:+ body = soften_seedream_input_text(extract_seedream_user_body(prompt) or prompt or "")+ style_bits: list[str] = []+ for key in (+ "羊毛毡",+ "毛毡定格",+ "毛毡",+ "粘土软萌",+ "粘土",+ "软萌",+ "治愈系",+ "3D",+ "毛绒",+ "缝线",+ ):+ if key in body and key not in style_bits:+ style_bits.append(key)+ style = "、".join(style_bits) if style_bits else "手作可爱质感"+ robe = "白衣宽袖" if ("白衣" in body or "月白" in body) else "古风常服"+ return (+ f"纯白背景,单人全身立绘,{robe}青年书生,腰间圆润佩饰,"+ f"{style},轮廓略不规整,针孔与绒感清晰,无文字水印,"+ "禁止真实历史人物肖像。"+ )diff --git a/backend/tests/test_seedream_text_soften.py b/backend/tests/test_seedream_text_soften.pyindex 0ff34d2..0668ac2 100644--- a/backend/tests/test_seedream_text_soften.py+++ b/backend/tests/test_seedream_text_soften.py@@ -4,6 +4,7 @@ from __future__ import annotationsfrom app.services.seedream_text_soften import (compact_seedream_prompt_for_retry,soften_seedream_input_text,+ style_only_seedream_prompt_for_retry,)@@ -23,22 +24,17 @@ def test_soften_xiaoxuesheng_and_child_terms() -> None:assert "少年学子" in out or "学堂" in out-def test_soften_libai_alcohol_weapon_and_title() -> None:+def test_soften_libai_removes_historical_identity() -> None:raw = ("盛唐顶流,白衣佩剑,腰悬酒葫芦,月白大袖,潇洒飘逸,羊毛毡手作风格,""暖阳柔光,眼神狂放不羁,气质超凡脱俗。。身份:诗仙。""细节精致,电影质感。")out = soften_seedream_input_text(raw)- assert "酒葫芦" not in out- assert "顶流" not in out- assert "佩剑" not in out- assert "诗仙" not in out- assert "葫芦" not in out- assert "狂放不羁" not in out- assert "电影质感" not in out- assert "盛唐洒脱文人" in out- assert "名士" in out+ for bad in ("酒葫芦", "顶流", "佩剑", "诗仙", "葫芦", "狂放不羁", "电影质感", "盛唐", "名士", "文人", "诗人"):+ assert bad not in out, bad+ assert "古风洒脱书生" in out or "书生" in out+ assert "白衣" in outdef test_compact_retry_strips_structure_prefix() -> None:@@ -52,11 +48,22 @@ def test_compact_retry_strips_structure_prefix() -> None:assert "三视图" not in compactassert "酒葫芦" not in compactassert "诗仙" not in compact+ assert "盛唐" not in compactassert "电影质感" not in compactassert "纯白背景" in compact- assert "盛唐" in compact+++def test_style_only_keeps_felt_and_robe() -> None:+ raw = "盛唐顶流,白衣佩剑,腰悬酒葫芦,身份:诗仙。羊毛毡 / 毛毡定格,粘土软萌。"+ out = style_only_seedream_prompt_for_retry(raw)+ assert "诗仙" not in out+ assert "盛唐" not in out+ assert "酒" not in out+ assert "白衣" in out+ assert "羊毛毡" in out or "毛毡" in out+ assert "纯白背景" in outdef test_soften_noop_when_clean() -> None:- raw = "白衣诗人,月白大袖,羊毛毡手作风格"+ raw = "白衣书生,月白大袖,羊毛毡手作风格"assert soften_seedream_input_text(raw) == raw