From b3a73089e2a1efbcb9123ee8ee104e2a0c3ea346 Mon Sep 17 00:00:00 2001 From: linyq Date: Mon, 2 Sep 2024 09:54:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E6=9D=A5=E8=87=AA=20Jrt=20?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=20-=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=BA=86=E8=A7=86=E9=A2=91=E5=AE=A1=E6=9F=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E9=87=8D=E6=96=B0=E7=94=9F=E6=88=90=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui/Main.py | 81 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/webui/Main.py b/webui/Main.py index 8eb4103..b1c8004 100644 --- a/webui/Main.py +++ b/webui/Main.py @@ -31,7 +31,7 @@ st.set_page_config( menu_items={ "Report a bug": "https://github.com/linyqh/NarratoAI/issues", 'About': f"# NarratoAI:sunglasses: 📽️ \n #### Version: v{config.project_version} \n " - f"自动化影视解说视频详情请移步:https://github.com/linyqh/NarratoAI" + f"自动化影视解说视频详情请移步:https://github.com/linyqh/NarratoAI" }, ) @@ -391,7 +391,8 @@ with left_panel: try: data = json.loads(input_json) except Exception as err: - raise ValueError(f"视频脚本格式错误,请检查脚本是否符合 JSON 格式;{err} \n\n{traceback.format_exc()}") + raise ValueError( + f"视频脚本格式错误,请检查脚本是否符合 JSON 格式;{err} \n\n{traceback.format_exc()}") # 检查是否是一个列表 if not isinstance(data, list): @@ -414,31 +415,36 @@ with left_panel: # 刷新页面 st.rerun() + + def caijian(): + with st.spinner(tr("裁剪视频中...")): + st.session_state['task_id'] = str(uuid4()) + + if st.session_state.get('video_script_list', None) is not None: + video_script_list = st.session_state.video_script_list + time_list = [i['timestamp'] for i in video_script_list] + subclip_videos = material.clip_videos( + task_id=st.session_state['task_id'], + timestamp_terms=time_list, + origin_video=params.video_origin_path + ) + if subclip_videos is None: + st.error(tr("裁剪视频失败")) + st.stop() + st.session_state['subclip_videos'] = subclip_videos + for video_script in video_script_list: + try: + video_script['path'] = subclip_videos[video_script['timestamp']] + except KeyError as e: + st.error(f"裁剪视频失败") + # logger.debug(f"当前的脚本为:{st.session_state.video_script_list}") + else: + st.error(tr("请先生成视频脚本")) + + with button_columns[1]: if st.button(tr("Crop Video"), key="auto_crop_video", use_container_width=True): - with st.spinner(tr("裁剪视频中...")): - st.session_state['task_id'] = str(uuid4()) - - if st.session_state.get('video_script_list', None) is not None: - video_script_list = st.session_state.video_script_list - time_list = [i['timestamp'] for i in video_script_list] - subclip_videos = material.clip_videos( - task_id=st.session_state['task_id'], - timestamp_terms=time_list, - origin_video=params.video_origin_path - ) - if subclip_videos is None: - st.error(tr("裁剪视频失败")) - st.stop() - st.session_state['subclip_videos'] = subclip_videos - for video_script in video_script_list: - try: - video_script['path'] = subclip_videos[video_script['timestamp']] - except KeyError as e: - st.error(f"裁剪视频失败") - # logger.debug(f"当前的脚本为:{st.session_state.video_script_list}") - else: - st.error(tr("请先生成视频脚本")) + caijian() # 新中间面板 with middle_panel: @@ -528,8 +534,8 @@ with middle_panel: else: for i, v in enumerate(voices): if ( - v.lower().startswith(st.session_state["ui_language"].lower()) - and "V2" not in v + v.lower().startswith(st.session_state["ui_language"].lower()) + and "V2" not in v ): saved_voice_name_index = i break @@ -723,17 +729,30 @@ with st.expander(tr("Video Check"), expanded=False): text2 = st.text_area(tr("Picture description"), value=initial_picture, height=20) text3 = st.text_area(tr("Narration"), value=initial_narration, height=100) - # 清空文本框按钮 + # 重新生成按钮 if st.button(tr("Rebuild"), key=f"button_{index}"): - print(123123) - # with st.spinner(tr("大模型生成中...")): + # 更新video_list中的对应项 + video_list[index]['timestamp'] = text1 + video_list[index]['picture'] = text2 + video_list[index]['narration'] = text3 + + for video in video_list: + if 'path' in video: + del video['path'] + # 更新session_state以确保更改被保存 + st.session_state['video_clip_json'] = utils.to_json(video_list) + # 替换原JSON 文件 + with open(video_json_file, 'w', encoding='utf-8') as file: + json.dump(video_list, file, ensure_ascii=False, indent=4) + caijian() + st.rerun() start_button = st.button(tr("Generate Video"), use_container_width=True, type="primary") if start_button: config.save_config() task_id = st.session_state.get('task_id') if st.session_state.get('video_script_json_path') is not None: - params.video_clip_json = st.session_state.get('video_script_json_path') + params.video_clip_json = st.session_state.get('video_clip_json') logger.debug(f"当前的脚本为:{params.video_clip_json}")