优化保存脚本必须刷新浏览器才能加载下拉框的bug

This commit is contained in:
linyq 2024-08-27 15:46:25 +08:00
parent 7b7e2391b3
commit d50c6e695c
2 changed files with 10 additions and 9 deletions

View File

@ -339,9 +339,6 @@ def start_subclip(task_id, params: VideoClipParams, subclip_path_videos):
max_clip_duration = params.video_clip_duration
logger.info("\n\n## 1. 读取json")
# video_script = params.video_script.strip()
# 搜索 ../storage 目录下 名称为 video_subject 的docx文件,并读出所有字符串
# video_script_path = path.join('E:\\Projects\\linyq\\MoneyPrinterLin\\txt.txt\\txt2.json')
video_script_path = path.join(params.video_clip_json)
# 判断json文件是否存在
if path.exists(video_script_path):
@ -356,7 +353,6 @@ def start_subclip(task_id, params: VideoClipParams, subclip_path_videos):
logger.debug(f"原json时间戳: \n{time_list}")
else:
print("#@#@#@", params.video_clip_json)
raise ValueError("解说文案不存在!检查文案名称是否正确。")
# video_script = llm.text_polishing(context=video_script, language=params.video_language)

View File

@ -385,9 +385,8 @@ with left_panel:
save_path = os.path.join(script_dir, f"{timestamp}.json")
# 尝试解析输入的 JSON 数据
# input_json = str(video_clip_json_details).replace("'", '"')
input_json = str(video_clip_json_details)
logger.error(input_json)
# 去掉json的头尾标识
input_json = input_json.strip('```json').strip('```')
try:
data = json.loads(input_json)
@ -411,8 +410,9 @@ with left_panel:
json.dump(data, file, ensure_ascii=False, indent=4)
# 将data的值存储到 session_state 中,类似缓存
st.session_state['video_script_list'] = data
logger.debug(f"脚本内容已成功保存到 {save_path}")
st.session_state['video_clip_json_path'] = save_path
# 刷新页面
st.rerun()
with button_columns[1]:
if st.button(tr("Crop Video"), key="auto_crop_video", use_container_width=True):
@ -731,7 +731,12 @@ with st.expander(tr("Video Check"), expanded=False):
start_button = st.button(tr("Generate Video"), use_container_width=True, type="primary")
if start_button:
config.save_config()
task_id = st.session_state['task_id']
task_id = st.session_state.get('task_id')
params.video_clip_json = st.session_state['video_clip_json_path']
if not task_id:
st.error(tr("请先裁剪视频"))
scroll_to_bottom()
st.stop()
if not params.video_clip_json:
st.error(tr("脚本文件不能为空"))
scroll_to_bottom()