Spaces:
Sleeping
Sleeping
def chatbot_select(chatbot_name):
Browse files
app.py
CHANGED
|
@@ -2294,7 +2294,7 @@ def handle_conversation_by_open_ai_assistant(client, user_message, instructions,
|
|
| 2294 |
thread = client.beta.threads.retrieve(thread_id)
|
| 2295 |
|
| 2296 |
if metadata:
|
| 2297 |
-
client.beta.threads.update(thread_id=
|
| 2298 |
|
| 2299 |
# Send the user message to the thread
|
| 2300 |
client.beta.threads.messages.create(thread_id=thread.id, role="user", content=user_message)
|
|
@@ -2580,26 +2580,31 @@ def create_thread_id():
|
|
| 2580 |
def chatbot_select(chatbot_name):
|
| 2581 |
chatbot_select_accordion_visible = gr.update(visible=False)
|
| 2582 |
all_chatbot_select_btn_visible = gr.update(visible=True)
|
| 2583 |
-
chatbot_open_ai_visible = gr.update(visible=False)
|
| 2584 |
chatbot_open_ai_streaming_visible = gr.update(visible=False)
|
| 2585 |
-
|
| 2586 |
ai_name_update = gr.update(value="foxcat")
|
| 2587 |
-
|
|
|
|
| 2588 |
if chatbot_name == "chatbot_open_ai":
|
| 2589 |
-
|
|
|
|
| 2590 |
elif chatbot_name == "chatbot_open_ai_streaming":
|
| 2591 |
chatbot_open_ai_streaming_visible = gr.update(visible=True)
|
|
|
|
| 2592 |
else:
|
| 2593 |
-
|
|
|
|
| 2594 |
|
| 2595 |
ai_name_update = gr.update(value=chatbot_name)
|
| 2596 |
|
| 2597 |
-
return chatbot_select_accordion_visible, all_chatbot_select_btn_visible,
|
|
|
|
|
|
|
| 2598 |
|
| 2599 |
-
def update_avatar_images(avatar_images,
|
| 2600 |
value = [[
|
| 2601 |
"請問你是誰?",
|
| 2602 |
-
|
| 2603 |
]]
|
| 2604 |
ai_chatbot_update = gr.update(avatar_images=avatar_images, value=value)
|
| 2605 |
return ai_chatbot_update
|
|
@@ -2657,12 +2662,9 @@ def init_params(text, request: gr.Request):
|
|
| 2657 |
lesson_plan_accordion = gr.update(visible=True)
|
| 2658 |
exit_ticket_accordion = gr.update(visible=True)
|
| 2659 |
|
| 2660 |
-
chatbot_open_ai = gr.update(visible=False)
|
| 2661 |
chatbot_open_ai_streaming = gr.update(visible=False)
|
| 2662 |
-
|
| 2663 |
-
|
| 2664 |
-
ai_chatbot_socratic_mode_btn = gr.update(visible=True)
|
| 2665 |
-
streaming_chat_socratic_mode_btn = gr.update(visible=True)
|
| 2666 |
|
| 2667 |
# if youtube_link in query_params
|
| 2668 |
if "youtube_id" in request.query_params:
|
|
@@ -2681,15 +2683,12 @@ def init_params(text, request: gr.Request):
|
|
| 2681 |
worksheet_accordion = gr.update(visible=False)
|
| 2682 |
lesson_plan_accordion = gr.update(visible=False)
|
| 2683 |
exit_ticket_accordion = gr.update(visible=False)
|
| 2684 |
-
|
| 2685 |
-
ai_chatbot_socratic_mode_btn = gr.update(visible=False)
|
| 2686 |
-
streaming_chat_socratic_mode_btn = gr.update(visible=False)
|
| 2687 |
|
| 2688 |
return admin, reading_passage_admin, summary_admin, see_detail, \
|
| 2689 |
worksheet_accordion, lesson_plan_accordion, exit_ticket_accordion, \
|
| 2690 |
password_text, youtube_link, \
|
| 2691 |
-
|
| 2692 |
-
socratic_mode_btn, ai_chatbot_socratic_mode_btn, streaming_chat_socratic_mode_btn
|
| 2693 |
|
| 2694 |
def update_state(content_subject, content_grade, trascript, key_moments, questions_answers):
|
| 2695 |
# inputs=[content_subject, content_grade, df_string_output],
|
|
@@ -2706,16 +2705,12 @@ def update_state(content_subject, content_grade, trascript, key_moments, questio
|
|
| 2706 |
question_1 = questions_answers_json[0]["question"]
|
| 2707 |
question_2 = questions_answers_json[1]["question"]
|
| 2708 |
question_3 = questions_answers_json[2]["question"]
|
| 2709 |
-
btn_1 = question_1
|
| 2710 |
-
btn_2 = question_2
|
| 2711 |
-
btn_3 = question_3
|
| 2712 |
ai_chatbot_question_1 = question_1
|
| 2713 |
ai_chatbot_question_2 = question_2
|
| 2714 |
ai_chatbot_question_3 = question_3
|
| 2715 |
|
| 2716 |
return content_subject_state, content_grade_state, trascript_state, key_moments_state, \
|
| 2717 |
streaming_chat_thread_id_state, \
|
| 2718 |
-
btn_1, btn_2, btn_3, \
|
| 2719 |
ai_chatbot_question_1, ai_chatbot_question_2, ai_chatbot_question_3
|
| 2720 |
|
| 2721 |
|
|
@@ -2764,6 +2759,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2764 |
with gr.Tab("AI小精靈"):
|
| 2765 |
with gr.Row():
|
| 2766 |
all_chatbot_select_btn = gr.Button("選擇 AI 小精靈 👈", elem_id="all_chatbot_select_btn", visible=False, variant="secondary", size="sm")
|
|
|
|
| 2767 |
ai_name = gr.Dropdown(
|
| 2768 |
label="選擇 AI 助理",
|
| 2769 |
choices=[
|
|
@@ -2774,15 +2770,20 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2774 |
("狐狸貓","foxcat")
|
| 2775 |
],
|
| 2776 |
value="foxcat",
|
| 2777 |
-
visible=
|
| 2778 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2779 |
with gr.Accordion("選擇 AI 小精靈", elem_id="chatbot_select_accordion") as chatbot_select_accordion:
|
| 2780 |
with gr.Row():
|
| 2781 |
user_avatar = "https://em-content.zobj.net/source/google/263/flushed-face_1f633.png"
|
| 2782 |
-
|
| 2783 |
with gr.Column(scale=1, variant="panel", visible=True):
|
| 2784 |
-
|
| 2785 |
-
|
|
|
|
| 2786 |
我可以陪你一起學習本次的內容,有什麼問題都可以問我喔!\n
|
| 2787 |
🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!\n
|
| 2788 |
🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!\n
|
|
@@ -2791,21 +2792,10 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2791 |
🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!\n
|
| 2792 |
"""
|
| 2793 |
chatbot_open_ai_name = gr.State("chatbot_open_ai")
|
| 2794 |
-
gr.Image(value=
|
| 2795 |
chatbot_open_ai_select_btn = gr.Button("👆選擇【飛特精靈】", elem_id="chatbot_btn", visible=True, variant="primary")
|
| 2796 |
-
gr.Markdown(value=
|
| 2797 |
-
|
| 2798 |
-
streaming_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/11/1-%E6%98%9F%E7%A9%BA%E9%A0%AD%E8%B2%BC-%E5%A4%AA%E7%A9%BA%E7%8B%90%E7%8B%B8%E8%B2%93-150x150.png"
|
| 2799 |
-
streaming_chatbot_description = """Hi,我是【飛特音速】, \n
|
| 2800 |
-
說話比較快,但有什麼問題都可以問我喔! \n
|
| 2801 |
-
🚀 我沒有預設問題、也沒有語音輸入,適合快問快答,一起練習問出好問題吧 \n
|
| 2802 |
-
🔠 擅長用文字表達的你,可以用鍵盤輸入你的問題,我會盡力回答你的問題喔\n
|
| 2803 |
-
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔~
|
| 2804 |
-
"""
|
| 2805 |
-
chatbot_open_ai_streaming_name = gr.State("chatbot_open_ai_streaming")
|
| 2806 |
-
gr.Image(value=streaming_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
|
| 2807 |
-
chatbot_open_ai_streaming_select_btn = gr.Button("👆選擇【飛特音速】", elem_id="streaming_chatbot_btn", visible=True, variant="primary")
|
| 2808 |
-
gr.Markdown(value=streaming_chatbot_description, visible=True)
|
| 2809 |
with gr.Column(scale=1, variant="panel"):
|
| 2810 |
foxcat_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/06/%E7%A7%91%E5%AD%B8%E5%BE%BD%E7%AB%A0-2-150x150.png"
|
| 2811 |
foxcat_avatar_images = gr.State([user_avatar, foxcat_chatbot_avatar_url])
|
|
@@ -2850,51 +2840,32 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2850 |
gr.Image(value=maimai_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
|
| 2851 |
maimai_chatbot_select_btn = gr.Button("👆選擇【麥麥】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
|
| 2852 |
maimai_chatbot_description_value = gr.Markdown(value=maimai_chatbot_description, visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2853 |
with gr.Column(scale=1, variant="panel"):
|
| 2854 |
gr.Markdown(value="### 尚未開放", visible=True)
|
| 2855 |
|
| 2856 |
-
with gr.Row("飛特精靈") as chatbot_open_ai:
|
| 2857 |
-
with gr.Column():
|
| 2858 |
-
bot_avatar = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
|
| 2859 |
-
latex_delimiters = [{"left": "$", "right": "$", "display": False}]
|
| 2860 |
-
chatbot_greeting = [[
|
| 2861 |
-
"請問你是誰?",
|
| 2862 |
-
"""Hi,我是你的AI學伴【飛特精靈】,我可以陪你一起學習本次的內容,有什麼問題都可以問我喔!
|
| 2863 |
-
🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!
|
| 2864 |
-
🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!
|
| 2865 |
-
🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!
|
| 2866 |
-
💤 但我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
|
| 2867 |
-
🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!
|
| 2868 |
-
""",
|
| 2869 |
-
]]
|
| 2870 |
-
with gr.Row():
|
| 2871 |
-
chatbot = gr.Chatbot(avatar_images=[user_avatar, bot_avatar], label="OPEN AI", show_share_button=False, likeable=True, show_label=False, latex_delimiters=latex_delimiters,value=chatbot_greeting)
|
| 2872 |
-
with gr.Row():
|
| 2873 |
-
chatbot_ai_type = gr.Textbox(value="assistant", visible=False)
|
| 2874 |
-
thread_id = gr.Textbox(label="thread_id", visible=False)
|
| 2875 |
-
socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=False)
|
| 2876 |
-
with gr.Row():
|
| 2877 |
-
with gr.Accordion("你也有類似的問題想問嗎? 請按下 ◀︎", open=False) as ask_questions_accordion:
|
| 2878 |
-
btn_1 = gr.Button("問題一")
|
| 2879 |
-
btn_2 = gr.Button("問題一")
|
| 2880 |
-
btn_3 = gr.Button("問題一")
|
| 2881 |
-
gr.Markdown("### 重新生成問題")
|
| 2882 |
-
btn_create_question = gr.Button("生成其他問題", variant="primary")
|
| 2883 |
-
openai_chatbot_audio_input = gr.Audio(sources=["microphone"], type="filepath", max_length=60, label="語音輸入")
|
| 2884 |
-
with gr.Row():
|
| 2885 |
-
msg = gr.Textbox(label="訊息",scale=3)
|
| 2886 |
-
send_button = gr.Button("送出", variant="primary", scale=1)
|
| 2887 |
-
send_feedback_btn = gr.Button("提問力回饋", variant="primary", scale=1, visible=False)
|
| 2888 |
with gr.Row("飛特音速") as chatbot_open_ai_streaming:
|
| 2889 |
with gr.Column():
|
| 2890 |
-
streaming_chat_socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=True)
|
| 2891 |
streaming_chat_greeting = """
|
| 2892 |
Hi,我是【飛特音速】,說話比較快,但有什麼問題都可以問我喔! \n
|
| 2893 |
🚀 我沒有預設問題、也沒有語音輸入,適合快問快答的你 \n
|
| 2894 |
🔠 鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
|
| 2895 |
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
|
| 2896 |
"""
|
| 2897 |
-
additional_inputs = [password, video_id, user_data, streaming_chat_thread_id_state, trascript_state, key_moments_state, content_subject_state, content_grade_state,
|
| 2898 |
streaming_chat = gr.ChatInterface(
|
| 2899 |
fn=chat_with_opan_ai_assistant_streaming,
|
| 2900 |
additional_inputs=additional_inputs,
|
|
@@ -2905,7 +2876,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2905 |
stop_btn=None,
|
| 2906 |
description=streaming_chat_greeting
|
| 2907 |
)
|
| 2908 |
-
with gr.Row("
|
| 2909 |
with gr.Column():
|
| 2910 |
ai_chatbot_greeting = [[
|
| 2911 |
"請問你是誰?",
|
|
@@ -2917,11 +2888,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2917 |
""",
|
| 2918 |
]]
|
| 2919 |
with gr.Row():
|
| 2920 |
-
ai_chatbot = gr.Chatbot(label="ai_chatbot", show_share_button=False, likeable=True, show_label=False, latex_delimiters=latex_delimiters, value=ai_chatbot_greeting)
|
| 2921 |
-
with gr.Row():
|
| 2922 |
-
ai_chatbot_ai_type = gr.Textbox(value="chat_completions", visible=False)
|
| 2923 |
-
ai_chatbot_thread_id = gr.Textbox(label="thread_id", visible=False)
|
| 2924 |
-
ai_chatbot_socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=False)
|
| 2925 |
with gr.Row():
|
| 2926 |
with gr.Accordion("你也有類似的問題想問嗎? 請按下 ◀︎", open=False) as ask_questions_accordion_2:
|
| 2927 |
ai_chatbot_question_1 = gr.Button("問題一")
|
|
@@ -3115,23 +3082,26 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 3115 |
with gr.Tab("心智圖",elem_id="mind_map_tab"):
|
| 3116 |
mind_map_html = gr.HTML()
|
| 3117 |
|
| 3118 |
-
# --- Event ---
|
| 3119 |
-
chatbot_select_outputs=[chatbot_select_accordion, all_chatbot_select_btn, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, ai_name]
|
| 3120 |
-
|
| 3121 |
# OPEN AI CHATBOT SELECT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3122 |
chatbot_open_ai_select_btn.click(
|
| 3123 |
chatbot_select,
|
| 3124 |
inputs=[chatbot_open_ai_name],
|
| 3125 |
outputs=chatbot_select_outputs
|
| 3126 |
-
)
|
| 3127 |
-
chatbot_open_ai_streaming_select_btn.click(
|
| 3128 |
-
chatbot_select,
|
| 3129 |
-
inputs=[chatbot_open_ai_streaming_name],
|
| 3130 |
-
outputs=chatbot_select_outputs
|
| 3131 |
).then(
|
| 3132 |
-
|
| 3133 |
-
inputs=[],
|
| 3134 |
-
outputs=[
|
|
|
|
| 3135 |
)
|
| 3136 |
foxcat_chatbot_select_btn.click(
|
| 3137 |
chatbot_select,
|
|
@@ -3163,6 +3133,17 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 3163 |
outputs=[ai_chatbot],
|
| 3164 |
scroll_to_output=True
|
| 3165 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3166 |
# ALL CHATBOT SELECT LIST
|
| 3167 |
all_chatbot_select_btn.click(
|
| 3168 |
show_all_chatbot_accordion,
|
|
@@ -3171,23 +3152,23 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 3171 |
)
|
| 3172 |
|
| 3173 |
# OPENAI ASSISTANT CHATBOT 模式
|
| 3174 |
-
send_button.click(
|
| 3175 |
-
|
| 3176 |
-
|
| 3177 |
-
|
| 3178 |
-
|
| 3179 |
-
)
|
| 3180 |
-
send_feedback_btn.click(
|
| 3181 |
-
|
| 3182 |
-
|
| 3183 |
-
|
| 3184 |
-
|
| 3185 |
-
)
|
| 3186 |
-
openai_chatbot_audio_input.change(
|
| 3187 |
-
|
| 3188 |
-
|
| 3189 |
-
|
| 3190 |
-
)
|
| 3191 |
# OPENAI ASSISTANT CHATBOT 連接按鈕點擊事件
|
| 3192 |
def setup_question_button_click(button, inputs_list, outputs_list, chat_func, scroll_to_output=True):
|
| 3193 |
button.click(
|
|
@@ -3196,18 +3177,18 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 3196 |
outputs=outputs_list,
|
| 3197 |
scroll_to_output=scroll_to_output
|
| 3198 |
)
|
| 3199 |
-
question_buttons = [btn_1, btn_2, btn_3]
|
| 3200 |
-
for question_btn in question_buttons:
|
| 3201 |
-
|
| 3202 |
-
|
| 3203 |
-
|
| 3204 |
|
| 3205 |
# 為生成問題按鈕設定特殊的點擊事件
|
| 3206 |
-
btn_create_question.click(
|
| 3207 |
-
|
| 3208 |
-
|
| 3209 |
-
|
| 3210 |
-
)
|
| 3211 |
|
| 3212 |
# 其他精靈 ai_chatbot 模式
|
| 3213 |
ai_send_button.click(
|
|
@@ -3272,9 +3253,6 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 3272 |
trascript_state,
|
| 3273 |
key_moments_state,
|
| 3274 |
streaming_chat_thread_id_state,
|
| 3275 |
-
btn_1,
|
| 3276 |
-
btn_2,
|
| 3277 |
-
btn_3,
|
| 3278 |
ai_chatbot_question_1,
|
| 3279 |
ai_chatbot_question_2,
|
| 3280 |
ai_chatbot_question_3
|
|
@@ -3606,11 +3584,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 3606 |
exit_ticket_accordion,
|
| 3607 |
password,
|
| 3608 |
youtube_link,
|
| 3609 |
-
chatbot_open_ai,
|
| 3610 |
chatbot_open_ai_streaming,
|
| 3611 |
-
|
| 3612 |
-
|
| 3613 |
-
ai_chatbot_socratic_mode_btn,
|
| 3614 |
]
|
| 3615 |
demo.load(
|
| 3616 |
init_params,
|
|
|
|
| 2294 |
thread = client.beta.threads.retrieve(thread_id)
|
| 2295 |
|
| 2296 |
if metadata:
|
| 2297 |
+
client.beta.threads.update(thread_id=thread.id, metadata=metadata)
|
| 2298 |
|
| 2299 |
# Send the user message to the thread
|
| 2300 |
client.beta.threads.messages.create(thread_id=thread.id, role="user", content=user_message)
|
|
|
|
| 2580 |
def chatbot_select(chatbot_name):
|
| 2581 |
chatbot_select_accordion_visible = gr.update(visible=False)
|
| 2582 |
all_chatbot_select_btn_visible = gr.update(visible=True)
|
|
|
|
| 2583 |
chatbot_open_ai_streaming_visible = gr.update(visible=False)
|
| 2584 |
+
chatbot_ai_visible = gr.update(visible=False)
|
| 2585 |
ai_name_update = gr.update(value="foxcat")
|
| 2586 |
+
ai_chatbot_thread_id_update = gr.update(value="")
|
| 2587 |
+
|
| 2588 |
if chatbot_name == "chatbot_open_ai":
|
| 2589 |
+
chatbot_ai_visible = gr.update(visible=True)
|
| 2590 |
+
ai_chatbot_ai_type_update = gr.update(value="assistant")
|
| 2591 |
elif chatbot_name == "chatbot_open_ai_streaming":
|
| 2592 |
chatbot_open_ai_streaming_visible = gr.update(visible=True)
|
| 2593 |
+
ai_chatbot_ai_type_update = gr.update(value="assistant_streaming")
|
| 2594 |
else:
|
| 2595 |
+
chatbot_ai_visible = gr.update(visible=True)
|
| 2596 |
+
ai_chatbot_ai_type_update = gr.update(value="chat_completions")
|
| 2597 |
|
| 2598 |
ai_name_update = gr.update(value=chatbot_name)
|
| 2599 |
|
| 2600 |
+
return chatbot_select_accordion_visible, all_chatbot_select_btn_visible, \
|
| 2601 |
+
chatbot_open_ai_streaming_visible, chatbot_ai_visible, \
|
| 2602 |
+
ai_name_update, ai_chatbot_ai_type_update, ai_chatbot_thread_id_update
|
| 2603 |
|
| 2604 |
+
def update_avatar_images(avatar_images, chatbot_description_value):
|
| 2605 |
value = [[
|
| 2606 |
"請問你是誰?",
|
| 2607 |
+
chatbot_description_value
|
| 2608 |
]]
|
| 2609 |
ai_chatbot_update = gr.update(avatar_images=avatar_images, value=value)
|
| 2610 |
return ai_chatbot_update
|
|
|
|
| 2662 |
lesson_plan_accordion = gr.update(visible=True)
|
| 2663 |
exit_ticket_accordion = gr.update(visible=True)
|
| 2664 |
|
|
|
|
| 2665 |
chatbot_open_ai_streaming = gr.update(visible=False)
|
| 2666 |
+
chatbot_ai = gr.update(visible=False)
|
| 2667 |
+
ai_chatbot_params = gr.update(visible=True)
|
|
|
|
|
|
|
| 2668 |
|
| 2669 |
# if youtube_link in query_params
|
| 2670 |
if "youtube_id" in request.query_params:
|
|
|
|
| 2683 |
worksheet_accordion = gr.update(visible=False)
|
| 2684 |
lesson_plan_accordion = gr.update(visible=False)
|
| 2685 |
exit_ticket_accordion = gr.update(visible=False)
|
| 2686 |
+
ai_chatbot_params = gr.update(visible=False)
|
|
|
|
|
|
|
| 2687 |
|
| 2688 |
return admin, reading_passage_admin, summary_admin, see_detail, \
|
| 2689 |
worksheet_accordion, lesson_plan_accordion, exit_ticket_accordion, \
|
| 2690 |
password_text, youtube_link, \
|
| 2691 |
+
chatbot_open_ai_streaming, chatbot_ai, ai_chatbot_params
|
|
|
|
| 2692 |
|
| 2693 |
def update_state(content_subject, content_grade, trascript, key_moments, questions_answers):
|
| 2694 |
# inputs=[content_subject, content_grade, df_string_output],
|
|
|
|
| 2705 |
question_1 = questions_answers_json[0]["question"]
|
| 2706 |
question_2 = questions_answers_json[1]["question"]
|
| 2707 |
question_3 = questions_answers_json[2]["question"]
|
|
|
|
|
|
|
|
|
|
| 2708 |
ai_chatbot_question_1 = question_1
|
| 2709 |
ai_chatbot_question_2 = question_2
|
| 2710 |
ai_chatbot_question_3 = question_3
|
| 2711 |
|
| 2712 |
return content_subject_state, content_grade_state, trascript_state, key_moments_state, \
|
| 2713 |
streaming_chat_thread_id_state, \
|
|
|
|
| 2714 |
ai_chatbot_question_1, ai_chatbot_question_2, ai_chatbot_question_3
|
| 2715 |
|
| 2716 |
|
|
|
|
| 2759 |
with gr.Tab("AI小精靈"):
|
| 2760 |
with gr.Row():
|
| 2761 |
all_chatbot_select_btn = gr.Button("選擇 AI 小精靈 👈", elem_id="all_chatbot_select_btn", visible=False, variant="secondary", size="sm")
|
| 2762 |
+
with gr.Row() as ai_chatbot_params:
|
| 2763 |
ai_name = gr.Dropdown(
|
| 2764 |
label="選擇 AI 助理",
|
| 2765 |
choices=[
|
|
|
|
| 2770 |
("狐狸貓","foxcat")
|
| 2771 |
],
|
| 2772 |
value="foxcat",
|
| 2773 |
+
visible=True
|
| 2774 |
)
|
| 2775 |
+
ai_chatbot_ai_type = gr.Textbox(value="chat_completions", visible=True)
|
| 2776 |
+
ai_chatbot_thread_id = gr.Textbox(label="thread_id", visible=True)
|
| 2777 |
+
ai_chatbot_socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=True)
|
| 2778 |
+
latex_delimiters = [{"left": "$", "right": "$", "display": False}]
|
| 2779 |
with gr.Accordion("選擇 AI 小精靈", elem_id="chatbot_select_accordion") as chatbot_select_accordion:
|
| 2780 |
with gr.Row():
|
| 2781 |
user_avatar = "https://em-content.zobj.net/source/google/263/flushed-face_1f633.png"
|
| 2782 |
+
# 飛特精靈
|
| 2783 |
with gr.Column(scale=1, variant="panel", visible=True):
|
| 2784 |
+
vaitor_chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
|
| 2785 |
+
vaitor_chatbot_avatar_images = gr.State([user_avatar, vaitor_chatbot_avatar_url])
|
| 2786 |
+
vaitor_chatbot_description = """Hi,我是你的AI學伴【飛特精靈】,\n
|
| 2787 |
我可以陪你一起學習本次的內容,有什麼問題都可以問我喔!\n
|
| 2788 |
🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!\n
|
| 2789 |
🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!\n
|
|
|
|
| 2792 |
🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!\n
|
| 2793 |
"""
|
| 2794 |
chatbot_open_ai_name = gr.State("chatbot_open_ai")
|
| 2795 |
+
gr.Image(value=vaitor_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
|
| 2796 |
chatbot_open_ai_select_btn = gr.Button("👆選擇【飛特精靈】", elem_id="chatbot_btn", visible=True, variant="primary")
|
| 2797 |
+
vaitor_chatbot_description_value = gr.Markdown(value=vaitor_chatbot_description, visible=True)
|
| 2798 |
+
# 狐狸貓
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2799 |
with gr.Column(scale=1, variant="panel"):
|
| 2800 |
foxcat_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/06/%E7%A7%91%E5%AD%B8%E5%BE%BD%E7%AB%A0-2-150x150.png"
|
| 2801 |
foxcat_avatar_images = gr.State([user_avatar, foxcat_chatbot_avatar_url])
|
|
|
|
| 2840 |
gr.Image(value=maimai_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
|
| 2841 |
maimai_chatbot_select_btn = gr.Button("👆選擇【麥麥】", visible=True, variant="primary", elem_classes="chatbot_select_btn")
|
| 2842 |
maimai_chatbot_description_value = gr.Markdown(value=maimai_chatbot_description, visible=True)
|
| 2843 |
+
# 飛特音速
|
| 2844 |
+
with gr.Column(scale=1, variant="panel", visible=True):
|
| 2845 |
+
streaming_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/11/1-%E6%98%9F%E7%A9%BA%E9%A0%AD%E8%B2%BC-%E5%A4%AA%E7%A9%BA%E7%8B%90%E7%8B%B8%E8%B2%93-150x150.png"
|
| 2846 |
+
streaming_chatbot_description = """Hi,我是【飛特音速】, \n
|
| 2847 |
+
說話比較快,但有什麼問題都可以問我喔! \n
|
| 2848 |
+
🚀 我沒有預設問題、也沒有語音輸入,適合快問快答,一起練習問出好問題吧 \n
|
| 2849 |
+
🔠 擅長用文字表達的你,可以用鍵盤輸入你的問題,我會盡力回答你的問題喔\n
|
| 2850 |
+
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔~
|
| 2851 |
+
"""
|
| 2852 |
+
chatbot_open_ai_streaming_name = gr.State("chatbot_open_ai_streaming")
|
| 2853 |
+
gr.Image(value=streaming_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
|
| 2854 |
+
chatbot_open_ai_streaming_select_btn = gr.Button("👆選擇【飛特音速】", elem_id="streaming_chatbot_btn", visible=True, variant="primary")
|
| 2855 |
+
gr.Markdown(value=streaming_chatbot_description, visible=True)
|
| 2856 |
+
# 尚未開放
|
| 2857 |
with gr.Column(scale=1, variant="panel"):
|
| 2858 |
gr.Markdown(value="### 尚未開放", visible=True)
|
| 2859 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2860 |
with gr.Row("飛特音速") as chatbot_open_ai_streaming:
|
| 2861 |
with gr.Column():
|
|
|
|
| 2862 |
streaming_chat_greeting = """
|
| 2863 |
Hi,我是【飛特音速】,說話比較快,但有什麼問題都可以問我喔! \n
|
| 2864 |
🚀 我沒有預設問題、也沒有語音輸入,適合快問快答的你 \n
|
| 2865 |
🔠 鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
|
| 2866 |
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
|
| 2867 |
"""
|
| 2868 |
+
additional_inputs = [password, video_id, user_data, streaming_chat_thread_id_state, trascript_state, key_moments_state, content_subject_state, content_grade_state, ai_chatbot_socratic_mode_btn]
|
| 2869 |
streaming_chat = gr.ChatInterface(
|
| 2870 |
fn=chat_with_opan_ai_assistant_streaming,
|
| 2871 |
additional_inputs=additional_inputs,
|
|
|
|
| 2876 |
stop_btn=None,
|
| 2877 |
description=streaming_chat_greeting
|
| 2878 |
)
|
| 2879 |
+
with gr.Row("一般精靈") as chatbot_ai:
|
| 2880 |
with gr.Column():
|
| 2881 |
ai_chatbot_greeting = [[
|
| 2882 |
"請問你是誰?",
|
|
|
|
| 2888 |
""",
|
| 2889 |
]]
|
| 2890 |
with gr.Row():
|
| 2891 |
+
ai_chatbot = gr.Chatbot(label="ai_chatbot", show_share_button=False, likeable=True, show_label=False, latex_delimiters=latex_delimiters, value=ai_chatbot_greeting)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2892 |
with gr.Row():
|
| 2893 |
with gr.Accordion("你也有類似的問題想問嗎? 請按下 ◀︎", open=False) as ask_questions_accordion_2:
|
| 2894 |
ai_chatbot_question_1 = gr.Button("問題一")
|
|
|
|
| 3082 |
with gr.Tab("心智圖",elem_id="mind_map_tab"):
|
| 3083 |
mind_map_html = gr.HTML()
|
| 3084 |
|
|
|
|
|
|
|
|
|
|
| 3085 |
# OPEN AI CHATBOT SELECT
|
| 3086 |
+
chatbot_select_outputs=[
|
| 3087 |
+
chatbot_select_accordion,
|
| 3088 |
+
all_chatbot_select_btn,
|
| 3089 |
+
chatbot_open_ai_streaming,
|
| 3090 |
+
chatbot_ai,
|
| 3091 |
+
ai_name,
|
| 3092 |
+
ai_chatbot_ai_type,
|
| 3093 |
+
ai_chatbot_thread_id
|
| 3094 |
+
]
|
| 3095 |
+
|
| 3096 |
chatbot_open_ai_select_btn.click(
|
| 3097 |
chatbot_select,
|
| 3098 |
inputs=[chatbot_open_ai_name],
|
| 3099 |
outputs=chatbot_select_outputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3100 |
).then(
|
| 3101 |
+
update_avatar_images,
|
| 3102 |
+
inputs=[vaitor_chatbot_avatar_images, vaitor_chatbot_description_value],
|
| 3103 |
+
outputs=[ai_chatbot],
|
| 3104 |
+
scroll_to_output=True
|
| 3105 |
)
|
| 3106 |
foxcat_chatbot_select_btn.click(
|
| 3107 |
chatbot_select,
|
|
|
|
| 3133 |
outputs=[ai_chatbot],
|
| 3134 |
scroll_to_output=True
|
| 3135 |
)
|
| 3136 |
+
# STREAMING CHATBOT SELECT
|
| 3137 |
+
chatbot_open_ai_streaming_select_btn.click(
|
| 3138 |
+
chatbot_select,
|
| 3139 |
+
inputs=[chatbot_open_ai_streaming_name],
|
| 3140 |
+
outputs=chatbot_select_outputs
|
| 3141 |
+
).then(
|
| 3142 |
+
create_thread_id,
|
| 3143 |
+
inputs=[],
|
| 3144 |
+
outputs=[streaming_chat_thread_id_state]
|
| 3145 |
+
)
|
| 3146 |
+
|
| 3147 |
# ALL CHATBOT SELECT LIST
|
| 3148 |
all_chatbot_select_btn.click(
|
| 3149 |
show_all_chatbot_accordion,
|
|
|
|
| 3152 |
)
|
| 3153 |
|
| 3154 |
# OPENAI ASSISTANT CHATBOT 模式
|
| 3155 |
+
# send_button.click(
|
| 3156 |
+
# chat_with_any_ai,
|
| 3157 |
+
# inputs=[chatbot_ai_type, password, video_id, user_data, trascript_state, key_moments, msg, chatbot, content_subject, content_grade, questions_answers_json, socratic_mode_btn, thread_id, ai_name],
|
| 3158 |
+
# outputs=[msg, chatbot, send_button, send_feedback_btn, thread_id],
|
| 3159 |
+
# scroll_to_output=True
|
| 3160 |
+
# )
|
| 3161 |
+
# send_feedback_btn.click(
|
| 3162 |
+
# feedback_with_ai,
|
| 3163 |
+
# inputs=[chatbot_ai_type, chatbot, thread_id],
|
| 3164 |
+
# outputs=[chatbot, send_feedback_btn],
|
| 3165 |
+
# scroll_to_output=True
|
| 3166 |
+
# )
|
| 3167 |
+
# openai_chatbot_audio_input.change(
|
| 3168 |
+
# process_open_ai_audio_to_chatbot,
|
| 3169 |
+
# inputs=[password, openai_chatbot_audio_input],
|
| 3170 |
+
# outputs=[msg]
|
| 3171 |
+
# )
|
| 3172 |
# OPENAI ASSISTANT CHATBOT 連接按鈕點擊事件
|
| 3173 |
def setup_question_button_click(button, inputs_list, outputs_list, chat_func, scroll_to_output=True):
|
| 3174 |
button.click(
|
|
|
|
| 3177 |
outputs=outputs_list,
|
| 3178 |
scroll_to_output=scroll_to_output
|
| 3179 |
)
|
| 3180 |
+
# question_buttons = [btn_1, btn_2, btn_3]
|
| 3181 |
+
# for question_btn in question_buttons:
|
| 3182 |
+
# inputs_list = [chatbot_ai_type, password, video_id, user_data, trascript_state, key_moments, question_btn, chatbot, content_subject, content_grade, questions_answers_json, socratic_mode_btn, thread_id, ai_name]
|
| 3183 |
+
# outputs_list = [msg, chatbot, send_button, send_feedback_btn, thread_id]
|
| 3184 |
+
# setup_question_button_click(question_btn, inputs_list, outputs_list, chat_with_any_ai)
|
| 3185 |
|
| 3186 |
# 為生成問題按鈕設定特殊的點擊事件
|
| 3187 |
+
# btn_create_question.click(
|
| 3188 |
+
# change_questions,
|
| 3189 |
+
# inputs=[password, df_string_output],
|
| 3190 |
+
# outputs=question_buttons
|
| 3191 |
+
# )
|
| 3192 |
|
| 3193 |
# 其他精靈 ai_chatbot 模式
|
| 3194 |
ai_send_button.click(
|
|
|
|
| 3253 |
trascript_state,
|
| 3254 |
key_moments_state,
|
| 3255 |
streaming_chat_thread_id_state,
|
|
|
|
|
|
|
|
|
|
| 3256 |
ai_chatbot_question_1,
|
| 3257 |
ai_chatbot_question_2,
|
| 3258 |
ai_chatbot_question_3
|
|
|
|
| 3584 |
exit_ticket_accordion,
|
| 3585 |
password,
|
| 3586 |
youtube_link,
|
|
|
|
| 3587 |
chatbot_open_ai_streaming,
|
| 3588 |
+
chatbot_ai,
|
| 3589 |
+
ai_chatbot_params,
|
|
|
|
| 3590 |
]
|
| 3591 |
demo.load(
|
| 3592 |
init_params,
|