Skip to content

Commit

Permalink
feat(webui): 新增脚本设置功能并优化关键帧提取- 在 script_settings.py 中添加了三个新的输入框,用于设置 …
Browse files Browse the repository at this point in the history
…skip_seconds、threshold 和 vision_batch_size- 更新了关键帧提取过程,使用新设置的参数替代了配置文件中的固定值

- 在 i18n/zh.json 中添加了相关翻译,确保新功能支持中文
  • Loading branch information
linyqh committed Nov 18, 2024
1 parent 07c3d54 commit 420f939
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
45 changes: 39 additions & 6 deletions webui/components/script_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,40 @@ def render_video_details(tr):

def render_script_buttons(tr, params):
"""渲染脚本操作按钮"""
# 新增三个输入框,放在同一行
input_cols = st.columns(3)

with input_cols[0]:
skip_seconds = st.number_input(
"skip_seconds",
min_value=0,
value=st.session_state.get('skip_seconds', config.frames.get('skip_seconds', 0)),
help=tr("Skip the first few seconds"),
key="skip_seconds_input"
)
st.session_state['skip_seconds'] = skip_seconds

with input_cols[1]:
threshold = st.number_input(
"threshold",
min_value=0,
value=st.session_state.get('threshold', config.frames.get('threshold', 30)),
help=tr("Difference threshold"),
key="threshold_input"
)
st.session_state['threshold'] = threshold

with input_cols[2]:
vision_batch_size = st.number_input(
"vision_batch_size",
min_value=1,
max_value=20,
value=st.session_state.get('vision_batch_size', config.frames.get('vision_batch_size', 5)),
help=tr("Vision processing batch size"),
key="vision_batch_size_input"
)
st.session_state['vision_batch_size'] = vision_batch_size

# 生成/加载按钮
script_path = st.session_state.get('video_clip_json_path', '')
if script_path == "auto":
Expand Down Expand Up @@ -287,7 +321,6 @@ def update_progress(progress: float, message: str = ""):
with st.spinner("正在生成脚本..."):
if not params.video_origin_path:
st.error("请先选择视频文件")
st.stop()
return

# ===================提取键帧===================
Expand Down Expand Up @@ -323,8 +356,8 @@ def update_progress(progress: float, message: str = ""):
# 处理视频并提取关键帧
processor.process_video_pipeline(
output_dir=video_keyframes_dir,
skip_seconds=config.frames.get("skip_seconds", 0),
threshold=config.frames.get("threshold", 30)
skip_seconds=st.session_state.get('skip_seconds'),
threshold=st.session_state.get('threshold')
)
else:
processor = video_processor.VideoProcessor(params.video_origin_path)
Expand Down Expand Up @@ -353,7 +386,7 @@ def update_progress(progress: float, message: str = ""):
except Exception as cleanup_err:
logger.error(f"清理失败的关键帧目录时出错: {cleanup_err}")

raise Exception(f"关键帧提取��败: {str(e)}")
raise Exception(f"关键帧提取失败: {str(e)}")

# 根据不同的 LLM 提供商处理
vision_llm_provider = st.session_state.get('vision_llm_providers').lower()
Expand All @@ -374,7 +407,7 @@ def update_progress(progress: float, message: str = ""):

analyzer = vision_analyzer.VisionAnalyzer(
model_name=vision_model,
api_key=vision_api_key
api_key=vision_api_key,
)

update_progress(40, "正在分析关键帧...")
Expand All @@ -388,7 +421,7 @@ def update_progress(progress: float, message: str = ""):
analyzer.analyze_images(
images=keyframe_files,
prompt=config.app.get('vision_analysis_prompt'),
batch_size=config.frames.get("vision_batch_size", 5)
batch_size=config.frames.get("vision_batch_size", st.session_state.get('vision_batch_size', 5))
)
)
loop.close()
Expand Down
13 changes: 11 additions & 2 deletions webui/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@
"Text API Key": "文案生成 API 密钥",
"Text Base URL": "文案生成接口地址",
"Text Model Name": "文案生成模型名称",
"Account ID": "账户 ID"
"Account ID": "账户 ID",
"Skip the first few seconds": "跳过开头多少秒",
"Difference threshold": "差异阈值",
"Vision processing batch size": "视觉处理批次大小",
"Test Connection": "测试连接",
"gemini model is available": "Gemini 模型可用",
"gemini model is not available": "Gemini 模型不可用",
"NarratoAPI is available": "NarratoAPI 可用",
"NarratoAPI is not available": "NarratoAPI 不可用",
"Unsupported provider": "不支持的提供商"
}
}
}

0 comments on commit 420f939

Please sign in to comment.