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

View File

@ -203,11 +203,12 @@ class SubtitleAnalyzer:
logger.error(f"保存分析结果时发生错误: {str(e)}") logger.error(f"保存分析结果时发生错误: {str(e)}")
return "" 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: Args:
short_name: 短剧名称
plot_analysis: 剧情分析内容 plot_analysis: 剧情分析内容
temperature: 生成温度控制创造性默认0.7 temperature: 生成温度控制创造性默认0.7
@ -216,7 +217,7 @@ class SubtitleAnalyzer:
""" """
try: try:
# 构建完整提示词 # 构建完整提示词
prompt = plot_writing % plot_analysis prompt = plot_writing % (short_name, plot_analysis)
# 构建请求体数据 # 构建请求体数据
payload = { payload = {
@ -371,6 +372,7 @@ def analyze_subtitle(
def generate_narration_script( def generate_narration_script(
short_name: str = None,
plot_analysis: str = None, plot_analysis: str = None,
api_key: Optional[str] = None, api_key: Optional[str] = None,
model: Optional[str] = None, model: Optional[str] = None,
@ -383,6 +385,7 @@ def generate_narration_script(
根据剧情分析生成解说文案的便捷函数 根据剧情分析生成解说文案的便捷函数
Args: Args:
short_name: 短剧名称
plot_analysis: 剧情分析内容直接提供 plot_analysis: 剧情分析内容直接提供
api_key: API密钥 api_key: API密钥
model: 模型名称 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": 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', '') script_path = st.session_state.get('video_clip_json_path', '')
# 根据脚本类型显示不同的布局 # 根据脚本类型显示不同的布局
if script_path == "short": if script_path == "auto":
# 短剧混剪 模式下显示的内容
render_short_generate_options(tr)
elif script_path == "auto":
# 画面解说 # 画面解说
render_video_details(tr) render_video_details(tr)
elif script_path == "short":
# 短剧混剪
render_short_generate_options(tr)
elif script_path == "summary": elif script_path == "summary":
# 短剧解说 # 短剧解说
short_drama_summary(tr) short_drama_summary(tr)
@ -187,6 +187,7 @@ def render_short_generate_options(tr):
渲染Short Generate模式下的特殊选项 渲染Short Generate模式下的特殊选项
在Short Generate模式下替换原有的输入框为自定义片段选项 在Short Generate模式下替换原有的输入框为自定义片段选项
""" """
short_drama_summary(tr)
# 显示自定义片段数量选择器 # 显示自定义片段数量选择器
custom_clips = st.number_input( custom_clips = st.number_input(
tr("自定义片段"), tr("自定义片段"),
@ -285,8 +286,12 @@ def short_drama_summary(tr):
except Exception as e: except Exception as e:
st.error(f"{tr('Upload failed')}: {str(e)}") st.error(f"{tr('Upload failed')}: {str(e)}")
# 名称输入框
video_theme = st.text_input(tr("短剧名称")) video_theme = st.text_input(tr("短剧名称"))
st.session_state['video_theme'] = video_theme 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 return video_theme
@ -312,14 +317,15 @@ def render_script_buttons(tr, params):
# 执行纪录片视频脚本生成(视频无字幕无配音) # 执行纪录片视频脚本生成(视频无字幕无配音)
generate_script_docu(params) generate_script_docu(params)
elif script_path == "short": elif script_path == "short":
# 获取自定义片段数量参数 # 执行 短剧混剪 脚本生成
custom_clips = st.session_state.get('custom_clips') custom_clips = st.session_state.get('custom_clips')
# 直接将custom_clips作为参数传递而不是通过params对象
generate_script_short(tr, params, custom_clips) generate_script_short(tr, params, custom_clips)
elif script_path == "summary": elif script_path == "summary":
# 执行短剧解说脚本生成 # 执行 短剧解说 脚本生成
subtitle_path = st.session_state.get('subtitle_path') 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: else:
load_script(tr, script_path) 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 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( narration_result = generate_narration_script(
short_name=video_theme,
plot_analysis=analysis_result["analysis"], plot_analysis=analysis_result["analysis"],
api_key=text_api_key, api_key=text_api_key,
model=text_model, model=text_model,
base_url=text_base_url, base_url=text_base_url,
save_result=True save_result=True,
temperature=temperature
) )
if narration_result["status"] == "success": if narration_result["status"] == "success":