Merge pull request #301 from harry0703/dev

optimize UI and code
This commit is contained in:
Harry
2024-04-22 17:59:40 +08:00
committed by GitHub
11 changed files with 187 additions and 80 deletions

View File

@@ -1,5 +1,5 @@
# Use an official Python runtime as a parent image # Use an official Python runtime as a parent image
FROM python:3.10-bullseye FROM python:3.10-slim
# Set the working directory in the container # Set the working directory in the container
WORKDIR /MoneyPrinterTurbo WORKDIR /MoneyPrinterTurbo

View File

@@ -213,7 +213,7 @@ Generate a script for a video, depending on the subject of the video.
final_script = "" final_script = ""
logger.info(f"subject: {video_subject}") logger.info(f"subject: {video_subject}")
logger.debug(f"prompt: \n{prompt}") # logger.debug(f"prompt: \n{prompt}")
response = _generate_response(prompt=prompt) response = _generate_response(prompt=prompt)
# Return the generated script # Return the generated script
@@ -241,6 +241,10 @@ Generate a script for a video, depending on the subject of the video.
else: else:
logging.error("gpt returned an empty response") logging.error("gpt returned an empty response")
# g4f may return an error message
if final_script and "当日额度已消耗完" in final_script:
raise ValueError(final_script)
logger.success(f"completed: \n{final_script}") logger.success(f"completed: \n{final_script}")
return final_script return final_script
@@ -273,7 +277,7 @@ Please note that you must use English for generating video search terms; Chinese
""".strip() """.strip()
logger.info(f"subject: {video_subject}") logger.info(f"subject: {video_subject}")
logger.debug(f"prompt: \n{prompt}") # logger.debug(f"prompt: \n{prompt}")
response = _generate_response(prompt) response = _generate_response(prompt)
search_terms = [] search_terms = []

View File

@@ -78,7 +78,11 @@ def start(task_id, params: VideoParams):
if sub_maker is None: if sub_maker is None:
sm.state.update_task(task_id, state=const.TASK_STATE_FAILED) sm.state.update_task(task_id, state=const.TASK_STATE_FAILED)
logger.error( logger.error(
"failed to generate audio, maybe the network is not available. if you are in China, please use a VPN.") """failed to generate audio:
1. check if the language of the voice matches the language of the video script.
2. check if the network is available. If you are in China, it is recommended to use a VPN and enable the global traffic mode.
""".strip()
)
return return
audio_duration = voice.get_audio_duration(sub_maker) audio_duration = voice.get_audio_duration(sub_maker)
@@ -174,7 +178,6 @@ def start(task_id, params: VideoParams):
sm.state.update_task(task_id, state=const.TASK_STATE_COMPLETE, progress=100, **kwargs) sm.state.update_task(task_id, state=const.TASK_STATE_COMPLETE, progress=100, **kwargs)
return kwargs return kwargs
# def start_test(task_id, params: VideoParams): # def start_test(task_id, params: VideoParams):
# print(f"start task {task_id} \n") # print(f"start task {task_id} \n")
# time.sleep(5) # time.sleep(5)

View File

@@ -1023,7 +1023,6 @@ def parse_voice_name(name: str):
def is_azure_v2_voice(voice_name: str): def is_azure_v2_voice(voice_name: str):
voice_name = parse_voice_name(voice_name) voice_name = parse_voice_name(voice_name)
print(voice_name)
if voice_name.endswith("-V2"): if voice_name.endswith("-V2"):
return voice_name.replace("-V2", "").strip() return voice_name.replace("-V2", "").strip()
return "" return ""

View File

@@ -34,7 +34,7 @@ listen_port = 8502
# No need to set it unless you want to use your own proxy # No need to set it unless you want to use your own proxy
openai_base_url = "" openai_base_url = ""
# Check your available models at https://platform.openai.com/account/limits # Check your available models at https://platform.openai.com/account/limits
openai_model_name = "gpt-4-turbo-preview" openai_model_name = "gpt-4-turbo"
########## Moonshot API Key ########## Moonshot API Key
# Visit https://platform.moonshot.cn/console/api-keys to get your API key. # Visit https://platform.moonshot.cn/console/api-keys to get your API key.
@@ -51,7 +51,7 @@ listen_port = 8502
########## G4F ########## G4F
# Visit https://github.com/xtekky/gpt4free to get more details # Visit https://github.com/xtekky/gpt4free to get more details
# Supported model list: https://github.com/xtekky/gpt4free/blob/main/g4f/models.py # Supported model list: https://github.com/xtekky/gpt4free/blob/main/g4f/models.py
g4f_model_name = "gpt-3.5-turbo-16k-0613" g4f_model_name = "gpt-3.5-turbo"
########## Azure API Key ########## Azure API Key
# Visit https://learn.microsoft.com/zh-cn/azure/ai-services/openai/ to get more details # Visit https://learn.microsoft.com/zh-cn/azure/ai-services/openai/ to get more details

View File

@@ -10,16 +10,16 @@ streamlit~=1.33.0
loguru~=0.7.2 loguru~=0.7.2
aiohttp~=3.9.3 aiohttp~=3.9.3
urllib3~=2.2.1 urllib3~=2.2.1
pillow~=9.5.0 pillow~=10.3.0
pydantic~=2.6.3 pydantic~=2.6.3
g4f~=0.2.5.4 g4f~=0.3.0.4
dashscope~=1.15.0 dashscope~=1.15.0
google.generativeai~=0.4.1 google.generativeai~=0.4.1
python-multipart~=0.0.9 python-multipart~=0.0.9
redis==5.0.3 redis==5.0.3
# if you use pillow~=10.3.0, you will get "PIL.Image' has no attribute 'ANTIALIAS'" error when resize video # if you use pillow~=10.3.0, you will get "PIL.Image' has no attribute 'ANTIALIAS'" error when resize video
# please install opencv-python to fix "PIL.Image' has no attribute 'ANTIALIAS'" error # please install opencv-python to fix "PIL.Image' has no attribute 'ANTIALIAS'" error
opencv-python opencv-python~=4.9.0.80
# for azure speech # for azure speech
# https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/9-more-realistic-ai-voices-for-conversations-now-generally/ba-p/4099471 # https://techcommunity.microsoft.com/t5/ai-azure-ai-services-blog/9-more-realistic-ai-voices-for-conversations-now-generally/ba-p/4099471
azure-cognitiveservices-speech~=1.37.0 azure-cognitiveservices-speech~=1.37.0

View File

@@ -41,11 +41,14 @@ hide_streamlit_style = """
st.markdown(hide_streamlit_style, unsafe_allow_html=True) st.markdown(hide_streamlit_style, unsafe_allow_html=True)
st.title(f"MoneyPrinterTurbo v{config.project_version}") st.title(f"MoneyPrinterTurbo v{config.project_version}")
support_locales = ["zh-CN", "zh-HK", "zh-TW", "de-DE", "en-US", "fr-FR", "vi-VN", "th-TH"]
font_dir = os.path.join(root_dir, "resource", "fonts") font_dir = os.path.join(root_dir, "resource", "fonts")
song_dir = os.path.join(root_dir, "resource", "songs") song_dir = os.path.join(root_dir, "resource", "songs")
i18n_dir = os.path.join(root_dir, "webui", "i18n") i18n_dir = os.path.join(root_dir, "webui", "i18n")
config_file = os.path.join(root_dir, "webui", ".streamlit", "webui.toml") config_file = os.path.join(root_dir, "webui", ".streamlit", "webui.toml")
system_locale = utils.get_system_locale() system_locale = utils.get_system_locale()
# print(f"******** system locale: {system_locale} ********")
if 'video_subject' not in st.session_state: if 'video_subject' not in st.session_state:
st.session_state['video_subject'] = '' st.session_state['video_subject'] = ''
@@ -185,6 +188,7 @@ with st.expander(tr("Basic Settings"), expanded=False):
break break
llm_provider = st.selectbox(tr("LLM Provider"), options=llm_providers, index=saved_llm_provider_index) llm_provider = st.selectbox(tr("LLM Provider"), options=llm_providers, index=saved_llm_provider_index)
llm_helper = st.container()
llm_provider = llm_provider.lower() llm_provider = llm_provider.lower()
config.app["llm_provider"] = llm_provider config.app["llm_provider"] = llm_provider
@@ -192,9 +196,97 @@ with st.expander(tr("Basic Settings"), expanded=False):
llm_base_url = config.app.get(f"{llm_provider}_base_url", "") llm_base_url = config.app.get(f"{llm_provider}_base_url", "")
llm_model_name = config.app.get(f"{llm_provider}_model_name", "") llm_model_name = config.app.get(f"{llm_provider}_model_name", "")
llm_account_id = config.app.get(f"{llm_provider}_account_id", "") llm_account_id = config.app.get(f"{llm_provider}_account_id", "")
tips = ""
if llm_provider == 'ollama':
if not llm_model_name:
llm_model_name = "qwen:7b"
if not llm_base_url:
llm_base_url = "http://localhost:11434/v1"
with llm_helper:
tips = """
##### Ollama配置说明
- **API Key**: 随便填写,比如 123
- **Base Url**: 一般为 http://localhost:11434/v1
- **Model Name**: 使用 `ollama list` 查看,比如 `qwen:7b`
"""
if llm_provider == 'openai':
if not llm_model_name:
llm_model_name = "gpt-3.5-turbo"
with llm_helper:
tips = """
##### OpenAI 配置说明
> 需要VPN开启全局流量模式
- **API Key**: [点击到官网申请](https://platform.openai.com/api-keys)
- **Base Url**: 可以留空
- **Model Name**: 填写**有权限**的模型,[点击查看模型列表](https://platform.openai.com/settings/organization/limits)
"""
if llm_provider == 'moonshot':
if not llm_model_name:
llm_model_name = "moonshot-v1-8k"
with llm_helper:
tips = """
##### Moonshot 配置说明
- **API Key**: [点击到官网申请](https://platform.moonshot.cn/console/api-keys)
- **Base Url**: 固定为 https://api.moonshot.cn/v1
- **Model Name**: 比如 moonshot-v1-8k[点击查看模型列表](https://platform.moonshot.cn/docs/intro#%E6%A8%A1%E5%9E%8B%E5%88%97%E8%A1%A8)
"""
if llm_provider == 'qwen':
if not llm_model_name:
llm_model_name = "qwen-max"
with llm_helper:
tips = """
##### 通义千问Qwen 配置说明
- **API Key**: [点击到官网申请](https://dashscope.console.aliyun.com/apiKey)
- **Base Url**: 留空
- **Model Name**: 比如 qwen-max[点击查看模型列表](https://help.aliyun.com/zh/dashscope/developer-reference/model-introduction#3ef6d0bcf91wy)
"""
if llm_provider == 'g4f':
if not llm_model_name:
llm_model_name = "gpt-3.5-turbo"
with llm_helper:
tips = """
##### gpt4free 配置说明
> [GitHub开源项目](https://github.com/xtekky/gpt4free)可以免费使用GPT模型但是**稳定性较差**
- **API Key**: 随便填写,比如 123
- **Base Url**: 留空
- **Model Name**: 比如 gpt-3.5-turbo[点击查看模型列表](https://github.com/xtekky/gpt4free/blob/main/g4f/models.py#L308)
"""
if llm_provider == 'azure':
with llm_helper:
tips = """
##### Azure 配置说明
> [点击查看如何部署模型](https://learn.microsoft.com/zh-cn/azure/ai-services/openai/how-to/create-resource)
- **API Key**: [点击到Azure后台创建](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI)
- **Base Url**: 留空
- **Model Name**: 填写你实际的部署名
"""
if llm_provider == 'gemini':
if not llm_model_name:
llm_model_name = "gemini-1.0-pro"
with llm_helper:
tips = """
##### Gemini 配置说明
> 需要VPN开启全局流量模式
- **API Key**: [点击到官网申请](https://ai.google.dev/)
- **Base Url**: 留空
- **Model Name**: 比如 gemini-1.0-pro
"""
if tips and config.ui['language'] == 'zh':
st.info(tips)
st_llm_api_key = st.text_input(tr("API Key"), value=llm_api_key, type="password") st_llm_api_key = st.text_input(tr("API Key"), value=llm_api_key, type="password")
st_llm_base_url = st.text_input(tr("Base Url"), value=llm_base_url) st_llm_base_url = st.text_input(tr("Base Url"), value=llm_base_url)
st_llm_model_name = st.text_input(tr("Model Name"), value=llm_model_name) st_llm_model_name = st.text_input(tr("Model Name"), value=llm_model_name)
if st_llm_api_key: if st_llm_api_key:
config.app[f"{llm_provider}_api_key"] = st_llm_api_key config.app[f"{llm_provider}_api_key"] = st_llm_api_key
if st_llm_base_url: if st_llm_base_url:
@@ -234,7 +326,7 @@ with left_panel:
video_languages = [ video_languages = [
(tr("Auto Detect"), ""), (tr("Auto Detect"), ""),
] ]
for code in ["zh-CN", "zh-TW", "de-DE", "en-US", "vi-VN"]: for code in support_locales:
video_languages.append((code, code)) video_languages.append((code, code))
selected_index = st.selectbox(tr("Script Language"), selected_index = st.selectbox(tr("Script Language"),
@@ -300,7 +392,7 @@ with middle_panel:
with st.container(border=True): with st.container(border=True):
st.write(tr("Audio Settings")) st.write(tr("Audio Settings"))
voices = voice.get_all_azure_voices( voices = voice.get_all_azure_voices(
filter_locals=["zh-CN", "zh-HK", "zh-TW", "de-DE", "en-US", "fr-FR", "vi-VN"]) filter_locals=support_locales)
friendly_names = { friendly_names = {
v: v. v: v.
replace("Female", tr("Female")). replace("Female", tr("Female")).
@@ -313,7 +405,7 @@ with middle_panel:
saved_voice_name_index = list(friendly_names.keys()).index(saved_voice_name) saved_voice_name_index = list(friendly_names.keys()).index(saved_voice_name)
else: else:
for i, v in enumerate(voices): for i, v in enumerate(voices):
if v.lower().startswith(st.session_state['ui_language'].lower()): if v.lower().startswith(st.session_state['ui_language'].lower()) and "V2" not in v:
saved_voice_name_index = i saved_voice_name_index = i
break break
@@ -324,6 +416,7 @@ with middle_panel:
voice_name = list(friendly_names.keys())[list(friendly_names.values()).index(selected_friendly_name)] voice_name = list(friendly_names.keys())[list(friendly_names.values()).index(selected_friendly_name)]
params.voice_name = voice_name params.voice_name = voice_name
config.ui['voice_name'] = voice_name config.ui['voice_name'] = voice_name
if voice.is_azure_v2_voice(voice_name): if voice.is_azure_v2_voice(voice_name):
saved_azure_speech_region = config.azure.get(f"speech_region", "") saved_azure_speech_region = config.azure.get(f"speech_region", "")
saved_azure_speech_key = config.azure.get(f"speech_key", "") saved_azure_speech_key = config.azure.get(f"speech_key", "")
@@ -434,12 +527,16 @@ if start_button:
scroll_to_bottom() scroll_to_bottom()
result = tm.start(task_id=task_id, params=params) result = tm.start(task_id=task_id, params=params)
if not result or "videos" not in result:
st.error(tr("Video Generation Failed"))
logger.error(tr("Video Generation Failed"))
scroll_to_bottom()
st.stop()
video_files = result.get("videos", []) video_files = result.get("videos", [])
st.success(tr("Video Generation Completed")) st.success(tr("Video Generation Completed"))
try: try:
if video_files: if video_files:
# center the video player
player_cols = st.columns(len(video_files) * 2 + 1) player_cols = st.columns(len(video_files) * 2 + 1)
for i, url in enumerate(video_files): for i, url in enumerate(video_files):
player_cols[i * 2 + 1].video(url) player_cols[i * 2 + 1].video(url)

View File

@@ -50,6 +50,7 @@
"Generating Video": "Video wird erstellt, bitte warten...", "Generating Video": "Video wird erstellt, bitte warten...",
"Start Generating Video": "Beginne mit der Generierung", "Start Generating Video": "Beginne mit der Generierung",
"Video Generation Completed": "Video erfolgreich generiert", "Video Generation Completed": "Video erfolgreich generiert",
"Video Generation Failed": "Video Generierung fehlgeschlagen",
"You can download the generated video from the following links": "Sie können das generierte Video über die folgenden Links herunterladen", "You can download the generated video from the following links": "Sie können das generierte Video über die folgenden Links herunterladen",
"Basic Settings": "**Grunde Instellungen**", "Basic Settings": "**Grunde Instellungen**",
"Pexels API Key": "Pexels API Key (:red[Required] [Get API Key](https://www.pexels.com/api/))", "Pexels API Key": "Pexels API Key (:red[Required] [Get API Key](https://www.pexels.com/api/))",

View File

@@ -50,6 +50,7 @@
"Generating Video": "Generating video, please wait...", "Generating Video": "Generating video, please wait...",
"Start Generating Video": "Start Generating Video", "Start Generating Video": "Start Generating Video",
"Video Generation Completed": "Video Generation Completed", "Video Generation Completed": "Video Generation Completed",
"Video Generation Failed": "Video Generation Failed",
"You can download the generated video from the following links": "You can download the generated video from the following links", "You can download the generated video from the following links": "You can download the generated video from the following links",
"Pexels API Key": "Pexels API Key (:red[Required] [Get API Key](https://www.pexels.com/api/))", "Pexels API Key": "Pexels API Key (:red[Required] [Get API Key](https://www.pexels.com/api/))",
"Basic Settings": "**Basic Settings** (:blue[Click to expand])", "Basic Settings": "**Basic Settings** (:blue[Click to expand])",

View File

@@ -50,6 +50,7 @@
"Generating Video": "Đang tạo video, vui lòng đợi...", "Generating Video": "Đang tạo video, vui lòng đợi...",
"Start Generating Video": "Bắt Đầu Tạo Video", "Start Generating Video": "Bắt Đầu Tạo Video",
"Video Generation Completed": "Hoàn Tất Tạo Video", "Video Generation Completed": "Hoàn Tất Tạo Video",
"Video Generation Failed": "Tạo Video Thất Bại",
"You can download the generated video from the following links": "Bạn có thể tải video được tạo ra từ các liên kết sau", "You can download the generated video from the following links": "Bạn có thể tải video được tạo ra từ các liên kết sau",
"Pexels API Key": "Khóa API Pexels (:red[Bắt Buộc] [Lấy Khóa API](https://www.pexels.com/api/))", "Pexels API Key": "Khóa API Pexels (:red[Bắt Buộc] [Lấy Khóa API](https://www.pexels.com/api/))",
"Basic Settings": "**Cài Đặt Cơ Bản** (:blue[Nhấp để mở rộng])", "Basic Settings": "**Cài Đặt Cơ Bản** (:blue[Nhấp để mở rộng])",

View File

@@ -19,12 +19,12 @@
"Video Ratio": "视频比例", "Video Ratio": "视频比例",
"Portrait": "竖屏 9:16抖音视频", "Portrait": "竖屏 9:16抖音视频",
"Landscape": "横屏 16:9西瓜视频", "Landscape": "横屏 16:9西瓜视频",
"Clip Duration": "视频片段最大时长(秒)", "Clip Duration": "视频片段最大时长(秒)**不是视频总长度**,是指每个**合成片段**的长度)",
"Number of Videos Generated Simultaneously": "同时生成视频数量", "Number of Videos Generated Simultaneously": "同时生成视频数量",
"Audio Settings": "**音频设置**", "Audio Settings": "**音频设置**",
"Speech Synthesis": "朗读声音(:red[尽量与文案语言保持一致]", "Speech Synthesis": "朗读声音(:red[**与文案语言保持一致**。注意V2版效果更好但是需要API KEY]",
"Speech Region": "服务区域 (:red[必填,[点击获取](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/SpeechServices)])", "Speech Region": "服务区域 (:red[必填,[点击获取](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/SpeechServices)])",
"Speech Key": "API Key(:red[必填,[点击获取](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/SpeechServices)])", "Speech Key": "API Key (:red[必填,密钥1 或 密钥2 均可 [点击获取](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/SpeechServices)])",
"Speech Volume": "朗读音量1.0表示100%", "Speech Volume": "朗读音量1.0表示100%",
"Male": "男性", "Male": "男性",
"Female": "女性", "Female": "女性",
@@ -50,6 +50,7 @@
"Generating Video": "正在生成视频,请稍候...", "Generating Video": "正在生成视频,请稍候...",
"Start Generating Video": "开始生成视频", "Start Generating Video": "开始生成视频",
"Video Generation Completed": "视频生成完成", "Video Generation Completed": "视频生成完成",
"Video Generation Failed": "视频生成失败",
"You can download the generated video from the following links": "你可以从以下链接下载生成的视频", "You can download the generated video from the following links": "你可以从以下链接下载生成的视频",
"Basic Settings": "**基础设置** (:blue[点击展开])", "Basic Settings": "**基础设置** (:blue[点击展开])",
"Language": "界面语言", "Language": "界面语言",