From a7ba6610530ece68427e7457aa0bf60e09274288 Mon Sep 17 00:00:00 2001 From: harry Date: Fri, 29 Mar 2024 10:16:56 +0800 Subject: [PATCH] open the output folder when task completed --- webui/Main.py | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/webui/Main.py b/webui/Main.py index ecbec8f..29be71f 100644 --- a/webui/Main.py +++ b/webui/Main.py @@ -5,26 +5,23 @@ st.set_page_config(page_title="MoneyPrinterTurbo", page_icon="🤖", layout="wid import sys import os from uuid import uuid4 - +import platform +import streamlit.components.v1 as components from loguru import logger from app.models.schema import VideoParams, VideoAspect, VoiceNames, VideoConcatMode from app.services import task as tm, llm +from app.utils import utils hide_streamlit_style = """ """ st.markdown(hide_streamlit_style, unsafe_allow_html=True) st.title("MoneyPrinterTurbo") -st.write( - "⚠️ 先在 **config.toml** 中设置 `pexels_api_keys` 和 `llm_provider` 参数,根据不同的 llm_provider,配置对应的 **API KEY**" -) root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) font_dir = os.path.join(root_dir, "resource", "fonts") song_dir = os.path.join(root_dir, "resource", "songs") -# st.session_state - if 'video_subject' not in st.session_state: st.session_state['video_subject'] = '' if 'video_script' not in st.session_state: @@ -51,6 +48,36 @@ def get_all_songs(): return songs +def open_task_folder(task_id): + try: + sys = platform.system() + path = os.path.join(root_dir, "storage", "tasks", task_id) + if os.path.exists(path): + if sys == 'Windows': + os.system(f"start {path}") + if sys == 'Darwin': + os.system(f"open {path}") + except Exception as e: + logger.error(e) + + +def scroll_to_bottom(): + js = f""" + + """ + st.components.v1.html(js, height=0, width=0) + + def init_log(): logger.remove() _lvl = "DEBUG" @@ -87,7 +114,6 @@ left_panel = panel[0] middle_panel = panel[1] right_panel = panel[2] -# define cfg as VideoParams class cfg = VideoParams() with left_panel: @@ -123,7 +149,7 @@ with left_panel: cfg.video_script = st.text_area( "视频文案(:blue[①可不填,使用AI生成 ②合理使用标点断句,有助于生成字幕])", value=st.session_state['video_script'], - height=230 + height=180 ) if st.button("点击使用AI根据**文案**生成【视频关键词】", key="auto_generate_terms"): if not cfg.video_script: @@ -242,12 +268,10 @@ if start_button: task_id = str(uuid4()) if not cfg.video_subject and not cfg.video_script: st.error("视频主题 或 视频文案,不能同时为空") + scroll_to_bottom() st.stop() - st.write(cfg) - log_container = st.empty() - log_records = [] @@ -259,6 +283,11 @@ if start_button: logger.add(log_received) + st.toast("正在生成视频,请稍候...") logger.info("开始生成视频") + logger.info(utils.to_json(cfg)) + scroll_to_bottom() tm.start(task_id=task_id, params=cfg) + open_task_folder(task_id) + logger.info(f"完成")