Spaces:
Running
Running
其他精靈
Browse files- app.py +79 -65
- chatbot.py +2 -2
app.py
CHANGED
@@ -691,11 +691,11 @@ def screenshot_youtube_video(youtube_id, snapshot_sec):
|
|
691 |
|
692 |
|
693 |
# ---- Web ----
|
694 |
-
def process_web_link(link):
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
|
700 |
|
701 |
# ---- LLM Generator ----
|
@@ -1926,15 +1926,20 @@ def init_params(text, request: gr.Request):
|
|
1926 |
|
1927 |
return admin, reading_passage_admin, summary_admin, see_detail, password_text, youtube_link
|
1928 |
|
1929 |
-
def update_state(content_subject, content_grade, trascript):
|
1930 |
# inputs=[content_subject, content_grade, df_string_output],
|
1931 |
# outputs=[content_subject_state, content_grade_state, trascript_state]
|
1932 |
content_subject_state = content_subject
|
1933 |
content_grade_state = content_grade
|
1934 |
trascript_state = trascript
|
1935 |
streaming_chat_thread_id_state = create_thread_id()
|
|
|
|
|
|
|
|
|
|
|
|
|
1936 |
|
1937 |
-
return content_subject_state, content_grade_state, trascript_state, streaming_chat_thread_id_state
|
1938 |
|
1939 |
HEAD = """
|
1940 |
<meta charset="UTF-8">
|
@@ -2003,10 +2008,10 @@ HEAD = """
|
|
2003 |
with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, secondary_hue=gr.themes.colors.amber, text_size = gr.themes.sizes.text_lg), head=HEAD) as demo:
|
2004 |
with gr.Row() as admin:
|
2005 |
password = gr.Textbox(label="Password", type="password", elem_id="password_input", visible=True)
|
2006 |
-
file_upload = gr.File(label="Upload your CSV or Word file", visible=False)
|
2007 |
youtube_link = gr.Textbox(label="Enter YouTube Link", elem_id="youtube_link_input", visible=True)
|
2008 |
video_id = gr.Textbox(label="video_id", visible=False)
|
2009 |
-
|
|
|
2010 |
user_data = gr.Textbox(label="User Data", elem_id="user_data_input", visible=True)
|
2011 |
youtube_link_btn = gr.Button("Submit_YouTube_Link", elem_id="youtube_link_btn", visible=True)
|
2012 |
with gr.Row() as data_state:
|
@@ -2032,28 +2037,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2032 |
btn_create_question = gr.Button("生成其他問題", variant="primary")
|
2033 |
openai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
2034 |
with gr.Row():
|
2035 |
-
|
2036 |
-
|
2037 |
-
# with gr.Tab("GROQ"):
|
2038 |
-
# groq_ai_name = gr.Textbox(label="AI 助理名稱", value="groq", visible=False)
|
2039 |
-
# groq_chatbot = gr.Chatbot(avatar_images=[bot_avatar, user_avatar], label="groq mode chatbot", show_share_button=False, likeable=True)
|
2040 |
-
# groq_msg = gr.Textbox(label="Message")
|
2041 |
-
# groq_send_button = gr.Button("Send", variant="primary")
|
2042 |
-
# with gr.Tab("JUTOR"):
|
2043 |
-
# jutor_ai_name = gr.Textbox(label="AI 助理名稱", value="jutor", visible=False)
|
2044 |
-
# jutor_chatbot = gr.Chatbot(avatar_images=[bot_avatar, user_avatar], label="jutor mode chatbot", show_share_button=False, likeable=True)
|
2045 |
-
# jutor_msg = gr.Textbox(label="Message")
|
2046 |
-
# jutor_send_button = gr.Button("Send", variant="primary")
|
2047 |
-
# with gr.Tab("CLAUDE"):
|
2048 |
-
# claude_ai_name = gr.Textbox(label="AI 助理名稱", value="claude3", visible=False)
|
2049 |
-
# claude_chatbot = gr.Chatbot(avatar_images=[bot_avatar, user_avatar], label="claude mode chatbot", show_share_button=False, likeable=True)
|
2050 |
-
# claude_msg = gr.Textbox(label="Message")
|
2051 |
-
# claude_send_button = gr.Button("Send", variant="primary")
|
2052 |
-
with gr.Tab("其他精靈"):
|
2053 |
-
ai_name = gr.Dropdown(label="選擇 AI 助理", choices=["jutor", "claude3", "groq"], value="jutor")
|
2054 |
-
ai_chatbot = gr.Chatbot(avatar_images=[bot_avatar, user_avatar], label="ai_chatbot", show_share_button=False, likeable=True, show_label=False)
|
2055 |
-
ai_msg = gr.Textbox(label="Message")
|
2056 |
-
ai_send_button = gr.Button("Send", variant="primary")
|
2057 |
with gr.Tab("飛特音速版"):
|
2058 |
additional_inputs = [password, streaming_chat_thread_id_state, trascript_state, content_subject_state, content_grade_state]
|
2059 |
streaming_chat = gr.ChatInterface(
|
@@ -2065,6 +2050,20 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2065 |
clear_btn="🗑️ 清除全部",
|
2066 |
stop_btn="🛑 停止",
|
2067 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2068 |
with gr.Tab("文章模式"):
|
2069 |
with gr.Row() as reading_passage_admin:
|
2070 |
reading_passage_kind = gr.Textbox(value="reading_passage", show_label=False)
|
@@ -2197,7 +2196,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2197 |
mind_map_html = gr.HTML()
|
2198 |
|
2199 |
# --- Event ---
|
2200 |
-
# OPENAI 模式
|
2201 |
send_button.click(
|
2202 |
chat_with_opan_ai_assistant,
|
2203 |
inputs=[password, video_id, thread_id, df_string_output, msg, chatbot, content_subject, content_grade, socratic_mode_btn],
|
@@ -2208,35 +2207,10 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2208 |
inputs=[password, openai_chatbot_audio_input],
|
2209 |
outputs=[msg]
|
2210 |
)
|
2211 |
-
#
|
2212 |
-
|
2213 |
-
|
2214 |
-
|
2215 |
-
# outputs=[groq_msg, groq_chatbot]
|
2216 |
-
# )
|
2217 |
-
# # JUTOR API 模式
|
2218 |
-
# jutor_send_button.click(
|
2219 |
-
# chat_with_ai,
|
2220 |
-
# inputs=[jutor_ai_name, password, video_id, df_string_output, jutor_msg, jutor_chatbot, content_subject, content_grade, socratic_mode_btn],
|
2221 |
-
# outputs=[jutor_msg, jutor_chatbot]
|
2222 |
-
# )
|
2223 |
-
# # CLAUDE 模式
|
2224 |
-
# claude_send_button.click(
|
2225 |
-
# chat_with_ai,
|
2226 |
-
# inputs=[claude_ai_name, password, video_id, df_string_output, claude_msg, claude_chatbot, content_subject, content_grade, socratic_mode_btn],
|
2227 |
-
# outputs=[claude_msg, claude_chatbot]
|
2228 |
-
# )
|
2229 |
-
# ai_chatbot 模式
|
2230 |
-
ai_send_button.click(
|
2231 |
-
chat_with_ai,
|
2232 |
-
inputs=[ai_name, password, video_id, df_string_output, ai_msg, ai_chatbot, content_subject, content_grade, socratic_mode_btn],
|
2233 |
-
outputs=[ai_msg, ai_chatbot]
|
2234 |
-
)
|
2235 |
-
|
2236 |
-
# 连接按钮点击事件
|
2237 |
-
btn_1_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, df_string_output, btn_1, chatbot, content_subject, content_grade, socratic_mode_btn]
|
2238 |
-
btn_2_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, df_string_output, btn_2, chatbot, content_subject, content_grade, socratic_mode_btn]
|
2239 |
-
btn_3_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, df_string_output, btn_3, chatbot, content_subject, content_grade, socratic_mode_btn]
|
2240 |
btn_1.click(
|
2241 |
chat_with_opan_ai_assistant,
|
2242 |
inputs=btn_1_chat_with_opan_ai_assistant_input,
|
@@ -2252,15 +2226,40 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2252 |
inputs=btn_3_chat_with_opan_ai_assistant_input,
|
2253 |
outputs=[msg, chatbot, thread_id]
|
2254 |
)
|
2255 |
-
|
2256 |
btn_create_question.click(
|
2257 |
change_questions,
|
2258 |
inputs = [password, df_string_output],
|
2259 |
outputs = [btn_1, btn_2, btn_3]
|
2260 |
)
|
2261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2262 |
# file_upload.change(process_file, inputs=file_upload, outputs=df_string_output)
|
2263 |
-
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
2264 |
|
2265 |
# 当输入 YouTube 链接时触发
|
2266 |
process_youtube_link_inputs = [password, youtube_link]
|
@@ -2282,8 +2281,23 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2282 |
content_subject,
|
2283 |
content_grade,
|
2284 |
]
|
2285 |
-
update_state_inputs = [
|
2286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2287 |
|
2288 |
youtube_link.change(
|
2289 |
process_youtube_link,
|
|
|
691 |
|
692 |
|
693 |
# ---- Web ----
|
694 |
+
# def process_web_link(link):
|
695 |
+
# # 抓取和解析网页内容
|
696 |
+
# response = requests.get(link)
|
697 |
+
# soup = BeautifulSoup(response.content, 'html.parser')
|
698 |
+
# return soup.get_text()
|
699 |
|
700 |
|
701 |
# ---- LLM Generator ----
|
|
|
1926 |
|
1927 |
return admin, reading_passage_admin, summary_admin, see_detail, password_text, youtube_link
|
1928 |
|
1929 |
+
def update_state(content_subject, content_grade, trascript, question_1, question_2, question_3):
|
1930 |
# inputs=[content_subject, content_grade, df_string_output],
|
1931 |
# outputs=[content_subject_state, content_grade_state, trascript_state]
|
1932 |
content_subject_state = content_subject
|
1933 |
content_grade_state = content_grade
|
1934 |
trascript_state = trascript
|
1935 |
streaming_chat_thread_id_state = create_thread_id()
|
1936 |
+
ai_chatbot_question_1 = question_1
|
1937 |
+
ai_chatbot_question_2 = question_2
|
1938 |
+
ai_chatbot_question_3 = question_3
|
1939 |
+
|
1940 |
+
return content_subject_state, content_grade_state, trascript_state, streaming_chat_thread_id_state, \
|
1941 |
+
ai_chatbot_question_1, ai_chatbot_question_2, ai_chatbot_question_3
|
1942 |
|
|
|
1943 |
|
1944 |
HEAD = """
|
1945 |
<meta charset="UTF-8">
|
|
|
2008 |
with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, secondary_hue=gr.themes.colors.amber, text_size = gr.themes.sizes.text_lg), head=HEAD) as demo:
|
2009 |
with gr.Row() as admin:
|
2010 |
password = gr.Textbox(label="Password", type="password", elem_id="password_input", visible=True)
|
|
|
2011 |
youtube_link = gr.Textbox(label="Enter YouTube Link", elem_id="youtube_link_input", visible=True)
|
2012 |
video_id = gr.Textbox(label="video_id", visible=False)
|
2013 |
+
# file_upload = gr.File(label="Upload your CSV or Word file", visible=False)
|
2014 |
+
# web_link = gr.Textbox(label="Enter Web Page Link", visible=False)
|
2015 |
user_data = gr.Textbox(label="User Data", elem_id="user_data_input", visible=True)
|
2016 |
youtube_link_btn = gr.Button("Submit_YouTube_Link", elem_id="youtube_link_btn", visible=True)
|
2017 |
with gr.Row() as data_state:
|
|
|
2037 |
btn_create_question = gr.Button("生成其他問題", variant="primary")
|
2038 |
openai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
2039 |
with gr.Row():
|
2040 |
+
msg = gr.Textbox(label="訊息",scale=3)
|
2041 |
+
send_button = gr.Button("送出", variant="primary", scale=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2042 |
with gr.Tab("飛特音速版"):
|
2043 |
additional_inputs = [password, streaming_chat_thread_id_state, trascript_state, content_subject_state, content_grade_state]
|
2044 |
streaming_chat = gr.ChatInterface(
|
|
|
2050 |
clear_btn="🗑️ 清除全部",
|
2051 |
stop_btn="🛑 停止",
|
2052 |
)
|
2053 |
+
with gr.Tab("其他精靈"):
|
2054 |
+
ai_name = gr.Dropdown(label="選擇 AI 助理", choices=["jutor", "claude3", "groq"], value="jutor")
|
2055 |
+
ai_chatbot = gr.Chatbot(avatar_images=[bot_avatar, user_avatar], label="ai_chatbot", show_share_button=False, likeable=True, show_label=False, latex_delimiters=latex_delimiters)
|
2056 |
+
ai_chatbot_socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=False)
|
2057 |
+
with gr.Row():
|
2058 |
+
with gr.Accordion("你也有類似的問題想問嗎?", open=False) as ask_questions_accordion_2:
|
2059 |
+
ai_chatbot_question_1 = gr.Button("問題一")
|
2060 |
+
ai_chatbot_question_2 = gr.Button("問題一")
|
2061 |
+
ai_chatbot_question_3 = gr.Button("問題一")
|
2062 |
+
ai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
2063 |
+
with gr.Row():
|
2064 |
+
ai_msg = gr.Textbox(label="Message",scale=3)
|
2065 |
+
ai_send_button = gr.Button("Send", variant="primary",scale=1)
|
2066 |
+
|
2067 |
with gr.Tab("文章模式"):
|
2068 |
with gr.Row() as reading_passage_admin:
|
2069 |
reading_passage_kind = gr.Textbox(value="reading_passage", show_label=False)
|
|
|
2196 |
mind_map_html = gr.HTML()
|
2197 |
|
2198 |
# --- Event ---
|
2199 |
+
# OPENAI ASSISTANT CHATBOT 模式
|
2200 |
send_button.click(
|
2201 |
chat_with_opan_ai_assistant,
|
2202 |
inputs=[password, video_id, thread_id, df_string_output, msg, chatbot, content_subject, content_grade, socratic_mode_btn],
|
|
|
2207 |
inputs=[password, openai_chatbot_audio_input],
|
2208 |
outputs=[msg]
|
2209 |
)
|
2210 |
+
# OPENAI ASSISTANT CHATBOT 連接按鈕點擊事件
|
2211 |
+
btn_1_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, df_string_output, btn_1, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2212 |
+
btn_2_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, df_string_output, btn_2, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2213 |
+
btn_3_chat_with_opan_ai_assistant_input =[password, video_id, thread_id, df_string_output, btn_3, chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2214 |
btn_1.click(
|
2215 |
chat_with_opan_ai_assistant,
|
2216 |
inputs=btn_1_chat_with_opan_ai_assistant_input,
|
|
|
2226 |
inputs=btn_3_chat_with_opan_ai_assistant_input,
|
2227 |
outputs=[msg, chatbot, thread_id]
|
2228 |
)
|
|
|
2229 |
btn_create_question.click(
|
2230 |
change_questions,
|
2231 |
inputs = [password, df_string_output],
|
2232 |
outputs = [btn_1, btn_2, btn_3]
|
2233 |
)
|
2234 |
|
2235 |
+
# ai_chatbot 模式
|
2236 |
+
ai_send_button.click(
|
2237 |
+
chat_with_ai,
|
2238 |
+
inputs=[ai_name, password, video_id, df_string_output, ai_msg, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn],
|
2239 |
+
outputs=[ai_msg, ai_chatbot]
|
2240 |
+
)
|
2241 |
+
# ai_chatbot 连接按钮点击事件
|
2242 |
+
ai_chatbot_question_1_chat_with_ai_input =[ai_name, password, video_id, df_string_output, ai_chatbot_question_1, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2243 |
+
ai_chatbot_question_2_chat_with_ai_input =[ai_name, password, video_id, df_string_output, ai_chatbot_question_2, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2244 |
+
ai_chatbot_question_3_chat_with_ai_input =[ai_name, password, video_id, df_string_output, ai_chatbot_question_3, ai_chatbot, content_subject, content_grade, ai_chatbot_socratic_mode_btn]
|
2245 |
+
ai_chatbot_question_1.click(
|
2246 |
+
chat_with_ai,
|
2247 |
+
inputs=ai_chatbot_question_1_chat_with_ai_input,
|
2248 |
+
outputs=[ai_msg, ai_chatbot]
|
2249 |
+
)
|
2250 |
+
ai_chatbot_question_2.click(
|
2251 |
+
chat_with_ai,
|
2252 |
+
inputs=ai_chatbot_question_2_chat_with_ai_input,
|
2253 |
+
outputs=[ai_msg, ai_chatbot]
|
2254 |
+
)
|
2255 |
+
ai_chatbot_question_3.click(
|
2256 |
+
chat_with_ai,
|
2257 |
+
inputs=ai_chatbot_question_3_chat_with_ai_input,
|
2258 |
+
outputs=[ai_msg, ai_chatbot]
|
2259 |
+
)
|
2260 |
+
|
2261 |
# file_upload.change(process_file, inputs=file_upload, outputs=df_string_output)
|
2262 |
+
# file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
2263 |
|
2264 |
# 当输入 YouTube 链接时触发
|
2265 |
process_youtube_link_inputs = [password, youtube_link]
|
|
|
2281 |
content_subject,
|
2282 |
content_grade,
|
2283 |
]
|
2284 |
+
update_state_inputs = [
|
2285 |
+
content_subject,
|
2286 |
+
content_grade,
|
2287 |
+
df_string_output,
|
2288 |
+
btn_1,
|
2289 |
+
btn_2,
|
2290 |
+
btn_3
|
2291 |
+
]
|
2292 |
+
update_state_outputs = [
|
2293 |
+
content_subject_state,
|
2294 |
+
content_grade_state,
|
2295 |
+
trascript_state,
|
2296 |
+
streaming_chat_thread_id_state,
|
2297 |
+
ai_chatbot_question_1,
|
2298 |
+
ai_chatbot_question_2,
|
2299 |
+
ai_chatbot_question_3
|
2300 |
+
]
|
2301 |
|
2302 |
youtube_link.change(
|
2303 |
process_youtube_link,
|
chatbot.py
CHANGED
@@ -122,7 +122,7 @@ class Chatbot:
|
|
122 |
request_payload = {
|
123 |
"model": "mixtral-8x7b-32768",
|
124 |
"messages": messages,
|
125 |
-
"max_tokens":
|
126 |
}
|
127 |
groq_client = self.ai_client
|
128 |
response = groq_client.chat.completions.create(**request_payload)
|
@@ -141,7 +141,7 @@ class Chatbot:
|
|
141 |
"accept": "application/json",
|
142 |
"body": json.dumps({
|
143 |
"anthropic_version": "bedrock-2023-05-31",
|
144 |
-
"max_tokens":
|
145 |
"system": system_prompt,
|
146 |
"messages": messages
|
147 |
})
|
|
|
122 |
request_payload = {
|
123 |
"model": "mixtral-8x7b-32768",
|
124 |
"messages": messages,
|
125 |
+
"max_tokens": 500 # 設定一個較大的值,可根據需要調整
|
126 |
}
|
127 |
groq_client = self.ai_client
|
128 |
response = groq_client.chat.completions.create(**request_payload)
|
|
|
141 |
"accept": "application/json",
|
142 |
"body": json.dumps({
|
143 |
"anthropic_version": "bedrock-2023-05-31",
|
144 |
+
"max_tokens": 500,
|
145 |
"system": system_prompt,
|
146 |
"messages": messages
|
147 |
})
|