Spaces:
Sleeping
Sleeping
其他精靈
Browse files- app.py +12 -11
- chatbot.py +7 -4
app.py
CHANGED
@@ -1612,7 +1612,7 @@ def download_exam_result(content):
|
|
1612 |
return word_path
|
1613 |
|
1614 |
# ---- Chatbot ----
|
1615 |
-
def chat_with_ai(ai_name, password, video_id,
|
1616 |
verify_password(password)
|
1617 |
|
1618 |
if chat_history is not None and len(chat_history) > 10:
|
@@ -1625,10 +1625,14 @@ def chat_with_ai(ai_name, password, video_id, trascript, user_message, chat_hist
|
|
1625 |
ai_client = BEDROCK_CLIENT
|
1626 |
elif ai_name == "groq":
|
1627 |
ai_client = GROQ_CLIENT
|
|
|
|
|
|
|
|
|
1628 |
|
1629 |
chatbot_config = {
|
1630 |
"video_id": video_id,
|
1631 |
-
"trascript":
|
1632 |
"content_subject": content_subject,
|
1633 |
"content_grade": content_grade,
|
1634 |
"jutor_chat_key": JUTOR_CHAT_KEY,
|
@@ -1987,9 +1991,6 @@ def update_state(content_subject, content_grade, trascript, question_1, question
|
|
1987 |
trascript_json = json.loads(trascript)
|
1988 |
formatted_simple_transcript = create_formatted_simple_transcript(trascript_json)
|
1989 |
trascript_state = formatted_simple_transcript
|
1990 |
-
print("=== update_state ===")
|
1991 |
-
print(trascript_state)
|
1992 |
-
print("=== update_state ===")
|
1993 |
streaming_chat_thread_id_state = create_thread_id()
|
1994 |
ai_chatbot_question_1 = question_1
|
1995 |
ai_chatbot_question_2 = question_2
|
@@ -2119,8 +2120,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2119 |
ai_chatbot_question_3 = gr.Button("問題一")
|
2120 |
ai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
2121 |
with gr.Row():
|
2122 |
-
ai_msg = gr.Textbox(label="
|
2123 |
-
ai_send_button = gr.Button("
|
2124 |
with gr.Tab("文章模式"):
|
2125 |
with gr.Row() as reading_passage_admin:
|
2126 |
reading_passage_kind = gr.Textbox(value="reading_passage", show_label=False)
|
@@ -2316,13 +2317,13 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2316 |
# ai_chatbot 模式
|
2317 |
ai_send_button.click(
|
2318 |
chat_with_ai,
|
2319 |
-
inputs=[ai_name, password, video_id,
|
2320 |
outputs=[ai_msg, ai_chatbot]
|
2321 |
)
|
2322 |
# ai_chatbot 连接按钮点击事件
|
2323 |
-
ai_chatbot_question_1_chat_with_ai_input =[ai_name, password, video_id,
|
2324 |
-
ai_chatbot_question_2_chat_with_ai_input =[ai_name, password, video_id,
|
2325 |
-
ai_chatbot_question_3_chat_with_ai_input =[ai_name, password, video_id,
|
2326 |
ai_chatbot_question_1.click(
|
2327 |
chat_with_ai,
|
2328 |
inputs=ai_chatbot_question_1_chat_with_ai_input,
|
|
|
1612 |
return word_path
|
1613 |
|
1614 |
# ---- Chatbot ----
|
1615 |
+
def chat_with_ai(ai_name, password, video_id, trascript_state, user_message, chat_history, content_subject, content_grade, socratic_mode=False):
|
1616 |
verify_password(password)
|
1617 |
|
1618 |
if chat_history is not None and len(chat_history) > 10:
|
|
|
1625 |
ai_client = BEDROCK_CLIENT
|
1626 |
elif ai_name == "groq":
|
1627 |
ai_client = GROQ_CLIENT
|
1628 |
+
if isinstance(trascript_state, str):
|
1629 |
+
simple_transcript = json.loads(trascript_state)
|
1630 |
+
else:
|
1631 |
+
simple_transcript = trascript_state
|
1632 |
|
1633 |
chatbot_config = {
|
1634 |
"video_id": video_id,
|
1635 |
+
"trascript": simple_transcript,
|
1636 |
"content_subject": content_subject,
|
1637 |
"content_grade": content_grade,
|
1638 |
"jutor_chat_key": JUTOR_CHAT_KEY,
|
|
|
1991 |
trascript_json = json.loads(trascript)
|
1992 |
formatted_simple_transcript = create_formatted_simple_transcript(trascript_json)
|
1993 |
trascript_state = formatted_simple_transcript
|
|
|
|
|
|
|
1994 |
streaming_chat_thread_id_state = create_thread_id()
|
1995 |
ai_chatbot_question_1 = question_1
|
1996 |
ai_chatbot_question_2 = question_2
|
|
|
2120 |
ai_chatbot_question_3 = gr.Button("問題一")
|
2121 |
ai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
2122 |
with gr.Row():
|
2123 |
+
ai_msg = gr.Textbox(label="訊息輸入",scale=3)
|
2124 |
+
ai_send_button = gr.Button("送出", variant="primary",scale=1)
|
2125 |
with gr.Tab("文章模式"):
|
2126 |
with gr.Row() as reading_passage_admin:
|
2127 |
reading_passage_kind = gr.Textbox(value="reading_passage", show_label=False)
|
|
|
2317 |
# ai_chatbot 模式
|
2318 |
ai_send_button.click(
|
2319 |
chat_with_ai,
|
2320 |
+
inputs=[ai_name, password, video_id, trascript_state, ai_msg, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn],
|
2321 |
outputs=[ai_msg, ai_chatbot]
|
2322 |
)
|
2323 |
# ai_chatbot 连接按钮点击事件
|
2324 |
+
ai_chatbot_question_1_chat_with_ai_input =[ai_name, password, video_id, trascript_state, ai_chatbot_question_1, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2325 |
+
ai_chatbot_question_2_chat_with_ai_input =[ai_name, password, video_id, trascript_state, ai_chatbot_question_2, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2326 |
+
ai_chatbot_question_3_chat_with_ai_input =[ai_name, password, video_id, trascript_state, ai_chatbot_question_3, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2327 |
ai_chatbot_question_1.click(
|
2328 |
chat_with_ai,
|
2329 |
inputs=ai_chatbot_question_1_chat_with_ai_input,
|
chatbot.py
CHANGED
@@ -13,10 +13,10 @@ class Chatbot:
|
|
13 |
self.ai_client = config.get('ai_client')
|
14 |
|
15 |
def get_transcript_text(self, transcript_data):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
transcript_text = json.dumps(transcript_json, ensure_ascii=False)
|
21 |
return transcript_text
|
22 |
|
@@ -65,6 +65,9 @@ class Chatbot:
|
|
65 |
- 回答時數學式請用數學符號代替文字(Latex 用 $ 字號 render)
|
66 |
"""
|
67 |
|
|
|
|
|
|
|
68 |
return system_prompt
|
69 |
|
70 |
def prepare_messages(self, chat_history, user_message):
|
|
|
13 |
self.ai_client = config.get('ai_client')
|
14 |
|
15 |
def get_transcript_text(self, transcript_data):
|
16 |
+
if isinstance(transcript_data, str):
|
17 |
+
transcript_json = json.loads(transcript_data)
|
18 |
+
else:
|
19 |
+
transcript_json = transcript_data
|
20 |
transcript_text = json.dumps(transcript_json, ensure_ascii=False)
|
21 |
return transcript_text
|
22 |
|
|
|
65 |
- 回答時數學式請用數學符號代替文字(Latex 用 $ 字號 render)
|
66 |
"""
|
67 |
|
68 |
+
print("====================================")
|
69 |
+
print(system_prompt)
|
70 |
+
|
71 |
return system_prompt
|
72 |
|
73 |
def prepare_messages(self, chat_history, user_message):
|