Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ee5a4042d | |||
| a979af1488 | |||
| 77e19a6b44 | |||
| e4c3f9a046 | |||
| 902effc1f9 | |||
| a408cfdc97 | |||
| 9464322710 | |||
| aa1f318308 | |||
| 3a59948f53 |
@@ -0,0 +1,242 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""image_analysis v8 prompt + storyboard v3 prompt - 用户端展示格式 markdown 控制
|
||||
|
||||
Revision ID: 104_v8_display_markdown
|
||||
Revises: 103_v7_prompt_and_tokens_3000
|
||||
Create Date: 2026-10-07
|
||||
|
||||
变更:
|
||||
1. image_analysis v8: 在 v7 基础上 system_prompt 末尾追加「## 用户端展示格式」章节,
|
||||
要求 VLM 在每张图的 JSON 里输出 summary_markdown 字段(markdown 格式的图片描述),
|
||||
v8 设 is_active=true,v7 设 is_active=false。
|
||||
2. storyboard v3: 在 v2 基础上 system_prompt 追加要求 LLM 在 copy_result 中
|
||||
输出 copy_display_markdown 字段(markdown 格式的完整文案展示),
|
||||
v3 设 is_active=true,v2 设 is_active=false。
|
||||
"""
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "104_v8_display_markdown"
|
||||
down_revision = "103_v7_prompt_and_tokens_3000"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
# ── v8 追加的 system prompt 内容 ──────────────────────────────────────
|
||||
V8_SYSTEM_APPEND = """
|
||||
|
||||
## 用户端展示格式
|
||||
|
||||
对于每张分析的图片,在 JSON 中额外输出一个 **summary_markdown** 字段,用 markdown 格式写出给用户看的图片描述。
|
||||
|
||||
格式要求(根据图片类型自适应):
|
||||
|
||||
**商品图(type=product)**示例:
|
||||
### 商品名称
|
||||
**品牌**:品牌名 | **类目**:服饰鞋包/美妆/数码/...
|
||||
**核心特征**
|
||||
- 特征1:描述
|
||||
- 特征2:描述
|
||||
**外观**:颜色+材质+设计描述
|
||||
**包装**:包装类型描述
|
||||
**文字信息**:包装上看到的文字
|
||||
|
||||
**门店场景图(type=store)**示例:
|
||||
### 门店名称/类型
|
||||
**类型**:奶茶店/便利店/养生馆/...
|
||||
**品牌标识**:招牌文字描述
|
||||
**环境氛围**:店内整体感觉
|
||||
**陈列亮点**
|
||||
- 亮点1
|
||||
- 亮点2
|
||||
**氛围**:亲民/专业/时尚/...
|
||||
|
||||
**人物图(type=person)**示例:
|
||||
### 人物描述
|
||||
**形象**:年龄段 + 风格
|
||||
**穿搭**
|
||||
- 上装:颜色+款式
|
||||
- 下装:颜色+款式
|
||||
- 配饰:...
|
||||
**气质**:表情+姿势+整体感觉
|
||||
|
||||
**风景/场景图(type=scene)**示例:
|
||||
### 场景名称
|
||||
**类型**:自然风景/城市街景/动物/美食
|
||||
**主体**:画面主要元素
|
||||
**氛围**:整体感觉描述
|
||||
|
||||
要求:
|
||||
- 内容真实具体,从实际图片分析得出
|
||||
- 用 markdown 语法:**加粗**、列表、标题
|
||||
- 控制在 100-200 字
|
||||
- 不要编造图片中没有的信息
|
||||
"""
|
||||
|
||||
# ── storyboard v3 追加的 system prompt 内容 ──────────────────────────
|
||||
V3_STORYBOARD_APPEND = """
|
||||
|
||||
## 用户端展示格式
|
||||
|
||||
在输出分镜脚本的同时,在顶层输出一个 **copy_display_markdown** 字段(用 XML 标签 <copy_display_markdown> 包裹),用 markdown 格式写出完整文案展示。
|
||||
|
||||
格式示例:
|
||||
# 标题/主题
|
||||
|
||||
## 整体概要
|
||||
一句话描述视频内容
|
||||
|
||||
## 分镜预览
|
||||
|
||||
### 镜头1(0-3秒)
|
||||
**景别**:近景俯拍,缓慢推镜
|
||||
**画面**:场景描述
|
||||
**台词**:口播文本
|
||||
**动作**:人物动作描述
|
||||
|
||||
### 镜头2(3-9秒)
|
||||
...
|
||||
|
||||
## 完整口播
|
||||
完整口播文案文本
|
||||
|
||||
要求:
|
||||
- 把所有分镜按时间顺序整理成易读的格式
|
||||
- 用 markdown 语法组织,**加粗**标签、##二级标题、列表等
|
||||
- 控制在 300-500 字
|
||||
- 让用户一眼看懂视频会拍成什么样
|
||||
"""
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
|
||||
# ── 1. image_analysis v8 ──────────────────────────────────────────
|
||||
# 停用所有 active image_analysis prompt
|
||||
bind.execute(
|
||||
text(
|
||||
"UPDATE viral_video_prompt_templates SET is_active = FALSE "
|
||||
"WHERE prompt_type = 'image_analysis' AND is_active = TRUE"
|
||||
)
|
||||
)
|
||||
|
||||
# 读取 v7 的 prompt 内容作为基础
|
||||
v7_row = bind.execute(
|
||||
text(
|
||||
"SELECT system_prompt, user_prompt_template, COALESCE(example_output, '') "
|
||||
"FROM viral_video_prompt_templates "
|
||||
"WHERE prompt_type = 'image_analysis' "
|
||||
"ORDER BY version DESC LIMIT 1"
|
||||
)
|
||||
).fetchone()
|
||||
|
||||
if v7_row:
|
||||
v7_system = v7_row[0] or ""
|
||||
v8_system = v7_system + V8_SYSTEM_APPEND
|
||||
v8_user = v7_row[1] or "{image_url}"
|
||||
v8_example = v7_row[2] or ""
|
||||
|
||||
# 幂等:已有 v8 则更新,否则插入
|
||||
existing_v8 = bind.execute(
|
||||
text("SELECT id FROM viral_video_prompt_templates " "WHERE prompt_type = 'image_analysis' AND version = 8")
|
||||
).fetchone()
|
||||
if existing_v8:
|
||||
bind.execute(
|
||||
text(
|
||||
"UPDATE viral_video_prompt_templates SET is_active = TRUE, "
|
||||
"system_prompt = :sys, user_prompt_template = :usr, "
|
||||
"example_output = :ex, name = 'v8 用户端展示格式', "
|
||||
"updated_at = NOW() "
|
||||
"WHERE prompt_type = 'image_analysis' AND version = 8"
|
||||
),
|
||||
{"sys": v8_system, "usr": v8_user, "ex": v8_example},
|
||||
)
|
||||
else:
|
||||
bind.execute(
|
||||
text(
|
||||
"INSERT INTO viral_video_prompt_templates "
|
||||
"(prompt_type, version, name, system_prompt, user_prompt_template, "
|
||||
"example_output, is_active, created_at, updated_at) "
|
||||
"VALUES ('image_analysis', 8, 'v8 用户端展示格式', "
|
||||
":sys, :usr, :ex, TRUE, NOW(), NOW())"
|
||||
),
|
||||
{"sys": v8_system, "usr": v8_user, "ex": v8_example},
|
||||
)
|
||||
|
||||
# ── 2. storyboard v3 ─────────────────────────────────────────────
|
||||
# 停用所有 active storyboard prompt
|
||||
bind.execute(
|
||||
text(
|
||||
"UPDATE viral_video_prompt_templates SET is_active = FALSE "
|
||||
"WHERE prompt_type = 'storyboard' AND is_active = TRUE"
|
||||
)
|
||||
)
|
||||
|
||||
# 读取当前 storyboard prompt
|
||||
sb_row = bind.execute(
|
||||
text(
|
||||
"SELECT system_prompt, user_prompt_template, COALESCE(example_output, '') "
|
||||
"FROM viral_video_prompt_templates "
|
||||
"WHERE prompt_type = 'storyboard' "
|
||||
"ORDER BY version DESC LIMIT 1"
|
||||
)
|
||||
).fetchone()
|
||||
|
||||
if sb_row:
|
||||
sb_system = sb_row[0] or ""
|
||||
v3_system = sb_system + V3_STORYBOARD_APPEND
|
||||
v3_user = sb_row[1] or ""
|
||||
v3_example = sb_row[2] or ""
|
||||
|
||||
existing_v3 = bind.execute(
|
||||
text("SELECT id FROM viral_video_prompt_templates " "WHERE prompt_type = 'storyboard' AND version = 3")
|
||||
).fetchone()
|
||||
if existing_v3:
|
||||
bind.execute(
|
||||
text(
|
||||
"UPDATE viral_video_prompt_templates SET is_active = TRUE, "
|
||||
"system_prompt = :sys, user_prompt_template = :usr, "
|
||||
"example_output = :ex, name = 'v3 用户端展示格式', "
|
||||
"updated_at = NOW() "
|
||||
"WHERE prompt_type = 'storyboard' AND version = 3"
|
||||
),
|
||||
{"sys": v3_system, "usr": v3_user, "ex": v3_example},
|
||||
)
|
||||
else:
|
||||
bind.execute(
|
||||
text(
|
||||
"INSERT INTO viral_video_prompt_templates "
|
||||
"(prompt_type, version, name, system_prompt, user_prompt_template, "
|
||||
"example_output, is_active, created_at, updated_at) "
|
||||
"VALUES ('storyboard', 3, 'v3 用户端展示格式', "
|
||||
":sys, :usr, :ex, TRUE, NOW(), NOW())"
|
||||
),
|
||||
{"sys": v3_system, "usr": v3_user, "ex": v3_example},
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
|
||||
# 删除 v8
|
||||
bind.execute(
|
||||
text("DELETE FROM viral_video_prompt_templates " "WHERE prompt_type = 'image_analysis' AND version = 8")
|
||||
)
|
||||
# 恢复 v7 active
|
||||
bind.execute(
|
||||
text(
|
||||
"UPDATE viral_video_prompt_templates SET is_active = TRUE, updated_at = NOW() "
|
||||
"WHERE prompt_type = 'image_analysis' AND version = 7"
|
||||
)
|
||||
)
|
||||
|
||||
# 删除 v3
|
||||
bind.execute(text("DELETE FROM viral_video_prompt_templates " "WHERE prompt_type = 'storyboard' AND version = 3"))
|
||||
# 恢复 storyboard v2 active
|
||||
bind.execute(
|
||||
text(
|
||||
"UPDATE viral_video_prompt_templates SET is_active = TRUE, updated_at = NOW() "
|
||||
"WHERE prompt_type = 'storyboard' AND version = 2"
|
||||
)
|
||||
)
|
||||
Generated
+12
@@ -14,6 +14,7 @@
|
||||
"axios": "^1.7.2",
|
||||
"classnames": "^2.5.1",
|
||||
"dayjs": "^1.11.23",
|
||||
"marked": "^12.0.2",
|
||||
"mp4box": "^2.4.1",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
@@ -4502,6 +4503,17 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/marked": {
|
||||
"version": "12.0.2",
|
||||
"resolved": "https://registry.npmmirror.com/marked/-/marked-12.0.2.tgz",
|
||||
"integrity": "sha512-qXUm7e/YKFoqFPYPa3Ukg9xlI5cyAtGmyEIzMfW//m6kXwCy2Ps9DYf5ioijFKQ8qyuscrHoY04iJGctu2Kg0Q==",
|
||||
"bin": {
|
||||
"marked": "bin/marked.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"axios": "^1.7.2",
|
||||
"classnames": "^2.5.1",
|
||||
"dayjs": "^1.11.23",
|
||||
"marked": "^12.0.2",
|
||||
"mp4box": "^2.4.1",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
|
||||
@@ -83,6 +83,8 @@ export interface ImageProductAnalysis {
|
||||
label_text?: string
|
||||
selling_points?: string
|
||||
image_index?: number
|
||||
/** v8: 用户端展示用的 markdown 描述(由提示词控制排版) */
|
||||
summary_markdown?: string
|
||||
}
|
||||
|
||||
export interface ImageAnalysisResult {
|
||||
@@ -132,6 +134,8 @@ export interface CopyResult {
|
||||
/** 向后兼容:= voiceover_script */
|
||||
suggested_copy?: string
|
||||
title?: string
|
||||
/** v3 storyboard: 用户端展示用的 markdown 文案(由提示词控制排版) */
|
||||
copy_display_markdown?: string
|
||||
/** v1.5 旧字段兼容(老数据降级时可能出现) */
|
||||
scenes?: Array<{ shot: string; narration: string; duration?: number }>
|
||||
}
|
||||
|
||||
@@ -1973,3 +1973,99 @@
|
||||
padding-bottom: 6px;
|
||||
border-bottom: 1px dashed #e5e7eb;
|
||||
}
|
||||
|
||||
/* ─────────── markdown 渲染(提示词控制展示格式) ─────────── */
|
||||
.vv-recog-md {
|
||||
padding: 4px 0;
|
||||
}
|
||||
.vv-copy-preview {
|
||||
margin-bottom: 14px;
|
||||
padding: 12px 14px;
|
||||
background: linear-gradient(180deg, #faf7ff 0%, #f6f2ff 100%);
|
||||
border: 1px solid #ece4fb;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.vv-copy-preview-h {
|
||||
margin: 0 0 8px;
|
||||
border-bottom: none;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
.vv-md-body {
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
color: #374151;
|
||||
word-break: break-word;
|
||||
}
|
||||
.vv-md-body h1,
|
||||
.vv-md-body h2,
|
||||
.vv-md-body h3,
|
||||
.vv-md-body h4 {
|
||||
margin: 10px 0 6px;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.vv-md-body h1 {
|
||||
font-size: 18px;
|
||||
}
|
||||
.vv-md-body h2 {
|
||||
font-size: 16px;
|
||||
}
|
||||
.vv-md-body h3 {
|
||||
font-size: 15px;
|
||||
}
|
||||
.vv-md-body h4 {
|
||||
font-size: 14px;
|
||||
}
|
||||
.vv-md-body p {
|
||||
margin: 6px 0;
|
||||
}
|
||||
.vv-md-body ul,
|
||||
.vv-md-body ol {
|
||||
margin: 6px 0;
|
||||
padding-left: 20px;
|
||||
}
|
||||
.vv-md-body li {
|
||||
margin: 3px 0;
|
||||
}
|
||||
.vv-md-body strong {
|
||||
color: #111827;
|
||||
font-weight: 600;
|
||||
}
|
||||
.vv-md-body blockquote {
|
||||
margin: 8px 0;
|
||||
padding: 4px 12px;
|
||||
border-left: 3px solid #7c3aed;
|
||||
background: rgba(124, 58, 237, 0.05);
|
||||
color: #4b5563;
|
||||
}
|
||||
.vv-md-body code {
|
||||
padding: 1px 5px;
|
||||
background: #f3f4f6;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
color: #be185d;
|
||||
}
|
||||
.vv-md-body a {
|
||||
color: #7c3aed;
|
||||
text-decoration: none;
|
||||
}
|
||||
.vv-md-body a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.vv-md-body table {
|
||||
border-collapse: collapse;
|
||||
margin: 8px 0;
|
||||
width: 100%;
|
||||
}
|
||||
.vv-md-body th,
|
||||
.vv-md-body td {
|
||||
border: 1px solid #e5e7eb;
|
||||
padding: 6px 10px;
|
||||
text-align: left;
|
||||
}
|
||||
.vv-md-body hr {
|
||||
border: none;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React, { useCallback, useEffect, useRef, useState } from "react"
|
||||
import axios from "axios"
|
||||
import { marked } from "marked"
|
||||
import {
|
||||
PlusOutlined,
|
||||
CloseOutlined,
|
||||
@@ -150,6 +151,16 @@ type TabTask = {
|
||||
audioInst: HTMLAudioElement | null
|
||||
}
|
||||
|
||||
/* ── marked 配置:禁用 mangle/headerIds,输出干净 HTML ── */
|
||||
marked.setOptions({ gfm: true, breaks: false })
|
||||
const renderMarkdown = (md: string): string => {
|
||||
try {
|
||||
return marked.parse(md ?? "", { async: false }) as string
|
||||
} catch {
|
||||
return (md ?? "").replace(/&/g, "&").replace(/</g, "<")
|
||||
}
|
||||
}
|
||||
|
||||
/* ─────────── 常量 ─────────── */
|
||||
|
||||
const LANGUAGES = ["中文(普通话)", "粤语", "英语", "日语", "韩语"]
|
||||
@@ -296,6 +307,8 @@ interface Storyboard {
|
||||
hard_constraints: string[]
|
||||
negative_prompts: string[]
|
||||
voiceover_script: string
|
||||
/** v3: 用户端展示用 markdown 文案(由提示词控制排版) */
|
||||
copy_display_markdown: string
|
||||
}
|
||||
|
||||
/** 兼容旧 copy_result(final_copy/title/scenes)→ 新 Storyboard 结构 */
|
||||
@@ -323,6 +336,7 @@ function copyResultToStoryboard(cr: CopyResult | null | undefined): Storyboard |
|
||||
hard_constraints: Array.isArray(cr.hard_constraints) ? cr.hard_constraints : [],
|
||||
negative_prompts: Array.isArray(cr.negative_prompts) ? cr.negative_prompts : [],
|
||||
voiceover_script: cr.voiceover_script || cr.final_copy || cr.suggested_copy || "",
|
||||
copy_display_markdown: cr.copy_display_markdown || "",
|
||||
}
|
||||
}
|
||||
// 兜底:旧结构转简单分镜
|
||||
@@ -358,6 +372,7 @@ function copyResultToStoryboard(cr: CopyResult | null | undefined): Storyboard |
|
||||
hard_constraints: [],
|
||||
negative_prompts: [],
|
||||
voiceover_script: finalCopy,
|
||||
copy_display_markdown: cr.copy_display_markdown || "",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,6 +427,7 @@ const MOCK_STORYBOARD: Storyboard = {
|
||||
negative_prompts: ["冷色调", "模糊", "变形", "水印文字", "卡通风格", "空无一人"],
|
||||
voiceover_script:
|
||||
"还在为餐桌选不到好桌子发愁?这张北美黑胡桃木餐桌,一家人坐下来吃饭刚刚好。全实木、无贴皮,纹理好看又耐刮。点小黄车,给家里添一张好桌子。",
|
||||
copy_display_markdown: "",
|
||||
}
|
||||
|
||||
const fmtSize = (bytes: number | undefined) => {
|
||||
@@ -1217,67 +1233,76 @@ const ViralVideoPage: React.FC = () => {
|
||||
<CheckCircleFilled style={{ color: "#10b981" }} />
|
||||
识别描述汇览
|
||||
</div>
|
||||
{products.map((p, i) => (
|
||||
<div key={i} className="vv-recog-item">
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">图片{i + 1}:</span>
|
||||
<span>
|
||||
{p.name || "未识别"}
|
||||
{p.spec && <span className="vv-recog-meta">({p.spec})</span>}
|
||||
{p.brand && <span className="vv-recog-meta"> · {p.brand}</span>}
|
||||
{p.category && <span className="vv-recog-meta"> · {p.category}</span>}
|
||||
</span>
|
||||
{products.map((p, i) =>
|
||||
p.summary_markdown ? (
|
||||
<div key={i} className="vv-recog-item vv-recog-md">
|
||||
<div
|
||||
className="vv-md-body"
|
||||
dangerouslySetInnerHTML={{ __html: renderMarkdown(p.summary_markdown) }}
|
||||
/>
|
||||
</div>
|
||||
{featureText(p.key_features ?? p.features) && (
|
||||
) : (
|
||||
<div key={i} className="vv-recog-item">
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">核心特征:</span>
|
||||
<span className="vv-recog-v">{featureText(p.key_features ?? p.features)}</span>
|
||||
<span className="vv-recog-k">图片{i + 1}:</span>
|
||||
<span>
|
||||
{p.name || "未识别"}
|
||||
{p.spec && <span className="vv-recog-meta">({p.spec})</span>}
|
||||
{p.brand && <span className="vv-recog-meta"> · {p.brand}</span>}
|
||||
{p.category && <span className="vv-recog-meta"> · {p.category}</span>}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{p.colors && p.colors.length > 0 && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">主色调:</span>
|
||||
<span className="vv-recog-v">{p.colors.join(" / ")}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.material_or_texture && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">材质/纹理:</span>
|
||||
<span className="vv-recog-v">{p.material_or_texture}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.visual_style && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">视觉风格:</span>
|
||||
<span className="vv-recog-v">{p.visual_style}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.scene && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">场景:</span>
|
||||
<span className="vv-recog-v">{p.scene}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.target_audience_hint && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">目标人群:</span>
|
||||
<span className="vv-recog-v">{p.target_audience_hint}</span>
|
||||
</div>
|
||||
)}
|
||||
{(p.text_on_image || p.label_text) && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">包装文字:</span>
|
||||
<span className="vv-recog-v">{p.text_on_image || p.label_text}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.selling_points && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">卖点:</span>
|
||||
<span className="vv-recog-v">{p.selling_points}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{featureText(p.key_features ?? p.features) && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">核心特征:</span>
|
||||
<span className="vv-recog-v">{featureText(p.key_features ?? p.features)}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.colors && p.colors.length > 0 && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">主色调:</span>
|
||||
<span className="vv-recog-v">{p.colors.join(" / ")}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.material_or_texture && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">材质/纹理:</span>
|
||||
<span className="vv-recog-v">{p.material_or_texture}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.visual_style && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">视觉风格:</span>
|
||||
<span className="vv-recog-v">{p.visual_style}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.scene && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">场景:</span>
|
||||
<span className="vv-recog-v">{p.scene}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.target_audience_hint && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">目标人群:</span>
|
||||
<span className="vv-recog-v">{p.target_audience_hint}</span>
|
||||
</div>
|
||||
)}
|
||||
{(p.text_on_image || p.label_text) && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">包装文字:</span>
|
||||
<span className="vv-recog-v">{p.text_on_image || p.label_text}</span>
|
||||
</div>
|
||||
)}
|
||||
{p.selling_points && (
|
||||
<div className="vv-recog-line">
|
||||
<span className="vv-recog-k">卖点:</span>
|
||||
<span className="vv-recog-v">{p.selling_points}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1416,6 +1441,19 @@ const ViralVideoPage: React.FC = () => {
|
||||
return (
|
||||
<div className="vv-copy-box vv-storyboard">
|
||||
<div className="vv-sb-doc">
|
||||
{/* 文案预览(提示词控制排版,只读;编辑在下方分镜字段中进行) */}
|
||||
{sb.copy_display_markdown && (
|
||||
<div className="vv-copy-preview">
|
||||
<h4 className="vv-sb-h vv-copy-preview-h">
|
||||
<FileTextOutlined style={{ color: "#7c3aed", marginRight: 6 }} />
|
||||
文案预览
|
||||
</h4>
|
||||
<div
|
||||
className="vv-md-body"
|
||||
dangerouslySetInnerHTML={{ __html: renderMarkdown(sb.copy_display_markdown) }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{/* 视频总览 */}
|
||||
<h4 className="vv-sb-h">视频总览</h4>
|
||||
<p className="vv-sb-inline-row">
|
||||
|
||||
@@ -948,6 +948,10 @@ def _script_from_xml(raw: str, job: ViralVideoJob) -> dict | None:
|
||||
base["final_copy"] = joined
|
||||
base["suggested_copy"] = joined
|
||||
base["title"] = base["overview"]["theme"]
|
||||
# 提取 copy_display_markdown(用户端展示格式)
|
||||
copy_display_md = xp.text_of(raw, "copy_display_markdown")
|
||||
if copy_display_md:
|
||||
base["copy_display_markdown"] = copy_display_md
|
||||
return base
|
||||
|
||||
|
||||
@@ -2072,18 +2076,27 @@ def _run_render_pipeline(job_id: str, session, repo, job) -> dict:
|
||||
try:
|
||||
review_result = _step_review(job, copy_result)
|
||||
if not review_result.get("passed", True):
|
||||
_emit_progress(job_id, ViralVideoStage.REVIEW, 67.0, "审核未通过,正在自动重写...")
|
||||
# #2040: Reviewer 已在 _step_review 内完成 1 次自动重写
|
||||
rewritten = review_result.get("rewritten_copy")
|
||||
if isinstance(rewritten, dict) and rewritten:
|
||||
copy_result = rewritten
|
||||
else:
|
||||
# #2218: 审核重写失败不再从意图解析重跑,直接报错让用户重新生成文案
|
||||
logger.error(
|
||||
"[爆款视频][阶段3] 合规审核未通过且自动重写失败 job_id=%s,终止渲染",
|
||||
# #2233: 如果issues为空但passed=False,说明是LLM超时/异常导致的误判,降级放行
|
||||
_issues = review_result.get("issues") or []
|
||||
if not _issues:
|
||||
logger.warning(
|
||||
"[爆款视频][阶段3] 审核未通过但无具体问题(可能LLM超时),降级放行 job_id=%s",
|
||||
job_id,
|
||||
)
|
||||
raise ValueError("文案合规审核未通过,请修改文案后重试或重新生成文案")
|
||||
review_result["passed"] = True
|
||||
else:
|
||||
_emit_progress(job_id, ViralVideoStage.REVIEW, 67.0, "审核未通过,正在自动重写...")
|
||||
# #2040: Reviewer 已在 _step_review 内完成 1 次自动重写
|
||||
rewritten = review_result.get("rewritten_copy")
|
||||
if isinstance(rewritten, dict) and rewritten:
|
||||
copy_result = rewritten
|
||||
else:
|
||||
# #2218: 审核重写失败不再从意图解析重跑,直接报错让用户重新生成文案
|
||||
logger.error(
|
||||
"[爆款视频][阶段3] 合规审核未通过且自动重写失败 job_id=%s,终止渲染",
|
||||
job_id,
|
||||
)
|
||||
raise ValueError("文案合规审核未通过,请修改文案后重试或重新生成文案")
|
||||
job.copy_result = copy_result
|
||||
job.generated_copy_text = copy_result.get("voiceover_script", "") or ""
|
||||
_save_job(repo, job, session)
|
||||
|
||||
@@ -22,6 +22,90 @@ _AGE_PREFIX = {"青年": "年轻", "中年": "中年", "老年": "老年"}
|
||||
_GENDER_WORD = {"男": "男性", "女": "女性"}
|
||||
|
||||
|
||||
def _build_summary_markdown(product: dict) -> str:
|
||||
"""根据结构化字段生成 summary_markdown 兜底(VLM未返回时调用)。"""
|
||||
p = product or {}
|
||||
name = p.get("name") or "未识别"
|
||||
brand = p.get("brand") or ""
|
||||
category = p.get("category") or ""
|
||||
appearance = p.get("appearance") or ""
|
||||
packaging = p.get("packaging") or ""
|
||||
scene = p.get("scene") or ""
|
||||
mood = p.get("mood") or ""
|
||||
key_features = p.get("key_features") or []
|
||||
text_on_package = p.get("text_on_package") or []
|
||||
store_type = p.get("store_type") or ""
|
||||
brand_signage = p.get("brand_signage") or ""
|
||||
visual_elements = p.get("visual_elements") or []
|
||||
atmosphere = p.get("atmosphere") or ""
|
||||
outfit_style = p.get("outfit_style") or ""
|
||||
upper_wear = p.get("upper_wear") or ""
|
||||
lower_wear = p.get("lower_wear") or ""
|
||||
expression = p.get("expression") or ""
|
||||
has_person = p.get("has_person", False)
|
||||
person_count = p.get("person_count") or 0
|
||||
|
||||
lines = []
|
||||
|
||||
# 门店场景
|
||||
if store_type or "门店" in str(category) or "店铺" in str(category):
|
||||
lines.append(f"### {brand_signage or store_type or '门店'}")
|
||||
if store_type:
|
||||
lines.append(f"**类型**:{store_type}")
|
||||
if brand_signage:
|
||||
lines.append(f"**品牌标识**:{brand_signage}")
|
||||
if atmosphere:
|
||||
lines.append(f"**氛围**:{atmosphere}")
|
||||
if visual_elements:
|
||||
lines.append("**陈列亮点**")
|
||||
for e in visual_elements[:5]:
|
||||
lines.append(f"- {e}")
|
||||
return "\n".join(lines)
|
||||
|
||||
# 人物
|
||||
if has_person or person_count or outfit_style:
|
||||
lines.append("### 人物描述")
|
||||
if person_count:
|
||||
lines.append(f"**人数**:{person_count}人")
|
||||
if outfit_style:
|
||||
lines.append(f"**风格**:{outfit_style}")
|
||||
wear_parts = []
|
||||
if upper_wear:
|
||||
wear_parts.append(f"上装:{upper_wear}")
|
||||
if lower_wear:
|
||||
wear_parts.append(f"下装:{lower_wear}")
|
||||
if wear_parts:
|
||||
lines.append("**穿搭**")
|
||||
for w in wear_parts:
|
||||
lines.append(f"- {w}")
|
||||
if expression:
|
||||
lines.append(f"**气质**:{expression}")
|
||||
return "\n".join(lines)
|
||||
|
||||
# 商品(默认)
|
||||
lines.append(f"### {name}")
|
||||
if brand and brand != "无法判断":
|
||||
lines.append(f"**品牌**:{brand}")
|
||||
if category and category != "非产品图" and category != "无法判断":
|
||||
lines.append(f"**类目**:{category}")
|
||||
if key_features:
|
||||
lines.append("**核心特征**")
|
||||
for kf in key_features[:5]:
|
||||
lines.append(f"- {kf}")
|
||||
if appearance:
|
||||
lines.append(f"**外观**:{appearance[:100]}")
|
||||
if packaging and packaging != "无法判断":
|
||||
lines.append(f"**包装**:{packaging}")
|
||||
if text_on_package:
|
||||
lines.append(f"**文字信息**:{'、'.join(text_on_package[:3])}")
|
||||
if scene and scene != "通用":
|
||||
lines.append(f"**场景**:{scene}")
|
||||
if mood:
|
||||
lines.append(f"**氛围**:{mood}")
|
||||
|
||||
return "\n".join(lines) if lines else f"### {name}\n暂无详细描述"
|
||||
|
||||
|
||||
def _person_subject(gender: str, age: str) -> str:
|
||||
gw = _GENDER_WORD.get(gender, "")
|
||||
if age == "儿童":
|
||||
@@ -384,7 +468,11 @@ def assemble_result(idx: int, fast_json: dict | None, ocr_texts: list[str]) -> d
|
||||
result = _assemble_v4(idx, fj, ocr_texts)
|
||||
else:
|
||||
result = _assemble_old(idx, fj, ocr_texts)
|
||||
return _apply_partial_fallback(result, fj)
|
||||
result = _apply_partial_fallback(result, fj)
|
||||
# summary_markdown: 优先用VLM输出,否则兜底生成
|
||||
if "summary_markdown" not in result or not result.get("summary_markdown"):
|
||||
result["summary_markdown"] = _build_summary_markdown(result)
|
||||
return result
|
||||
|
||||
|
||||
def _apply_partial_fallback(result: dict[str, Any], fj: dict) -> dict[str, Any]:
|
||||
@@ -681,8 +769,13 @@ def _assemble_v4(idx: int, fj: dict, ocr_texts: list[str]) -> dict[str, Any]:
|
||||
brand = "无法判断"
|
||||
else:
|
||||
brand = brand_raw
|
||||
# name兜底:store_type为空时用brand
|
||||
name = store_type if store_type != "店铺" else (brand if brand != "无法判断" else store_type)
|
||||
# name兜底:更保守的策略
|
||||
# - store_type有具体值(非"店铺")时直接用store_type
|
||||
# - store_type为默认"店铺"时,用"门店门头"而非brand(避免与brand字段重复)
|
||||
if store_type and store_type != "店铺":
|
||||
name = store_type
|
||||
else:
|
||||
name = "门店门头"
|
||||
category = "门店场景"
|
||||
# appearance: store_layout + furnishings + 陈设色调
|
||||
appearance_parts = []
|
||||
|
||||
@@ -53,6 +53,9 @@ _LOCATIONS = ["title", "hook", "body_points", "cta", "script_segments"]
|
||||
|
||||
|
||||
class Reviewer:
|
||||
# markdown展示字段不参与合规审核(避免格式字符误判)
|
||||
_MARKDOWN_FIELDS = {"summary_markdown", "copy_display_markdown"}
|
||||
|
||||
def __init__(self, client=None):
|
||||
if client is None:
|
||||
try:
|
||||
@@ -70,8 +73,9 @@ class Reviewer:
|
||||
local = self._rule_check(fusion, intent, fusion_level)
|
||||
llm_result = self._llm_review(fusion, intent, fusion_level)
|
||||
if llm_result is None:
|
||||
# LLM审核失败(超时/网络错误等),降级放行,不阻断渲染
|
||||
return ReviewResult(
|
||||
passed=not local,
|
||||
passed=True,
|
||||
issues=local,
|
||||
rewrite_suggestions=[],
|
||||
raw="",
|
||||
@@ -86,6 +90,17 @@ class Reviewer:
|
||||
)
|
||||
|
||||
def _llm_review(self, fusion: FusionResult, intent: IntentResult, fusion_level: str) -> Optional[ReviewResult]:
|
||||
try:
|
||||
return self._llm_review_inner(fusion, intent, fusion_level)
|
||||
except Exception as e:
|
||||
import logging
|
||||
|
||||
logging.getLogger(__name__).warning("[Reviewer] LLM审核调用异常,降级放行: %s", e)
|
||||
return None
|
||||
|
||||
def _llm_review_inner(
|
||||
self, fusion: FusionResult, intent: IntentResult, fusion_level: str
|
||||
) -> Optional[ReviewResult]:
|
||||
template = get_template("review")
|
||||
system = render_system_prompt(template)
|
||||
user = render_user_prompt(
|
||||
@@ -303,10 +318,13 @@ class Reviewer:
|
||||
|
||||
@staticmethod
|
||||
def _fusion_text(fusion: FusionResult) -> str:
|
||||
_MARKDOWN_FIELDS = {"summary_markdown", "copy_display_markdown"}
|
||||
parts = [fusion.title, fusion.hook]
|
||||
parts += [p.text for p in fusion.body_points]
|
||||
parts += [s.text for s in fusion.script_segments]
|
||||
parts.append(fusion.cta)
|
||||
# 过滤掉markdown展示字段,避免格式字符被误判
|
||||
parts = [p for p in parts if not any(mk in p for mk in _MARKDOWN_FIELDS)]
|
||||
return "\n".join(p for p in parts if p)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -337,13 +337,13 @@ class DoubaoClient:
|
||||
self.last_finish_reason = finish_reason
|
||||
_elapsed = time.time() - _t0
|
||||
logger.info(
|
||||
"[doubao] chat_completion 完成 model=%s tokens_in=%d tokens_out=%d elapsed=%.1fs attempt=%d timeout=%d",
|
||||
"[doubao] chat_completion 完成 model=%s tokens_in=%d tokens_out=%d elapsed=%.1fs attempt=%d timeout=%s",
|
||||
payload.get("model"),
|
||||
data.get("usage", {}).get("prompt_tokens", 0),
|
||||
data.get("usage", {}).get("completion_tokens", 0),
|
||||
_elapsed,
|
||||
attempt + 1,
|
||||
_req_timeout,
|
||||
getattr(_req_timeout, "read", _req_timeout),
|
||||
)
|
||||
return content.strip()
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user