Spaces:
Sleeping
Sleeping
逐字稿資料:{trascript}
Browse files
app.py
CHANGED
@@ -994,7 +994,7 @@ def respond(user_message, data, chat_history, socratic_mode=False):
|
|
994 |
# 返回聊天历史和空字符串清空输入框
|
995 |
return "", chat_history
|
996 |
|
997 |
-
def chat_with_youtube_transcript(youtube_id, thread_id, user_message, chat_history, socratic_mode=False):
|
998 |
# 先計算 user_message 是否超過 500 個字
|
999 |
if len(user_message) > 1500:
|
1000 |
error_msg = "你的訊息太長了,請縮短訊息長度至五百字以內"
|
@@ -1002,14 +1002,36 @@ def chat_with_youtube_transcript(youtube_id, thread_id, user_message, chat_histo
|
|
1002 |
|
1003 |
assistant_id = "asst_kmvZLNkDUYaNkMNtZEAYxyPq"
|
1004 |
client = OPEN_AI_CLIENT
|
1005 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1006 |
instructions = f"""
|
|
|
|
|
1007 |
你是一個擅長資料分析跟影片教學的老師,user 為學生
|
1008 |
-
請根據 assistant beta 的上傳資料
|
1009 |
-
如果 file 內有找到 file.content["{youtube_id}"] 為資料文本,自行判斷資料的種類,
|
1010 |
-
如果沒有資料,請告訴用戶沒有逐字稿資料,但仍然可以進行對話,使用台灣人的口與表達,及繁體中文 zh-TW
|
1011 |
-
請嚴格執行,只根據 file.content["{youtube_id}"] 為資料文本,沒有就是沒有資料,不要引用其他資料
|
1012 |
-
|
1013 |
如果是影片類型,不用解釋逐字稿格式,直接回答學生問題
|
1014 |
socratic_mode = {socratic_mode}
|
1015 |
如果 socratic_mode = True,
|
@@ -1231,23 +1253,23 @@ with gr.Blocks() as demo:
|
|
1231 |
# chat_with_youtube_transcript
|
1232 |
send_button.click(
|
1233 |
chat_with_youtube_transcript,
|
1234 |
-
inputs=[video_id, thread_id, msg, chatbot, socratic_mode_btn],
|
1235 |
outputs=[msg, chatbot, thread_id]
|
1236 |
)
|
1237 |
# 连接按钮点击事件
|
1238 |
btn_1.click(
|
1239 |
chat_with_youtube_transcript,
|
1240 |
-
inputs=[video_id, thread_id, btn_1, chatbot, socratic_mode_btn],
|
1241 |
outputs=[msg, chatbot, thread_id]
|
1242 |
)
|
1243 |
btn_2.click(
|
1244 |
chat_with_youtube_transcript,
|
1245 |
-
inputs=[video_id, thread_id, btn_2, chatbot, socratic_mode_btn],
|
1246 |
outputs=[msg, chatbot, thread_id]
|
1247 |
)
|
1248 |
btn_3.click(
|
1249 |
chat_with_youtube_transcript,
|
1250 |
-
inputs=[video_id, thread_id, btn_3, chatbot, socratic_mode_btn],
|
1251 |
outputs=[msg, chatbot, thread_id]
|
1252 |
)
|
1253 |
|
|
|
994 |
# 返回聊天历史和空字符串清空输入框
|
995 |
return "", chat_history
|
996 |
|
997 |
+
def chat_with_youtube_transcript(youtube_id, thread_id, trascript, user_message, chat_history, socratic_mode=False):
|
998 |
# 先計算 user_message 是否超過 500 個字
|
999 |
if len(user_message) > 1500:
|
1000 |
error_msg = "你的訊息太長了,請縮短訊息長度至五百字以內"
|
|
|
1002 |
|
1003 |
assistant_id = "asst_kmvZLNkDUYaNkMNtZEAYxyPq"
|
1004 |
client = OPEN_AI_CLIENT
|
1005 |
+
|
1006 |
+
# 從 file 拿逐字稿資料
|
1007 |
+
# instructions = f"""
|
1008 |
+
# 你是一個擅長資料分析跟影片教學的老師,user 為學生
|
1009 |
+
# 請根據 assistant beta 的上傳資料
|
1010 |
+
# 如果 file 內有找到 file.content["{youtube_id}"] 為資料文本,自行判斷資料的種類,
|
1011 |
+
# 如果沒有資料,請告訴用戶沒有逐字稿資料,但仍然可以進行對話,使用台灣人的口與表達,及繁體中文 zh-TW
|
1012 |
+
# 請嚴格執行,只根據 file.content["{youtube_id}"] 為資料文本,沒有就是沒有資料,不要引用其他資料
|
1013 |
+
|
1014 |
+
# 如果是影片類型,不用解釋逐字稿格式,直接回答學生問題
|
1015 |
+
# socratic_mode = {socratic_mode}
|
1016 |
+
# 如果 socratic_mode = True,
|
1017 |
+
# - 請用蘇格拉底式的提問方式,引導學生思考,並且給予學生一些提示
|
1018 |
+
# - 不要直接給予答案,讓學生自己思考
|
1019 |
+
# - 但可以給予一些提示跟引導,例如給予影片的時間軸,讓學生自己去找答案
|
1020 |
+
# - 在你回答的開頭標註【蘇格拉底助教:{youtube_id} 】
|
1021 |
+
# 如果 socratic_mode = False,
|
1022 |
+
# - 直接回答學生問題
|
1023 |
+
# - 在你回答的開頭標註【一般學習精靈:{youtube_id} 】
|
1024 |
+
# 如果學生問了一些問題你無法判斷,請告訴學生你無法判斷,並建議學生可以問其他問題
|
1025 |
+
# 或者你可以反問學生一些問題,幫助學生更好的理解資料
|
1026 |
+
# 如果學生的問題與資料文本無關,請告訴學生你無法回答超出範圍的問題
|
1027 |
+
# 最後只要是參考逐字稿資料,請在回答的最後標註【參考資料:(分):(秒)】
|
1028 |
+
# """
|
1029 |
+
|
1030 |
+
# 直接安排逐字稿資料 in instructions
|
1031 |
instructions = f"""
|
1032 |
+
逐字稿資料:{trascript}
|
1033 |
+
-------------------------------------
|
1034 |
你是一個擅長資料分析跟影片教學的老師,user 為學生
|
|
|
|
|
|
|
|
|
|
|
1035 |
如果是影片類型,不用解釋逐字稿格式,直接回答學生問題
|
1036 |
socratic_mode = {socratic_mode}
|
1037 |
如果 socratic_mode = True,
|
|
|
1253 |
# chat_with_youtube_transcript
|
1254 |
send_button.click(
|
1255 |
chat_with_youtube_transcript,
|
1256 |
+
inputs=[video_id, thread_id, df_string_output, msg, chatbot, socratic_mode_btn],
|
1257 |
outputs=[msg, chatbot, thread_id]
|
1258 |
)
|
1259 |
# 连接按钮点击事件
|
1260 |
btn_1.click(
|
1261 |
chat_with_youtube_transcript,
|
1262 |
+
inputs=[video_id, thread_id, df_string_output, btn_1, chatbot, socratic_mode_btn],
|
1263 |
outputs=[msg, chatbot, thread_id]
|
1264 |
)
|
1265 |
btn_2.click(
|
1266 |
chat_with_youtube_transcript,
|
1267 |
+
inputs=[video_id, thread_id, df_string_output, btn_2, chatbot, socratic_mode_btn],
|
1268 |
outputs=[msg, chatbot, thread_id]
|
1269 |
)
|
1270 |
btn_3.click(
|
1271 |
chat_with_youtube_transcript,
|
1272 |
+
inputs=[video_id, thread_id, df_string_output, btn_3, chatbot, socratic_mode_btn],
|
1273 |
outputs=[msg, chatbot, thread_id]
|
1274 |
)
|
1275 |
|