support local videos

This commit is contained in:
harry
2024-04-27 08:33:44 +08:00
parent c161ab3124
commit 5d06530a39
10 changed files with 201 additions and 66 deletions

View File

@@ -30,10 +30,11 @@ st.set_page_config(page_title="MoneyPrinterTurbo",
"video.\n\nhttps://github.com/harry0703/MoneyPrinterTurbo"
})
from app.models.schema import VideoParams, VideoAspect, VideoConcatMode
from app.models.schema import VideoParams, VideoAspect, VideoConcatMode, MaterialInfo
from app.services import task as tm, llm, voice
from app.utils import utils
from app.config import config
from app.models.const import FILE_TYPE_VIDEOS, FILE_TYPE_IMAGES
hide_streamlit_style = """
<style>#root > div:nth-child(1) > div > div > div > div > section > div {padding-top: 0rem;}</style>
@@ -150,6 +151,8 @@ def tr(key):
st.write(tr("Get Help"))
llm_provider = config.app.get("llm_provider", "").lower()
if not config.app.get("hide_config", False):
with st.expander(tr("Basic Settings"), expanded=False):
config_panels = st.columns(3)
@@ -319,6 +322,7 @@ middle_panel = panel[1]
right_panel = panel[2]
params = VideoParams(video_subject="")
uploaded_files = []
with left_panel:
with st.container(border=True):
@@ -372,6 +376,24 @@ with middle_panel:
(tr("Sequential"), "sequential"),
(tr("Random"), "random"),
]
video_sources = [
(tr("Pexels"), "pexels"),
(tr("Local file"), "local"),
(tr("TikTok"), "douyin"),
(tr("Bilibili"), "bilibili"),
(tr("Xiaohongshu"), "xiaohongshu"),
]
selected_index = st.selectbox(tr("Video Source"),
options=range(len(video_sources)), # 使用索引作为内部选项值
format_func=lambda x: video_sources[x][0] # 显示给用户的是标签
)
params.video_source = video_sources[selected_index][1]
if params.video_source == 'local':
_supported_types = FILE_TYPE_VIDEOS + FILE_TYPE_IMAGES
uploaded_files = st.file_uploader("Upload Local Files",
type=["mp4", "mov", "avi", "flv", "mkv", "jpg", "jpeg", "png"],
accept_multiple_files=True)
selected_index = st.selectbox(tr("Video Concat Mode"),
index=1,
options=range(len(video_concat_modes)), # 使用索引作为内部选项值
@@ -512,6 +534,19 @@ if start_button:
scroll_to_bottom()
st.stop()
if uploaded_files:
local_videos_dir = utils.storage_dir("local_videos", create=True)
for file in uploaded_files:
file_path = os.path.join(local_videos_dir, f"{file.file_id}_{file.name}")
with open(file_path, "wb") as f:
f.write(file.getbuffer())
m = MaterialInfo()
m.provider = "local"
m.url = file_path
if not params.video_materials:
params.video_materials = []
params.video_materials.append(m)
log_container = st.empty()
log_records = []

View File

@@ -61,6 +61,11 @@
"Model Name": "Model Name",
"Please Enter the LLM API Key": "Please Enter the **LLM API Key**",
"Please Enter the Pexels API Key": "Please Enter the **Pexels API Key**",
"Get Help": "If you need help, or have any questions, you can join discord for help: https://harryai.cc"
"Get Help": "If you need help, or have any questions, you can join discord for help: https://harryai.cc",
"Video Source": "Video Source",
"TikTok": "TikTok (TikTok support is coming soon)",
"Bilibili": "Bilibili (Bilibili support is coming soon)",
"Xiaohongshu": "Xiaohongshu (Xiaohongshu support is coming soon)",
"Local file": "Local file"
}
}

View File

@@ -62,6 +62,11 @@
"Model Name": "Model Name",
"Please Enter the LLM API Key": "Please Enter the **LLM API Key**",
"Please Enter the Pexels API Key": "Please Enter the **Pexels API Key**",
"Get Help": "If you need help, or have any questions, you can join discord for help: https://harryai.cc"
"Get Help": "If you need help, or have any questions, you can join discord for help: https://harryai.cc",
"Video Source": "Video Source",
"TikTok": "TikTok (TikTok support is coming soon)",
"Bilibili": "Bilibili (Bilibili support is coming soon)",
"Xiaohongshu": "Xiaohongshu (Xiaohongshu support is coming soon)",
"Local file": "Local file"
}
}

View File

@@ -62,6 +62,11 @@
"Model Name": "Tên Mô Hình",
"Please Enter the LLM API Key": "Vui lòng Nhập **Khóa API LLM**",
"Please Enter the Pexels API Key": "Vui lòng Nhập **Khóa API Pexels**",
"Get Help": "Nếu bạn cần giúp đỡ hoặc có bất kỳ câu hỏi nào, bạn có thể tham gia discord để được giúp đỡ: https://harryai.cc"
"Get Help": "Nếu bạn cần giúp đỡ hoặc có bất kỳ câu hỏi nào, bạn có thể tham gia discord để được giúp đỡ: https://harryai.cc",
"Video Source": "Video Source",
"TikTok": "TikTok (TikTok support is coming soon)",
"Bilibili": "Bilibili (Bilibili support is coming soon)",
"Xiaohongshu": "Xiaohongshu (Xiaohongshu support is coming soon)",
"Local file": "Local file"
}
}

View File

@@ -62,6 +62,11 @@
"Model Name": "模型名称 (:blue[需要到大模型提供商的后台确认被授权的模型名称])",
"Please Enter the LLM API Key": "请先填写大模型 **API Key**",
"Please Enter the Pexels API Key": "请先填写 **Pexels API Key**",
"Get Help": "有任何问题或建议,可以加入 **微信群** 求助或讨论https://harryai.cc"
"Get Help": "有任何问题或建议,可以加入 **微信群** 求助或讨论https://harryai.cc",
"Video Source": "视频来源",
"TikTok": "抖音 (TikTok 支持中,敬请期待)",
"Bilibili": "哔哩哔哩 (Bilibili 支持中,敬请期待)",
"Xiaohongshu": "小红书 (Xiaohongshu 支持中,敬请期待)",
"Local file": "本地文件"
}
}