feat(webui): 优化短剧解说功能

- 添加短剧名称输入框和温度调节滑块- 更新 generate_script_short_sunmmary 函数以接收新参数
- 修改 prompt 模板以包含短剧名称
- 调整组件渲染顺序,提高用户体验
This commit is contained in:
linyq 2025-05-11 00:13:56 +08:00
parent 6cd1ff8b68
commit 2ef42fda46
4 changed files with 27 additions and 16 deletions

View File

@ -68,7 +68,7 @@ subtitle_plot_analysis_v1 = """
"""
plot_writing = """
我是一个影视解说up主需要为我的粉丝讲解短剧家里家外的剧情目前正在解说1-5集的剧情希望能让粉丝通过我的解说了解剧情并且产生 继续观看的兴趣请生成一篇解说脚本包含解说文案以及穿插原声的片段下面<plot>中的内容是短剧的剧情概述
我是一个影视解说up主需要为我的粉丝讲解短剧%s的剧情目前正在解说剧情希望能让粉丝通过我的解说了解剧情并且产生 继续观看的兴趣请生成一篇解说脚本包含解说文案以及穿插原声的片段下面<plot>中的内容是短剧的剧情概述
<plot>
%s

View File

@ -203,11 +203,12 @@ class SubtitleAnalyzer:
logger.error(f"保存分析结果时发生错误: {str(e)}")
return ""
def generate_narration_script(self, plot_analysis: str, temperature: float = 0.7) -> Dict[str, Any]:
def generate_narration_script(self, short_name:str, plot_analysis: str, temperature: float = 0.7) -> Dict[str, Any]:
"""
根据剧情分析生成解说文案
Args:
short_name: 短剧名称
plot_analysis: 剧情分析内容
temperature: 生成温度控制创造性默认0.7
@ -216,8 +217,8 @@ class SubtitleAnalyzer:
"""
try:
# 构建完整提示词
prompt = plot_writing % plot_analysis
prompt = plot_writing % (short_name, plot_analysis)
# 构建请求体数据
payload = {
"model": self.model,
@ -371,6 +372,7 @@ def analyze_subtitle(
def generate_narration_script(
short_name: str = None,
plot_analysis: str = None,
api_key: Optional[str] = None,
model: Optional[str] = None,
@ -383,6 +385,7 @@ def generate_narration_script(
根据剧情分析生成解说文案的便捷函数
Args:
short_name: 短剧名称
plot_analysis: 剧情分析内容直接提供
api_key: API密钥
model: 模型名称
@ -403,7 +406,7 @@ def generate_narration_script(
)
# 生成解说文案
result = analyzer.generate_narration_script(plot_analysis, temperature)
result = analyzer.generate_narration_script(short_name, plot_analysis, temperature)
# 保存结果
if save_result and result["status"] == "success":

View File

@ -30,12 +30,12 @@ def render_script_panel(tr):
script_path = st.session_state.get('video_clip_json_path', '')
# 根据脚本类型显示不同的布局
if script_path == "short":
# 短剧混剪 模式下显示的内容
render_short_generate_options(tr)
elif script_path == "auto":
if script_path == "auto":
# 画面解说
render_video_details(tr)
elif script_path == "short":
# 短剧混剪
render_short_generate_options(tr)
elif script_path == "summary":
# 短剧解说
short_drama_summary(tr)
@ -187,6 +187,7 @@ def render_short_generate_options(tr):
渲染Short Generate模式下的特殊选项
在Short Generate模式下替换原有的输入框为自定义片段选项
"""
short_drama_summary(tr)
# 显示自定义片段数量选择器
custom_clips = st.number_input(
tr("自定义片段"),
@ -284,9 +285,13 @@ def short_drama_summary(tr):
except Exception as e:
st.error(f"{tr('Upload failed')}: {str(e)}")
# 名称输入框
video_theme = st.text_input(tr("短剧名称"))
st.session_state['video_theme'] = video_theme
# 数字输入框
temperature = st.slider("temperature", 0.0, 2.0, 0.7)
st.session_state['temperature'] = temperature
return video_theme
@ -312,14 +317,15 @@ def render_script_buttons(tr, params):
# 执行纪录片视频脚本生成(视频无字幕无配音)
generate_script_docu(params)
elif script_path == "short":
# 获取自定义片段数量参数
# 执行 短剧混剪 脚本生成
custom_clips = st.session_state.get('custom_clips')
# 直接将custom_clips作为参数传递而不是通过params对象
generate_script_short(tr, params, custom_clips)
elif script_path == "summary":
# 执行短剧解说脚本生成
# 执行 短剧解说 脚本生成
subtitle_path = st.session_state.get('subtitle_path')
generate_script_short_sunmmary(params, subtitle_path)
video_theme = st.session_state.get('video_theme')
temperature = st.session_state.get('temperature')
generate_script_short_sunmmary(params, subtitle_path, video_theme, temperature)
else:
load_script(tr, script_path)

View File

@ -18,7 +18,7 @@ from app.config import config
from app.services.SDE.short_drama_explanation import analyze_subtitle, generate_narration_script
def generate_script_short_sunmmary(params, subtitle_path):
def generate_script_short_sunmmary(params, subtitle_path, video_theme, temperature):
"""
生成 短剧解说 视频脚本
要求: 提供高质量短剧字幕
@ -71,11 +71,13 @@ def generate_script_short_sunmmary(params, subtitle_path):
# 根据剧情生成解说文案
narration_result = generate_narration_script(
short_name=video_theme,
plot_analysis=analysis_result["analysis"],
api_key=text_api_key,
model=text_model,
base_url=text_base_url,
save_result=True
save_result=True,
temperature=temperature
)
if narration_result["status"] == "success":