feat(webui): 添加系统设置功能

- 新增系统设置面板,包含清理缓存、关键帧、裁剪视频和任务目录的功能- 实现清理指定目录的通用函数 clear_directory
- 更新中文翻译文件,添加相关提示信息
This commit is contained in:
linyqh 2024-12-05 22:36:17 +08:00
parent 97a51ae904
commit 4e590380f5
3 changed files with 60 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import os
import sys
from uuid import uuid4
from app.config import config
from webui.components import basic_settings, video_settings, audio_settings, subtitle_settings, script_settings, review_settings, merge_settings
from webui.components import basic_settings, video_settings, audio_settings, subtitle_settings, script_settings, review_settings, merge_settings, system_settings
from webui.utils import cache, file_utils
from app.utils import utils
from app.models.schema import VideoClipParams, VideoAspect
@ -190,6 +190,8 @@ def main():
audio_settings.render_audio_panel(tr)
with panel[2]:
subtitle_settings.render_subtitle_panel(tr)
# 渲染系统设置面板
system_settings.render_system_panel(tr)
# 渲染视频审查面板
review_settings.render_review_panel(tr)

View File

@ -0,0 +1,45 @@
import streamlit as st
import os
import shutil
from loguru import logger
from app.utils.utils import storage_dir
def clear_directory(dir_path, tr):
"""清理指定目录"""
if os.path.exists(dir_path):
try:
for item in os.listdir(dir_path):
item_path = os.path.join(dir_path, item)
try:
if os.path.isfile(item_path):
os.unlink(item_path)
elif os.path.isdir(item_path):
shutil.rmtree(item_path)
except Exception as e:
logger.error(f"Failed to delete {item_path}: {e}")
st.success(tr("Directory cleared"))
logger.info(f"Cleared directory: {dir_path}")
except Exception as e:
st.error(f"{tr('Failed to clear directory')}: {str(e)}")
logger.error(f"Failed to clear directory {dir_path}: {e}")
else:
st.warning(tr("Directory does not exist"))
def render_system_panel(tr):
"""渲染系统设置面板"""
with st.expander(tr("System settings"), expanded=False):
col1, col2, col3 = st.columns(3)
with col1:
if st.button(tr("Clear frames"), use_container_width=True):
clear_directory(os.path.join(storage_dir(), "temp/keyframes"), tr)
with col2:
if st.button(tr("Clear clip videos"), use_container_width=True):
clear_directory(os.path.join(storage_dir(), "temp/clip_video"), tr)
with col3:
if st.button(tr("Clear tasks"), use_container_width=True):
clear_directory(os.path.join(storage_dir(), "tasks"), tr)

View File

@ -166,6 +166,17 @@
"Subtitle Path": "字幕路径",
"Enable Proxy": "启用代理",
"QwenVL model is available": "QwenVL 模型可用",
"QwenVL model is not available": "QwenVL 模型不可用"
"QwenVL model is not available": "QwenVL 模型不可用",
"System settings": "系统设置",
"Clear Cache": "清理缓存",
"Cache cleared": "缓存清理完成",
"storage directory does not exist": "storage目录不存在",
"Failed to clear cache": "清理缓存失败",
"Clear frames": "清理关键帧",
"Clear clip videos": "清理裁剪视频",
"Clear tasks": "清理任务",
"Directory cleared": "目录清理完成",
"Directory does not exist": "目录不存在",
"Failed to clear directory": "清理目录失败"
}
}