From 1bfa66f961db3a68c08e491025cf24cc6653bb2b Mon Sep 17 00:00:00 2001
From: hit-cxf <2024111082@stu.hit.edu.cn>
Date: Wed, 13 May 2026 22:11:17 +0800
Subject: [PATCH] 更改项目示意图
---
aigc-director/aigc-claw/frontend/components/pipelines/PipelinePage.tsx | 46 ++++++++++++---
aigc-director-pics/workflow.png | 0
aigc-director/aigc-claw/backend/pipelines/standard.py | 79 ++++++++++++++++++++++----
aigc-director/aigc-claw/backend/api/schemas/pipelines.py | 3
4 files changed, 105 insertions(+), 23 deletions(-)
diff --git a/aigc-director-pics/workflow.png b/aigc-director-pics/workflow.png
index 3f56561..ceb065e 100644
--- a/aigc-director-pics/workflow.png
+++ b/aigc-director-pics/workflow.png
Binary files differ
diff --git a/aigc-director/aigc-claw/backend/api/schemas/pipelines.py b/aigc-director/aigc-claw/backend/api/schemas/pipelines.py
index 5ad596c..d0a2df8 100644
--- a/aigc-director/aigc-claw/backend/api/schemas/pipelines.py
+++ b/aigc-director/aigc-claw/backend/api/schemas/pipelines.py
@@ -1,4 +1,4 @@
-from typing import Any, Dict, Optional
+from typing import Any, Dict, Literal, Optional
from pydantic import BaseModel, Field
@@ -21,6 +21,7 @@
generate_audio: bool = True
generate_videos: bool = False
enable_subtitles: bool = False
+ subtitle_render_mode: Literal["postprocess", "image_model"] = "postprocess"
subtitle_template: Optional[str] = None
subtitle_template_fields: Optional[Dict[str, str]] = None
video_duration: int = 5
diff --git a/aigc-director/aigc-claw/backend/pipelines/standard.py b/aigc-director/aigc-claw/backend/pipelines/standard.py
index bb43d40..3791cf4 100644
--- a/aigc-director/aigc-claw/backend/pipelines/standard.py
+++ b/aigc-director/aigc-claw/backend/pipelines/standard.py
@@ -2,6 +2,7 @@
import logging
import os
import re
+from typing import Optional
from models.llm_client import LLM
from prompts.loader import format_prompt, load_prompt
@@ -90,15 +91,30 @@
return image_prompts
-def build_image_prompt(visual_prompt: str, style_control: str) -> str:
+def build_image_prompt(
+ visual_prompt: str,
+ style_control: str,
+ *,
+ subtitle: Optional[str] = None,
+ render_subtitle_in_image: bool = False,
+) -> str:
style = style_control.strip()
no_text_instruction = (
"Do not include any text, captions, logos, watermarks, labels, typography, "
"or written characters in the image."
)
+ text_in_pic_instruction = (
+ "Render exactly one subtitle directly inside the image: "
+ f"\"{subtitle or ''}\". Place this subtitle in a visually appropriate area "
+ "that does not cover the main subject, using readable typography that matches "
+ "the image style, strong contrast, balanced spacing, and clean composition. "
+ "Copy the subtitle text exactly, preserving language, characters, and punctuation. "
+ "Do not add a title. Do not add logos, watermarks, labels, or any other text."
+ )
+ text_instruction = text_in_pic_instruction if render_subtitle_in_image else no_text_instruction
if not style:
- return f"{no_text_instruction}\n{visual_prompt}"
- return f"{style}\n{no_text_instruction}\n{visual_prompt}"
+ return f"{text_instruction}\n{visual_prompt}"
+ return f"{style}\n{text_instruction}\n{visual_prompt}"
async def generate_image_prompts(
@@ -106,6 +122,8 @@
style_control: str,
llm: LLM,
llm_model: str,
+ *,
+ render_subtitle_in_image: bool = False,
) -> list[str]:
template = load_prompt("pipelines", "standard_image_prompt_generation", "en")
prompt = format_prompt(
@@ -115,7 +133,15 @@
)
response = await run_blocking(llm.query, prompt, model=llm_model)
visual_prompts = parse_image_prompts_response(response, len(narrations))
- return [build_image_prompt(visual_prompt, style_control) for visual_prompt in visual_prompts]
+ return [
+ build_image_prompt(
+ visual_prompt,
+ style_control,
+ subtitle=narrations[idx],
+ render_subtitle_in_image=render_subtitle_in_image,
+ )
+ for idx, visual_prompt in enumerate(visual_prompts)
+ ]
async def generate_narrations_from_inspiration(
@@ -182,6 +208,14 @@
raise ValueError("standard pipeline requires image_model")
image_resolution = params.get("image_resolution") or "1080P"
enable_subtitles = bool(params.get("enable_subtitles", False))
+ subtitle_render_mode = params.get("subtitle_render_mode") or "postprocess"
+ if subtitle_render_mode not in {"postprocess", "image_model"}:
+ subtitle_render_mode = "postprocess"
+ render_subtitle_in_image = (
+ enable_subtitles
+ and subtitle_render_mode == "image_model"
+ and not params.get("subtitle_template")
+ )
subtitle_template = params.get("subtitle_template")
subtitle_template_fields = params.get("subtitle_template_fields") or {}
template_media = template_media_spec(subtitle_template, video_ratio) if subtitle_template else None
@@ -198,14 +232,28 @@
if llm is None:
llm = LLM()
try:
- image_prompts = await generate_image_prompts(narrations, style_control, llm, llm_model)
+ image_prompts = await generate_image_prompts(
+ narrations,
+ style_control,
+ llm,
+ llm_model,
+ render_subtitle_in_image=render_subtitle_in_image,
+ )
except Exception as exc:
logger.warning(
"Failed to generate structured image prompts, fallback to narration prompts: task_id=%s error=%s",
task_id,
exc,
)
- image_prompts = [build_image_prompt(narration, style_control) for narration in narrations]
+ image_prompts = [
+ build_image_prompt(
+ narration,
+ style_control,
+ subtitle=narration,
+ render_subtitle_in_image=render_subtitle_in_image,
+ )
+ for narration in narrations
+ ]
storyboard = {
"title": title,
@@ -214,6 +262,7 @@
"segment_count": len(narrations),
"video_mode": "dynamic_video" if dynamic_video else "image_concat",
"style_control": style_control,
+ "subtitle_render_mode": subtitle_render_mode,
"subtitle_template": subtitle_template,
"subtitle_template_fields": subtitle_template_fields,
"template_media": template_media,
@@ -283,8 +332,8 @@
duration = media_duration_seconds(audio_path) or 3.0
clip_image_path = image_path
if enable_subtitles:
- captioned_image_path = os.path.join(output_dir, f"captioned_image_{idx:02d}.jpg")
if subtitle_template:
+ captioned_image_path = os.path.join(output_dir, f"captioned_image_{idx:02d}.jpg")
clip_image_path = await run_blocking(
render_template_text_image,
image_path,
@@ -296,7 +345,8 @@
template_values=subtitle_template_fields,
index=idx,
)
- else:
+ elif subtitle_render_mode == "postprocess":
+ captioned_image_path = os.path.join(output_dir, f"captioned_image_{idx:02d}.jpg")
clip_image_path = await run_blocking(
render_static_text_image,
image_path,
@@ -305,10 +355,14 @@
title=title or None,
video_ratio=video_ratio,
)
- captioned_artifact = artifact(clip_image_path, "image", f"captioned_image_{idx:02d}")
- artifacts.append(captioned_artifact)
- append_artifact(task_id, captioned_artifact)
- storyboard["frames"][idx - 1]["captioned_image_path"] = clip_image_path
+ else:
+ storyboard["frames"][idx - 1]["captioned_image_path"] = clip_image_path
+ storyboard["frames"][idx - 1]["subtitle_rendered_in_image"] = True
+ if subtitle_template or subtitle_render_mode == "postprocess":
+ captioned_artifact = artifact(clip_image_path, "image", f"captioned_image_{idx:02d}")
+ artifacts.append(captioned_artifact)
+ append_artifact(task_id, captioned_artifact)
+ storyboard["frames"][idx - 1]["captioned_image_path"] = clip_image_path
video_path = os.path.join(output_dir, f"video_{idx:02d}.mp4")
if dynamic_video:
video_only_segment_path = os.path.join(output_dir, f"video_{idx:02d}_motion.mp4")
@@ -369,6 +423,7 @@
"videos": videos,
"video_mode": "dynamic_video" if dynamic_video else "image_concat",
"video_model": video_model if dynamic_video else None,
+ "subtitle_render_mode": subtitle_render_mode,
"subtitle_template": subtitle_template,
"subtitle_template_fields": subtitle_template_fields,
"template_media": template_media,
diff --git a/aigc-director/aigc-claw/frontend/components/pipelines/PipelinePage.tsx b/aigc-director/aigc-claw/frontend/components/pipelines/PipelinePage.tsx
index 86b12b2..20f53ab 100644
--- a/aigc-director/aigc-claw/frontend/components/pipelines/PipelinePage.tsx
+++ b/aigc-director/aigc-claw/frontend/components/pipelines/PipelinePage.tsx
@@ -649,6 +649,7 @@
const [titleValue, setTitleValue] = useState('');
const [standardSegmentCount, setStandardSegmentCount] = useState(6);
const [enableSubtitles, setEnableSubtitles] = useState(false);
+ const [subtitleRenderMode, setSubtitleRenderMode] = useState<'postprocess' | 'image_model'>('postprocess');
const [promptText, setPromptText] = useState('');
const [imagePath, setImagePath] = useState('');
const [videoPath, setVideoPath] = useState('');
@@ -832,6 +833,7 @@
image_model: imageModel,
video_ratio: ratio,
enable_subtitles: templateMode ? true : enableSubtitles,
+ subtitle_render_mode: !templateMode && enableSubtitles ? subtitleRenderMode : undefined,
subtitle_template: templateMode ? selectedTemplate?.id : undefined,
subtitle_template_fields: templateMode ? templateFieldValues : undefined,
tts_voice: ttsVoice,
@@ -1086,16 +1088,40 @@
生成配置
</button>
{pipeline === 'standard' && (
- <label className="flex items-center gap-2 h-9 rounded-lg border border-gray-200 bg-white px-3 text-xs font-medium text-gray-600">
- <input
- type="checkbox"
- checked={templateMode || enableSubtitles}
- onChange={e => setEnableSubtitles(e.target.checked)}
- disabled={templateMode}
- className="w-4 h-4 rounded border-gray-300"
- />
- 添加标题和字幕
- </label>
+ <>
+ <label className="flex items-center gap-2 h-9 rounded-lg border border-gray-200 bg-white px-3 text-xs font-medium text-gray-600">
+ <input
+ type="checkbox"
+ checked={templateMode || enableSubtitles}
+ onChange={e => setEnableSubtitles(e.target.checked)}
+ disabled={templateMode}
+ className="w-4 h-4 rounded border-gray-300"
+ />
+ 添加标题和字幕
+ </label>
+ {!templateMode && enableSubtitles && (
+ <div className="grid h-9 grid-cols-2 rounded-lg bg-gray-100 p-1 text-xs">
+ {[
+ { id: 'postprocess', label: 'PIL 后期叠字' },
+ { id: 'image_model', label: '模型直接生成字幕' },
+ ].map(item => (
+ <button
+ key={item.id}
+ type="button"
+ onClick={() => setSubtitleRenderMode(item.id as 'postprocess' | 'image_model')}
+ className={clsx(
+ 'rounded-md px-3 font-medium transition-colors',
+ subtitleRenderMode === item.id
+ ? 'bg-white text-blue-600 shadow-sm'
+ : 'text-gray-500 hover:text-gray-700'
+ )}
+ >
+ {item.label}
+ </button>
+ ))}
+ </div>
+ )}
+ </>
)}
{error && <span className="text-xs text-red-500 truncate">{error}</span>}
<button
--
Gitblit v1.8.0