PRINTFILM: AI short-video marketing and AI short-drama creation platform
fix(drama): keep turnaround sheet prefix through Seedream soften retries
yid66a44f1d2db
diff --git a/backend/app/services/ark.py b/backend/app/services/ark.pyindex 025be8d..13663d3 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)@@ -612,7 +612,7 @@ class ArkGateway:style_only_seedream_prompt_for_retry,)- # 发送前软化易触发文本审核的措辞(保留主体,非空场景/CG 兜底)+ # 只软化用户正文,保留角色/场景/道具结构前缀(三视图等)original = (prompt or "").strip()current = soften_seedream_input_text(original)if current != original:diff --git a/backend/app/services/seedream_text_soften.py b/backend/app/services/seedream_text_soften.pyindex 54f2812..b95007b 100644--- a/backend/app/services/seedream_text_soften.py+++ b/backend/app/services/seedream_text_soften.py@@ -1,6 +1,7 @@-"""Seedream 输入文案软化:保留外形/风格,降低 InputTextSensitive 误杀。+"""Seedream 输入文案软化:保留外形/风格与设定板结构,降低 InputTextSensitive 误杀。-不做空主体 / CG 厚涂兜底;必要时压缩前缀,并去掉易被识别为历史名人的身份词。+软化只改用户正文,不改结构前缀;审核重试仍尽量保留三视图设定板。+不做空主体 / CG 厚涂兜底。"""from __future__ import annotations@@ -67,43 +68,63 @@ _STRUCTURE_BODY_MARKERS: tuple[str, ...] = ("请严格依据以下用户描述生成素材画面:",)-_COMPACT_CHARACTER_PREFIX = (- "纯白背景,单人全身角色立绘,无复杂背景、无文字水印,毛毡手作可爱风格。"+# 审核重试用的简化三视图前缀(仍要求设定板,而非单张立绘)+_COMPACT_TURNAROUND_PREFIX = (+ "【强制任务:角色设定板】纯白背景,无复杂背景、无文字水印。"+ "画面含同一角色全身三视图(正面、左侧面、背面),站姿自然、双臂下垂;"+ "并含面部特写与半身特写;五官发型服装体型一致。""请依据以下描述生成:")-# 软化易触发 Seedream 文本审核的措辞;无变化则原样返回-def soften_seedream_input_text(prompt: str) -> str:- out = prompt or ""- if not out:- return out+# 对纯文本做敏感词替换+def _replace_sensitive_terms(text: str) -> str:+ out = text or ""for src, dst in _SEEDREAM_TEXT_SOFTEN:if src in out:out = out.replace(src, dst)return out-# 拆出设定板前缀后的用户正文;无标记则返回全文-def extract_seedream_user_body(prompt: str) -> str:+# 拆出设定板前缀与用户正文;(prefix, body),无标记则 prefix 为空+def split_seedream_structure_prompt(prompt: str) -> tuple[str, str]:text = prompt or ""for marker in _STRUCTURE_BODY_MARKERS:if marker in text:- return text.split(marker, 1)[1].strip()- return text.strip()+ prefix, body = text.split(marker, 1)+ return f"{prefix}{marker}", body.strip()+ return "", text.strip()+++# 软化易触发审核的措辞:只改用户正文,保留结构前缀(三视图等)+def soften_seedream_input_text(prompt: str) -> str:+ text = prompt or ""+ if not text:+ return text+ prefix, body = split_seedream_structure_prompt(text)+ soft_body = _replace_sensitive_terms(body)+ if prefix:+ return f"{prefix}{soft_body}"+ return soft_body+++# 拆出设定板前缀后的用户正文;无标记则返回全文+def extract_seedream_user_body(prompt: str) -> str:+ _, body = split_seedream_structure_prompt(prompt or "")+ return body-# 文本审核失败后的压缩重试:短前缀 + 再软化正文(仍保留主体)+# 文本审核失败后的压缩重试:简化三视图前缀 + 软化正文def compact_seedream_prompt_for_retry(prompt: str) -> str:- body = soften_seedream_input_text(extract_seedream_user_body(prompt))+ body = _replace_sensitive_terms(extract_seedream_user_body(prompt))if not body:- body = soften_seedream_input_text(prompt or "")- return f"{_COMPACT_CHARACTER_PREFIX}{body}"+ body = _replace_sensitive_terms(prompt or "")+ return f"{_COMPACT_TURNAROUND_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 "")+ body = _replace_sensitive_terms(extract_seedream_user_body(prompt) or prompt or "")style_bits: list[str] = []for key in ("羊毛毡",@@ -122,7 +143,7 @@ def style_only_seedream_prompt_for_retry(prompt: str) -> str:style = "、".join(style_bits) if style_bits else "手作可爱质感"robe = "白衣宽袖" if ("白衣" in body or "月白" in body) else "古风常服"return (- f"纯白背景,单人全身立绘,{robe}青年书生,腰间圆润佩饰,"- f"{style},轮廓略不规整,针孔与绒感清晰,无文字水印,"- "禁止真实历史人物肖像。"+ f"{_COMPACT_TURNAROUND_PREFIX}"+ f"{robe}青年书生,腰间圆润佩饰,{style},"+ "轮廓略不规整,针孔与绒感清晰,禁止真实历史人物肖像。")diff --git a/backend/tests/test_seedream_text_soften.py b/backend/tests/test_seedream_text_soften.pyindex 0668ac2..db0e289 100644--- a/backend/tests/test_seedream_text_soften.py+++ b/backend/tests/test_seedream_text_soften.py@@ -1,6 +1,7 @@"""seedream_text_soften 单元测试。"""from __future__ import annotations+from app.services.drama.generation_prompt import CHARACTER_PROMPT_PREFIX, build_generation_promptfrom app.services.seedream_text_soften import (compact_seedream_prompt_for_retry,soften_seedream_input_text,@@ -8,6 +9,19 @@ from app.services.seedream_text_soften import ()+def test_soften_preserves_turnaround_prefix() -> None:+ raw = "盛唐顶流,白衣佩剑,腰悬酒葫芦,身份:诗仙。电影质感。"+ full = build_generation_prompt(raw, asset_type="character")+ soft = soften_seedream_input_text(full)+ assert soft.startswith(CHARACTER_PROMPT_PREFIX) or "全身三视图" in soft+ assert "正面全身站姿" in soft+ assert "左侧面全身站姿" in soft+ assert "背面全身站姿" in soft+ assert "诗仙" not in soft+ assert "酒葫芦" not in soft+ assert "盛唐" not in soft++def test_soften_xiaoxuesheng_and_child_terms() -> None:raw = ("毛毡教室剪影,课桌后坐着齐刷刷毛毡小人,穿着现代校服,"@@ -16,54 +30,31 @@ def test_soften_xiaoxuesheng_and_child_terms() -> None:out = soften_seedream_input_text(raw)assert "小学生" not in outassert "童声" not in out- assert "童真" not in outassert "校服" not in outassert "课堂" not in outassert "学生" not in out- assert "毛毡小人" not in out- assert "少年学子" in out or "学堂" in out---def test_soften_libai_removes_historical_identity() -> None:- raw = (- "盛唐顶流,白衣佩剑,腰悬酒葫芦,月白大袖,潇洒飘逸,羊毛毡手作风格,"- "暖阳柔光,眼神狂放不羁,气质超凡脱俗。。身份:诗仙。"- "细节精致,电影质感。"- )- out = soften_seedream_input_text(raw)- for bad in ("酒葫芦", "顶流", "佩剑", "诗仙", "葫芦", "狂放不羁", "电影质感", "盛唐", "名士", "文人", "诗人"):- assert bad not in out, bad- assert "古风洒脱书生" in out or "书生" in out- assert "白衣" in out-def test_compact_retry_strips_structure_prefix() -> None:+def test_compact_retry_keeps_turnaround() -> None:full = ("【强制任务:角色设定板构图】很长前缀。""请严格依据以下用户描述生成上述结构的角色设定图:""盛唐顶流,白衣佩剑,腰悬酒葫芦,身份:诗仙。电影质感。")compact = compact_seedream_prompt_for_retry(full)- assert "设定板构图" not in compact- assert "三视图" not in compact+ assert "三视图" in compact+ assert "正面" in compact and "背面" in compactassert "酒葫芦" not in compactassert "诗仙" not in compactassert "盛唐" not in compact- assert "电影质感" not in compact- assert "纯白背景" in compact-def test_style_only_keeps_felt_and_robe() -> None:+def test_style_only_keeps_turnaround_and_felt() -> None:raw = "盛唐顶流,白衣佩剑,腰悬酒葫芦,身份:诗仙。羊毛毡 / 毛毡定格,粘土软萌。"out = style_only_seedream_prompt_for_retry(raw)+ assert "三视图" in outassert "诗仙" not in outassert "盛唐" not in outassert "酒" not in outassert "白衣" in outassert "羊毛毡" in out or "毛毡" in out- assert "纯白背景" in out---def test_soften_noop_when_clean() -> None:- raw = "白衣书生,月白大袖,羊毛毡手作风格"- assert soften_seedream_input_text(raw) == raw