🐛 fix: fix the LLM logic

This commit is contained in:
yyhhyyyyyy
2024-12-12 14:29:14 +08:00
parent 85d446e2d0
commit 2d8cd23fe7
3 changed files with 270 additions and 249 deletions

View File

@@ -449,8 +449,12 @@ with left_panel:
selected_index = st.selectbox(
tr("Script Language"),
index=0,
options=range(len(video_languages)), # 使用索引作为内部选项值
format_func=lambda x: video_languages[x][0], # 显示给用户的是标签
options=range(
len(video_languages)
), # Use the index as the internal option value
format_func=lambda x: video_languages[x][
0
], # The label is displayed to the user
)
params.video_language = video_languages[selected_index][1]
@@ -462,9 +466,13 @@ with left_panel:
video_subject=params.video_subject, language=params.video_language
)
terms = llm.generate_terms(params.video_subject, script)
st.session_state["video_script"] = script
st.session_state["video_terms"] = ", ".join(terms)
if "Error: " in script:
st.error(tr(script))
elif "Error: " in terms:
st.error(tr(terms))
else:
st.session_state["video_script"] = script
st.session_state["video_terms"] = ", ".join(terms)
params.video_script = st.text_area(
tr("Video Script"), value=st.session_state["video_script"], height=280
)
@@ -475,7 +483,10 @@ with left_panel:
with st.spinner(tr("Generating Video Keywords")):
terms = llm.generate_terms(params.video_subject, params.video_script)
st.session_state["video_terms"] = ", ".join(terms)
if "Error: " in terms:
st.error(tr(terms))
else:
st.session_state["video_terms"] = ", ".join(terms)
params.video_terms = st.text_area(
tr("Video Keywords"), value=st.session_state["video_terms"]
@@ -522,8 +533,12 @@ with middle_panel:
selected_index = st.selectbox(
tr("Video Concat Mode"),
index=1,
options=range(len(video_concat_modes)), # 使用索引作为内部选项值
format_func=lambda x: video_concat_modes[x][0], # 显示给用户的是标签
options=range(
len(video_concat_modes)
), # Use the index as the internal option value
format_func=lambda x: video_concat_modes[x][
0
], # The label is displayed to the user
)
params.video_concat_mode = VideoConcatMode(
video_concat_modes[selected_index][1]
@@ -535,8 +550,12 @@ with middle_panel:
]
selected_index = st.selectbox(
tr("Video Ratio"),
options=range(len(video_aspect_ratios)), # 使用索引作为内部选项值
format_func=lambda x: video_aspect_ratios[x][0], # 显示给用户的是标签
options=range(
len(video_aspect_ratios)
), # Use the index as the internal option value
format_func=lambda x: video_aspect_ratios[x][
0
], # The label is displayed to the user
)
params.video_aspect = VideoAspect(video_aspect_ratios[selected_index][1])
@@ -648,13 +667,17 @@ with middle_panel:
selected_index = st.selectbox(
tr("Background Music"),
index=1,
options=range(len(bgm_options)), # 使用索引作为内部选项值
format_func=lambda x: bgm_options[x][0], # 显示给用户的是标签
options=range(
len(bgm_options)
), # Use the index as the internal option value
format_func=lambda x: bgm_options[x][
0
], # The label is displayed to the user
)
# 获取选择的背景音乐类型
# Get the selected background music type
params.bgm_type = bgm_options[selected_index][1]
# 根据选择显示或隐藏组件
# Show or hide components based on the selection
if params.bgm_type == "custom":
custom_bgm_file = st.text_input(tr("Custom Background Music File"))
if custom_bgm_file and os.path.exists(custom_bgm_file):
@@ -733,15 +756,6 @@ if start_button:
scroll_to_bottom()
st.stop()
if (
llm_provider != "g4f"
and llm_provider != "ollama"
and not config.app.get(f"{llm_provider}_api_key", "")
):
st.error(tr("Please Enter the LLM API Key"))
scroll_to_bottom()
st.stop()
if params.video_source not in ["pexels", "pixabay", "local"]:
st.error(tr("Please Select a Valid Video Source"))
scroll_to_bottom()