mirror of
https://github.com/harry0703/MoneyPrinterTurbo.git
synced 2026-02-21 16:37:21 +08:00
open the output folder when task completed
This commit is contained in:
parent
50ee56b158
commit
a7ba661053
@ -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 = """
|
||||
<style>#root > div:nth-child(1) > div > div > div > div > section > div {padding-top: 0rem;}</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"""
|
||||
<script>
|
||||
console.log("scroll_to_bottom");
|
||||
function scroll(dummy_var_to_force_repeat_execution){{
|
||||
var sections = parent.document.querySelectorAll('section.main');
|
||||
console.log(sections);
|
||||
for(let index = 0; index<sections.length; index++) {{
|
||||
sections[index].scrollTop = sections[index].scrollHeight;
|
||||
}}
|
||||
}}
|
||||
scroll(1);
|
||||
</script>
|
||||
"""
|
||||
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"完成")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user