Spaces:
Sleeping
Sleeping
print("=====user_data=====")
Browse filesprint(f"user_data: {user_data}")
app.py
CHANGED
@@ -1693,9 +1693,12 @@ def get_instructions(content_subject, content_grade, key_moments):
|
|
1693 |
"""
|
1694 |
return instructions
|
1695 |
|
1696 |
-
def chat_with_ai(ai_name, password, video_id, trascript_state, key_moments, user_message, chat_history, content_subject, content_grade, socratic_mode=False):
|
1697 |
verify_password(password)
|
1698 |
|
|
|
|
|
|
|
1699 |
if chat_history is not None and len(chat_history) > 11:
|
1700 |
error_msg = "此次對話超過上限(對話一輪10次)"
|
1701 |
raise gr.Error(error_msg)
|
@@ -1764,9 +1767,12 @@ def chat_with_ai(ai_name, password, video_id, trascript_state, key_moments, user
|
|
1764 |
print(f"Error: {e}")
|
1765 |
return "请求失败,请稍后再试!", chat_history
|
1766 |
|
1767 |
-
def chat_with_opan_ai_assistant(password, youtube_id, thread_id, trascript_state, key_moments, user_message, chat_history, content_subject, content_grade, socratic_mode=False):
|
1768 |
verify_password(password)
|
1769 |
|
|
|
|
|
|
|
1770 |
# 先計算 user_message 是否超過 500 個字
|
1771 |
if len(user_message) > 1500:
|
1772 |
error_msg = "你的訊息太長了,請縮短訊息長度至五百字以內"
|
@@ -1922,9 +1928,12 @@ def poll_run_status(run_id, thread_id, timeout=600, poll_interval=5):
|
|
1922 |
|
1923 |
return run.status
|
1924 |
|
1925 |
-
def streaming_chat_with_open_ai(user_message, chat_history, password, thread_id, trascript, key_moments, content_subject, content_grade):
|
1926 |
verify_password(password)
|
1927 |
|
|
|
|
|
|
|
1928 |
print("===streaming_chat_with_open_ai===")
|
1929 |
print(thread_id)
|
1930 |
|
@@ -2204,7 +2213,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2204 |
🔠 鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
|
2205 |
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
|
2206 |
"""
|
2207 |
-
additional_inputs = [password, streaming_chat_thread_id_state, trascript_state, key_moments_state, content_subject_state, content_grade_state]
|
2208 |
streaming_chat = gr.ChatInterface(
|
2209 |
fn=streaming_chat_with_open_ai,
|
2210 |
additional_inputs=additional_inputs,
|
@@ -2400,7 +2409,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2400 |
# OPENAI ASSISTANT CHATBOT 模式
|
2401 |
send_button.click(
|
2402 |
chat_with_opan_ai_assistant,
|
2403 |
-
inputs=[password, video_id, thread_id, trascript_state, key_moments, msg, chatbot, content_subject, content_grade, socratic_mode_btn],
|
2404 |
outputs=[msg, chatbot, thread_id]
|
2405 |
)
|
2406 |
openai_chatbot_audio_input.change(
|
@@ -2409,9 +2418,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2409 |
outputs=[msg]
|
2410 |
)
|
2411 |
# OPENAI ASSISTANT CHATBOT 連接按鈕點擊事件
|
2412 |
-
btn_1_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, trascript_state, key_moments, btn_1, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2413 |
-
btn_2_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, trascript_state, key_moments, btn_2, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2414 |
-
btn_3_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, trascript_state, key_moments, btn_3, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2415 |
btn_1.click(
|
2416 |
chat_with_opan_ai_assistant,
|
2417 |
inputs=btn_1_chat_with_opan_ai_assistant_input,
|
@@ -2436,13 +2445,13 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2436 |
# ai_chatbot 模式
|
2437 |
ai_send_button.click(
|
2438 |
chat_with_ai,
|
2439 |
-
inputs=[ai_name, password, video_id, trascript_state, key_moments, ai_msg, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn],
|
2440 |
outputs=[ai_msg, ai_chatbot]
|
2441 |
)
|
2442 |
# ai_chatbot 连接按钮点击事件
|
2443 |
-
ai_chatbot_question_1_chat_with_ai_input =[ai_name, password, video_id, trascript_state, key_moments, ai_chatbot_question_1, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2444 |
-
ai_chatbot_question_2_chat_with_ai_input =[ai_name, password, video_id, trascript_state, key_moments, ai_chatbot_question_2, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2445 |
-
ai_chatbot_question_3_chat_with_ai_input =[ai_name, password, video_id, trascript_state, key_moments, ai_chatbot_question_3, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2446 |
ai_chatbot_question_1.click(
|
2447 |
chat_with_ai,
|
2448 |
inputs=ai_chatbot_question_1_chat_with_ai_input,
|
|
|
1693 |
"""
|
1694 |
return instructions
|
1695 |
|
1696 |
+
def chat_with_ai(ai_name, password, video_id, user_data, trascript_state, key_moments, user_message, chat_history, content_subject, content_grade, socratic_mode=False):
|
1697 |
verify_password(password)
|
1698 |
|
1699 |
+
print("=====user_data=====")
|
1700 |
+
print(f"user_data: {user_data}")
|
1701 |
+
|
1702 |
if chat_history is not None and len(chat_history) > 11:
|
1703 |
error_msg = "此次對話超過上限(對話一輪10次)"
|
1704 |
raise gr.Error(error_msg)
|
|
|
1767 |
print(f"Error: {e}")
|
1768 |
return "请求失败,请稍后再试!", chat_history
|
1769 |
|
1770 |
+
def chat_with_opan_ai_assistant(password, youtube_id, user_data, thread_id, trascript_state, key_moments, user_message, chat_history, content_subject, content_grade, socratic_mode=False):
|
1771 |
verify_password(password)
|
1772 |
|
1773 |
+
print("=====user_data=====")
|
1774 |
+
print(f"user_data: {user_data}")
|
1775 |
+
|
1776 |
# 先計算 user_message 是否超過 500 個字
|
1777 |
if len(user_message) > 1500:
|
1778 |
error_msg = "你的訊息太長了,請縮短訊息長度至五百字以內"
|
|
|
1928 |
|
1929 |
return run.status
|
1930 |
|
1931 |
+
def streaming_chat_with_open_ai(user_message, chat_history, password, user_data, thread_id, trascript, key_moments, content_subject, content_grade):
|
1932 |
verify_password(password)
|
1933 |
|
1934 |
+
print("=====user_data=====")
|
1935 |
+
print(f"user_data: {user_data}")
|
1936 |
+
|
1937 |
print("===streaming_chat_with_open_ai===")
|
1938 |
print(thread_id)
|
1939 |
|
|
|
2213 |
🔠 鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
|
2214 |
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
|
2215 |
"""
|
2216 |
+
additional_inputs = [password, user_data, streaming_chat_thread_id_state, trascript_state, key_moments_state, content_subject_state, content_grade_state]
|
2217 |
streaming_chat = gr.ChatInterface(
|
2218 |
fn=streaming_chat_with_open_ai,
|
2219 |
additional_inputs=additional_inputs,
|
|
|
2409 |
# OPENAI ASSISTANT CHATBOT 模式
|
2410 |
send_button.click(
|
2411 |
chat_with_opan_ai_assistant,
|
2412 |
+
inputs=[password, video_id, user_data, thread_id, trascript_state, key_moments, msg, chatbot, content_subject, content_grade, socratic_mode_btn],
|
2413 |
outputs=[msg, chatbot, thread_id]
|
2414 |
)
|
2415 |
openai_chatbot_audio_input.change(
|
|
|
2418 |
outputs=[msg]
|
2419 |
)
|
2420 |
# OPENAI ASSISTANT CHATBOT 連接按鈕點擊事件
|
2421 |
+
btn_1_chat_with_opan_ai_assistant_input =[password, video_id, user_data, thread_id, trascript_state, key_moments, btn_1, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2422 |
+
btn_2_chat_with_opan_ai_assistant_input =[password, video_id, user_data, thread_id, trascript_state, key_moments, btn_2, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2423 |
+
btn_3_chat_with_opan_ai_assistant_input =[password, video_id, user_data, thread_id, trascript_state, key_moments, btn_3, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2424 |
btn_1.click(
|
2425 |
chat_with_opan_ai_assistant,
|
2426 |
inputs=btn_1_chat_with_opan_ai_assistant_input,
|
|
|
2445 |
# ai_chatbot 模式
|
2446 |
ai_send_button.click(
|
2447 |
chat_with_ai,
|
2448 |
+
inputs=[ai_name, password, video_id, user_data, trascript_state, key_moments, ai_msg, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn],
|
2449 |
outputs=[ai_msg, ai_chatbot]
|
2450 |
)
|
2451 |
# ai_chatbot 连接按钮点击事件
|
2452 |
+
ai_chatbot_question_1_chat_with_ai_input =[ai_name, password, video_id, user_data, trascript_state, key_moments, ai_chatbot_question_1, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2453 |
+
ai_chatbot_question_2_chat_with_ai_input =[ai_name, password, video_id, user_data, trascript_state, key_moments, ai_chatbot_question_2, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2454 |
+
ai_chatbot_question_3_chat_with_ai_input =[ai_name, password, video_id, user_data, trascript_state, key_moments, ai_chatbot_question_3, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2455 |
ai_chatbot_question_1.click(
|
2456 |
chat_with_ai,
|
2457 |
inputs=ai_chatbot_question_1_chat_with_ai_input,
|