youngtsai commited on
Commit
3016707
·
1 Parent(s): d4e0071

with gr.Accordion("選擇 AI 小精靈", open=True) as chatbot_select_accordion:

Browse files
Files changed (1) hide show
  1. app.py +87 -43
app.py CHANGED
@@ -2008,6 +2008,21 @@ def create_thread_id():
2008
  print(f"create new thread_id: {thread_id}")
2009
  return thread_id
2010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2011
  # --- Slide mode ---
2012
  def update_slide(direction):
2013
  global TRANSCRIPTS
@@ -2056,6 +2071,10 @@ def init_params(text, request: gr.Request):
2056
  lesson_plan_accordion = gr.update(visible=True)
2057
  exit_ticket_accordion = gr.update(visible=True)
2058
 
 
 
 
 
2059
  # if youtube_link in query_params
2060
  if "youtube_id" in request.query_params:
2061
  youtube_id = request.query_params["youtube_id"]
@@ -2076,7 +2095,8 @@ def init_params(text, request: gr.Request):
2076
 
2077
  return admin, reading_passage_admin, summary_admin, see_detail, \
2078
  worksheet_accordion, lesson_plan_accordion, exit_ticket_accordion, \
2079
- password_text, youtube_link
 
2080
 
2081
  def update_state(content_subject, content_grade, trascript, key_moments, question_1, question_2, question_3):
2082
  # inputs=[content_subject, content_grade, df_string_output],
@@ -2177,50 +2197,48 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2177
  key_moments_state = gr.State() # 使用 gr.State 存储 key_moments
2178
  streaming_chat_thread_id_state = gr.State() # 使用 gr.State 存储 streaming_chat_thread_id
2179
  with gr.Tab("AI小精靈"):
2180
- with gr.Accordion("選擇 AI 小精靈", open=True):
2181
  with gr.Row():
2182
- with gr.Column(scale=1):
2183
  chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2184
- chatbot_description = """Hi,我是你的AI學伴【飛特精靈】,我可以陪你一起學習本次的內容,有什麼問題都可以問我喔!
2185
- 🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!
2186
- 🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!
2187
- 🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!
2188
- 💤 但我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
2189
- 🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!
2190
  """
2191
-
2192
  gr.Image(value=chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2193
- gr.Button("👆選擇【飛特精靈】", elem_id="chatbot_btn", visible=True, variant="primary")
2194
- gr.Textbox(label="Chatbot Description", value=chatbot_description, visible=True)
2195
- with gr.Column(scale=1):
2196
- streaming_chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2197
- streaming_chatbot_description = """Hi,我是你的AI學伴【飛特精靈】,我可以陪你一起學習本次的內容,有什麼問題都可以問我喔!
2198
- 🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!
2199
- 🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!
2200
- 🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!
2201
- 💤 但我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
2202
- 🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!
2203
  """
 
2204
  gr.Image(value=streaming_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2205
- gr.Button("👆選擇【飛特音速】", elem_id="streaming_chatbot_btn", visible=True, variant="primary")
2206
- gr.Textbox(label="Chatbot Description", value=streaming_chatbot_description, visible=True)
2207
- with gr.Column(scale=1):
2208
- jutor_chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2209
- jutor_chatbot_description = """Hi,我是你的AI學伴【飛特精靈】,我可以陪你一起學習本次的內容,有什麼問題都可以問我喔!
2210
- 🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!
2211
- 🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!
2212
- 🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!
2213
- 💤 但我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
2214
- 🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!
2215
  """
 
2216
  gr.Image(value=jutor_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2217
- gr.Button("👆選擇【梨梨】", elem_id="jutor_chatbot_btn", visible=True, variant="primary")
2218
- gr.Textbox(label="Chatbot Description", value=jutor_chatbot_description, visible=True)
2219
 
2220
-
2221
-
2222
- with gr.Row():
2223
- with gr.Tab("飛特精靈"):
2224
  user_avatar = "https://em-content.zobj.net/source/google/263/flushed-face_1f633.png"
2225
  bot_avatar = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2226
  latex_delimiters = [{"left": "$", "right": "$", "display": False}]
@@ -2234,9 +2252,11 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2234
  🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!
2235
  """,
2236
  ]]
2237
- 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)
2238
- thread_id = gr.Textbox(label="thread_id", visible=False)
2239
- socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=False)
 
 
2240
  with gr.Row():
2241
  with gr.Accordion("你也有類似的問題想問嗎?", open=False) as ask_questions_accordion:
2242
  btn_1 = gr.Button("問題一")
@@ -2248,7 +2268,10 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2248
  with gr.Row():
2249
  msg = gr.Textbox(label="訊息",scale=3)
2250
  send_button = gr.Button("送出", variant="primary", scale=1)
2251
- with gr.Tab("飛特音速"):
 
 
 
2252
  streaming_chat_greeting = """
2253
  Hi,我是【飛特音速】,說話比較快,但有什麼問題都可以問我喔! \n
2254
  🚀 我沒有預設問題、也沒有語音輸入,適合快問快答的你 \n
@@ -2265,8 +2288,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2265
  clear_btn="🗑️ 清除全部",
2266
  stop_btn=None,
2267
  description=streaming_chat_greeting
2268
- )
2269
- with gr.Tab("其他精靈"):
 
2270
  ai_chatbot_greeting = [[
2271
  None,
2272
  """Hi,我是飛特精靈的朋友們【梨梨、麥麥、狐狸貓】,也可以陪你一起學習本次的內容,有什麼問題都可以問我喔!
@@ -2447,6 +2471,23 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2447
  mind_map_html = gr.HTML()
2448
 
2449
  # --- Event ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2450
  # OPENAI ASSISTANT CHATBOT 模式
2451
  send_button.click(
2452
  chat_with_opan_ai_assistant,
@@ -2777,7 +2818,10 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2777
  lesson_plan_accordion,
2778
  exit_ticket_accordion,
2779
  password,
2780
- youtube_link
 
 
 
2781
  ]
2782
  demo.load(
2783
  init_params,
 
2008
  print(f"create new thread_id: {thread_id}")
2009
  return thread_id
2010
 
2011
+ def chatbot_select(chatbot_name):
2012
+ chatbot_select_accordion_visible = gr.update(open=False)
2013
+ chatbot_open_ai_visible = gr.update(visible=False)
2014
+ chatbot_open_ai_streaming_visible = gr.update(visible=False)
2015
+ chatbot_jutor_visible = gr.update(visible=False)
2016
+
2017
+ if chatbot_name == "chatbot_open_ai":
2018
+ chatbot_open_ai_visible = gr.update(visible=True)
2019
+ elif chatbot_name == "chatbot_open_ai_streaming":
2020
+ chatbot_open_ai_streaming_visible = gr.update(visible=True)
2021
+ elif chatbot_name == "chatbot_jutor":
2022
+ chatbot_jutor_visible = gr.update(visible=True)
2023
+
2024
+ return chatbot_select_accordion_visible, chatbot_open_ai_visible, chatbot_open_ai_streaming_visible, chatbot_jutor_visible
2025
+
2026
  # --- Slide mode ---
2027
  def update_slide(direction):
2028
  global TRANSCRIPTS
 
2071
  lesson_plan_accordion = gr.update(visible=True)
2072
  exit_ticket_accordion = gr.update(visible=True)
2073
 
2074
+ chatbot_open_ai = gr.update(visible=False)
2075
+ chatbot_open_ai_streaming = gr.update(visible=False)
2076
+ chatbot_jutor = gr.update(visible=False)
2077
+
2078
  # if youtube_link in query_params
2079
  if "youtube_id" in request.query_params:
2080
  youtube_id = request.query_params["youtube_id"]
 
2095
 
2096
  return admin, reading_passage_admin, summary_admin, see_detail, \
2097
  worksheet_accordion, lesson_plan_accordion, exit_ticket_accordion, \
2098
+ password_text, youtube_link, \
2099
+ chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor
2100
 
2101
  def update_state(content_subject, content_grade, trascript, key_moments, question_1, question_2, question_3):
2102
  # inputs=[content_subject, content_grade, df_string_output],
 
2197
  key_moments_state = gr.State() # 使用 gr.State 存储 key_moments
2198
  streaming_chat_thread_id_state = gr.State() # 使用 gr.State 存储 streaming_chat_thread_id
2199
  with gr.Tab("AI小精靈"):
2200
+ with gr.Accordion("選擇 AI 小精靈", open=True) as chatbot_select_accordion:
2201
  with gr.Row():
2202
+ with gr.Column(scale=1, variant="panel"):
2203
  chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2204
+ chatbot_description = """Hi,我是你的AI學伴【飛特精靈】,我可以陪你一起學習本次的內容,有什麼問題都可以問我喔!\n
2205
+ 🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!\n
2206
+ 🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!\n
2207
+ 🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
2208
+ 💤 但我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!\n
2209
+ 🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!\n
2210
  """
2211
+ chatbot_open_ai_name = gr.State("chatbot_open_ai")
2212
  gr.Image(value=chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2213
+ chatbot_open_ai_select_btn = gr.Button("👆選擇【飛特精靈】", elem_id="chatbot_btn", visible=True, variant="primary")
2214
+ gr.Markdown(value=chatbot_description, visible=True)
2215
+ with gr.Column(scale=1, variant="panel"):
2216
+ 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"
2217
+ streaming_chatbot_description = """Hi,我是【飛特音速】, \n
2218
+ 說話比較快,但有什麼問題都可以問我喔! \n
2219
+ 🚀 我沒有預設問題、也沒有語音輸入,適合快問快答 \n
2220
+ 🔠 擅長用文字表達的你,可以用鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
2221
+ 💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
 
2222
  """
2223
+ chatbot_open_ai_streaming_name = gr.State("chatbot_open_ai_streaming")
2224
  gr.Image(value=streaming_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2225
+ chatbot_open_ai_streaming_select_btn = gr.Button("👆選擇【飛特音速】", elem_id="streaming_chatbot_btn", visible=True, variant="primary")
2226
+ gr.Markdown(value=streaming_chatbot_description, visible=True)
2227
+ with gr.Column(scale=1, variant="panel"):
2228
+ jutor_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2019/11/%E5%9B%9B%E6%A0%BC%E6%95%85%E4%BA%8B-04.jpg"
2229
+ jutor_chatbot_description = """Hi,我是飛特精靈的朋友們【梨梨、麥麥、狐狸貓】,也可以陪你一起學習本次的內容,有什麼問題都可以問我喔!\n
2230
+ 🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!\n
2231
+ 🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!\n
2232
+ 🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
2233
+ 💤 精靈們體力都有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!\n
 
2234
  """
2235
+ chatbot_jutor_name = gr.State("chatbot_jutor")
2236
  gr.Image(value=jutor_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2237
+ chatbot_jutor_select_btn = gr.Button("👆選擇【梨梨、麥麥、狐狸貓】", elem_id="jutor_chatbot_btn", visible=True, variant="primary")
2238
+ gr.Markdown(value=jutor_chatbot_description, visible=True)
2239
 
2240
+ with gr.Row("飛特精靈") as chatbot_open_ai:
2241
+ with gr.Column():
 
 
2242
  user_avatar = "https://em-content.zobj.net/source/google/263/flushed-face_1f633.png"
2243
  bot_avatar = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2244
  latex_delimiters = [{"left": "$", "right": "$", "display": False}]
 
2252
  🦄 如果達到上限,或是遇到精靈很累,請問問其他朋友,像是飛特音速說話的速度比較快,你是否跟得上呢?你也可以和其他精靈互動看看喔!
2253
  """,
2254
  ]]
2255
+ with gr.Row():
2256
+ 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)
2257
+ with gr.Row():
2258
+ thread_id = gr.Textbox(label="thread_id", visible=False)
2259
+ socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=False)
2260
  with gr.Row():
2261
  with gr.Accordion("你也有類似的問題想問嗎?", open=False) as ask_questions_accordion:
2262
  btn_1 = gr.Button("問題一")
 
2268
  with gr.Row():
2269
  msg = gr.Textbox(label="訊息",scale=3)
2270
  send_button = gr.Button("送出", variant="primary", scale=1)
2271
+
2272
+
2273
+ with gr.Row("飛特音速") as chatbot_open_ai_streaming:
2274
+ with gr.Column():
2275
  streaming_chat_greeting = """
2276
  Hi,我是【飛特音速】,說話比較快,但有什麼問題都可以問我喔! \n
2277
  🚀 我沒有預設問題、也沒有語音輸入,適合快問快答的你 \n
 
2288
  clear_btn="🗑️ 清除全部",
2289
  stop_btn=None,
2290
  description=streaming_chat_greeting
2291
+ )
2292
+ with gr.Row("其他精靈") as chatbot_jutor:
2293
+ with gr.Column():
2294
  ai_chatbot_greeting = [[
2295
  None,
2296
  """Hi,我是飛特精靈的朋友們【梨梨、麥麥、狐狸貓】,也可以陪你一起學習本次的內容,有什麼問題都可以問我喔!
 
2471
  mind_map_html = gr.HTML()
2472
 
2473
  # --- Event ---
2474
+ # CHATBOT SELECT
2475
+ chatbot_open_ai_select_btn.click(
2476
+ chatbot_select,
2477
+ inputs=[chatbot_open_ai_name],
2478
+ outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor]
2479
+ )
2480
+ chatbot_open_ai_streaming_select_btn.click(
2481
+ chatbot_select,
2482
+ inputs=[chatbot_open_ai_streaming_name],
2483
+ outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor]
2484
+ )
2485
+ chatbot_jutor_select_btn.click(
2486
+ chatbot_select,
2487
+ inputs=[chatbot_jutor_name],
2488
+ outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor]
2489
+ )
2490
+
2491
  # OPENAI ASSISTANT CHATBOT 模式
2492
  send_button.click(
2493
  chat_with_opan_ai_assistant,
 
2818
  lesson_plan_accordion,
2819
  exit_ticket_accordion,
2820
  password,
2821
+ youtube_link,
2822
+ chatbot_open_ai,
2823
+ chatbot_open_ai_streaming,
2824
+ chatbot_jutor
2825
  ]
2826
  demo.load(
2827
  init_params,