youngtsai commited on
Commit
2ac9392
·
1 Parent(s): 930c56c

lili_avatar_images = gr.State([user_avatar, lili_chatbot_avatar_url])

Browse files
Files changed (1) hide show
  1. app.py +31 -8
app.py CHANGED
@@ -2450,6 +2450,14 @@ def chatbot_select(chatbot_name):
2450
 
2451
  return chatbot_select_accordion_visible, chatbot_open_ai_visible, chatbot_open_ai_streaming_visible, chatbot_jutor_visible, ai_name_update
2452
 
 
 
 
 
 
 
 
 
2453
  # --- Slide mode ---
2454
  def update_slide(direction):
2455
  global TRANSCRIPTS
@@ -2635,6 +2643,8 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2635
  with gr.Tab("AI小精靈"):
2636
  with gr.Accordion("選擇 AI 小精靈", open=True) as chatbot_select_accordion:
2637
  with gr.Row():
 
 
2638
  with gr.Column(scale=1, variant="panel", visible=False):
2639
  chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2640
  chatbot_description = """Hi,我是你的AI學伴【飛特精靈】,\n
@@ -2663,20 +2673,22 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2663
  gr.Markdown(value=streaming_chatbot_description, visible=True)
2664
  with gr.Column(scale=1, variant="panel"):
2665
  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"
 
2666
  foxcat_chatbot_description = """Hi,我是【狐狸貓】,\n
2667
  也可以陪你一起學習本次的內容,有什麼問題都可以問我喔!\n
2668
  🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!\n
2669
  🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!\n
2670
  🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
2671
- 💤 精靈們體力都有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!\n
2672
  """
2673
  foxcat_chatbot_name = gr.State("foxcat")
2674
  gr.Image(value=foxcat_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2675
  foxcat_chatbot_select_btn = gr.Button("👆選擇【狐狸貓】", visible=True, variant="primary")
2676
- gr.Markdown(value=foxcat_chatbot_description, visible=True)
2677
  # 梨梨
2678
  with gr.Column(scale=1, variant="panel"):
2679
  lili_chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/live/v1283-new-topic-44-icon.png?v=20230529071206714"
 
2680
  lili_chatbot_description = """你好,我是溫柔的【梨梨】, \n
2681
  很高興可以在這裡陪伴你學習。如果你有任何疑問,請隨時向我提出哦! \n
2682
  🤔 如果你在思考如何提問,可以嘗試點擊下方的「問題一」、「問題二」或「問題三」,我會為你生成一些問題來幫助你啟動思考。 \n
@@ -2687,25 +2699,25 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2687
  lili_chatbot_name = gr.State("lili")
2688
  gr.Image(value=lili_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2689
  lili_chatbot_select_btn = gr.Button("👆選擇【梨梨】", visible=True, variant="primary")
2690
- gr.Markdown(value=lili_chatbot_description, visible=True)
2691
  # 麥麥
2692
  with gr.Column(scale=1, variant="panel"):
2693
  maimai_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/07/%E6%80%9D%E8%80%83%E5%8A%9B%E8%B6%85%E4%BA%BA%E5%BE%BD%E7%AB%A0_%E5%B7%A5%E4%BD%9C%E5%8D%80%E5%9F%9F-1-%E8%A4%87%E6%9C%AC-150x150.png"
 
2694
  maimai_chatbot_description = """Hi,我是迷人的【麥麥】,\n
2695
  我在這裡等���和你一起探索新知,任何疑問都可以向我提出!\n
2696
  🤔 如果你不知道從哪裡開始,試試左下方的「問題一」、「問題二」、「問題三」,我會為你提供一些啟發思考的問題。\n
2697
  🗣️ 你也可以利用右下角的語音輸入功能,讓我將你的語音轉成文字,是不是很酷?\n
2698
  🔠 當然,你也可以直接透過鍵盤向我發問,我會全力以赴來回答你的每一個問題。\n
2699
- 💤 我們這些精靈也需要休息,每次學習我們只能回答十個問題,當達到上限時,請給我一點時間充電再繼續。\n
2700
  """
2701
  maimai_chatbot_name = gr.State("maimai")
2702
  gr.Image(value=maimai_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2703
  maimai_chatbot_select_btn = gr.Button("👆選擇【麥麥】", visible=True, variant="primary")
2704
- gr.Markdown(value=maimai_chatbot_description, visible=True)
2705
 
2706
  with gr.Row("飛特精靈") as chatbot_open_ai:
2707
  with gr.Column():
2708
- user_avatar = "https://em-content.zobj.net/source/google/263/flushed-face_1f633.png"
2709
  bot_avatar = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2710
  latex_delimiters = [{"left": "$", "right": "$", "display": False}]
2711
  chatbot_greeting = [[
@@ -2764,7 +2776,6 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2764
  💤 精靈們體力都有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
2765
  """,
2766
  ]]
2767
- ai_chatbot_bot_avatar = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2019/11/%E5%9B%9B%E6%A0%BC%E6%95%85%E4%BA%8B-04.jpg"
2768
  ai_name = gr.Dropdown(
2769
  label="選擇 AI 助理",
2770
  choices=[
@@ -2775,7 +2786,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2775
  value="foxcat",
2776
  visible=False
2777
  )
2778
- ai_chatbot = gr.Chatbot(avatar_images=[user_avatar, ai_chatbot_bot_avatar], label="ai_chatbot", show_share_button=False, likeable=True, show_label=False, latex_delimiters=latex_delimiters, value=ai_chatbot_greeting)
2779
  ai_chatbot_socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=False)
2780
  with gr.Row():
2781
  with gr.Accordion("你也有類似的問題想問嗎?", open=False) as ask_questions_accordion_2:
@@ -2989,16 +3000,28 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
2989
  chatbot_select,
2990
  inputs=[foxcat_chatbot_name],
2991
  outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, ai_name]
 
 
 
 
2992
  )
2993
  lili_chatbot_select_btn.click(
2994
  chatbot_select,
2995
  inputs=[lili_chatbot_name],
2996
  outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, ai_name]
 
 
 
 
2997
  )
2998
  maimai_chatbot_select_btn.click(
2999
  chatbot_select,
3000
  inputs=[maimai_chatbot_name],
3001
  outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, ai_name]
 
 
 
 
3002
  )
3003
 
3004
  # OPENAI ASSISTANT CHATBOT 模式
 
2450
 
2451
  return chatbot_select_accordion_visible, chatbot_open_ai_visible, chatbot_open_ai_streaming_visible, chatbot_jutor_visible, ai_name_update
2452
 
2453
+ def update_avatar_images(avatar_images, maimai_chatbot_description_value):
2454
+ value = [[
2455
+ "請問你是誰?",
2456
+ maimai_chatbot_description_value
2457
+ ]]
2458
+ ai_chatbot_update = gr.update(avatar_images=avatar_images, value=value)
2459
+ return ai_chatbot_update
2460
+
2461
  # --- Slide mode ---
2462
  def update_slide(direction):
2463
  global TRANSCRIPTS
 
2643
  with gr.Tab("AI小精靈"):
2644
  with gr.Accordion("選擇 AI 小精靈", open=True) as chatbot_select_accordion:
2645
  with gr.Row():
2646
+ user_avatar = "https://em-content.zobj.net/source/google/263/flushed-face_1f633.png"
2647
+ ai_chatbot_bot_avatar = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2648
  with gr.Column(scale=1, variant="panel", visible=False):
2649
  chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2650
  chatbot_description = """Hi,我是你的AI學伴【飛特精靈】,\n
 
2673
  gr.Markdown(value=streaming_chatbot_description, visible=True)
2674
  with gr.Column(scale=1, variant="panel"):
2675
  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"
2676
+ foxcat_avatar_images = gr.State([user_avatar, foxcat_chatbot_avatar_url])
2677
  foxcat_chatbot_description = """Hi,我是【狐狸貓】,\n
2678
  也可以陪你一起學習本次的內容,有什麼問題都可以問我喔!\n
2679
  🤔 如果你不知道怎麼發問,可以點擊左下方的問題一、問題二、問題三,我會幫你生成問題!\n
2680
  🗣️ 也可以點擊右下方用語音輸入,我會幫你轉換成文字,厲害吧!\n
2681
  🔠 或是直接鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
2682
+ 💤 精靈們體力都有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
2683
  """
2684
  foxcat_chatbot_name = gr.State("foxcat")
2685
  gr.Image(value=foxcat_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2686
  foxcat_chatbot_select_btn = gr.Button("👆選擇【狐狸貓】", visible=True, variant="primary")
2687
+ foxcat_chatbot_description_value = gr.Markdown(value=foxcat_chatbot_description, visible=True)
2688
  # 梨梨
2689
  with gr.Column(scale=1, variant="panel"):
2690
  lili_chatbot_avatar_url = "https://junyitopicimg.s3.amazonaws.com/live/v1283-new-topic-44-icon.png?v=20230529071206714"
2691
+ lili_avatar_images = gr.State([user_avatar, lili_chatbot_avatar_url])
2692
  lili_chatbot_description = """你好,我是溫柔的【梨梨】, \n
2693
  很高興可以在這裡陪伴你學習。如果你有任何疑問,請隨時向我提出哦! \n
2694
  🤔 如果你在思考如何提問,可以嘗試點擊下方的「問題一」、「問題二」或「問題三」,我會為你生成一些問題來幫助你啟動思考。 \n
 
2699
  lili_chatbot_name = gr.State("lili")
2700
  gr.Image(value=lili_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2701
  lili_chatbot_select_btn = gr.Button("👆選擇【梨梨】", visible=True, variant="primary")
2702
+ lili_chatbot_description_value = gr.Markdown(value=lili_chatbot_description, visible=True)
2703
  # 麥麥
2704
  with gr.Column(scale=1, variant="panel"):
2705
  maimai_chatbot_avatar_url = "https://storage.googleapis.com/wpassets.junyiacademy.org/1/2020/07/%E6%80%9D%E8%80%83%E5%8A%9B%E8%B6%85%E4%BA%BA%E5%BE%BD%E7%AB%A0_%E5%B7%A5%E4%BD%9C%E5%8D%80%E5%9F%9F-1-%E8%A4%87%E6%9C%AC-150x150.png"
2706
+ maimai_avatar_images = gr.State([user_avatar, maimai_chatbot_avatar_url])
2707
  maimai_chatbot_description = """Hi,我是迷人的【麥麥】,\n
2708
  我在這裡等���和你一起探索新知,任何疑問都可以向我提出!\n
2709
  🤔 如果你不知道從哪裡開始,試試左下方的「問題一」、「問題二」、「問題三」,我會為你提供一些啟發思考的問題。\n
2710
  🗣️ 你也可以利用右下角的語音輸入功能,讓我將你的語音轉成文字,是不是很酷?\n
2711
  🔠 當然,你也可以直接透過鍵盤向我發問,我會全力以赴來回答你的每一個問題。\n
2712
+ 💤 我們這些精靈也需要休息,每次學習我們只能回答十個問題,當達到上限時,請給我一點時間充電再繼續。
2713
  """
2714
  maimai_chatbot_name = gr.State("maimai")
2715
  gr.Image(value=maimai_chatbot_avatar_url, height=100, width=100, show_label=False, show_download_button=False)
2716
  maimai_chatbot_select_btn = gr.Button("👆選擇【麥麥】", visible=True, variant="primary")
2717
+ maimai_chatbot_description_value = gr.Markdown(value=maimai_chatbot_description, visible=True)
2718
 
2719
  with gr.Row("飛特精靈") as chatbot_open_ai:
2720
  with gr.Column():
 
2721
  bot_avatar = "https://junyitopicimg.s3.amazonaws.com/s4byy--icon.jpe?v=20200513013523726"
2722
  latex_delimiters = [{"left": "$", "right": "$", "display": False}]
2723
  chatbot_greeting = [[
 
2776
  💤 精靈們體力都有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
2777
  """,
2778
  ]]
 
2779
  ai_name = gr.Dropdown(
2780
  label="選擇 AI 助理",
2781
  choices=[
 
2786
  value="foxcat",
2787
  visible=False
2788
  )
2789
+ ai_chatbot = gr.Chatbot(label="ai_chatbot", show_share_button=False, likeable=True, show_label=False, latex_delimiters=latex_delimiters, value=ai_chatbot_greeting)
2790
  ai_chatbot_socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=False)
2791
  with gr.Row():
2792
  with gr.Accordion("你也有類似的問題想問嗎?", open=False) as ask_questions_accordion_2:
 
3000
  chatbot_select,
3001
  inputs=[foxcat_chatbot_name],
3002
  outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, ai_name]
3003
+ ).then(
3004
+ update_avatar_images,
3005
+ inputs=[foxcat_avatar_images, foxcat_chatbot_description_value],
3006
+ outputs=[ai_chatbot]
3007
  )
3008
  lili_chatbot_select_btn.click(
3009
  chatbot_select,
3010
  inputs=[lili_chatbot_name],
3011
  outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, ai_name]
3012
+ ).then(
3013
+ update_avatar_images,
3014
+ inputs=[lili_avatar_images, lili_chatbot_description_value],
3015
+ outputs=[ai_chatbot]
3016
  )
3017
  maimai_chatbot_select_btn.click(
3018
  chatbot_select,
3019
  inputs=[maimai_chatbot_name],
3020
  outputs=[chatbot_select_accordion, chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, ai_name]
3021
+ ).then(
3022
+ update_avatar_images,
3023
+ inputs=[maimai_avatar_images, maimai_chatbot_description_value],
3024
+ outputs=[ai_chatbot]
3025
  )
3026
 
3027
  # OPENAI ASSISTANT CHATBOT 模式