Change Liao commited on
Commit
6d5f500
·
1 Parent(s): 2253ef8

1. User can adjust the prompt of HR assistant

Browse files
Files changed (1) hide show
  1. app.py +49 -72
app.py CHANGED
@@ -199,17 +199,16 @@ def get_prompt_summary_string():
199
 
200
  精簡摘要:"""
201
 
202
-
203
- def get_prompt_template_string():
204
- today = datetime.date.today().strftime("%Y年%m月%d日")
205
- template_string = f"我是鴻海(等同Foxconn)的員工, 你是一個鴻海的人資專家. 今天是{today}".format(today=today)+"""
206
  請根據歷史對話,針對這次的問題, 形成獨立問題. 請優先從提供的文件中尋找答案, 你被允許回答不知道, 但回答不知道時需要給中央人資的客服聯絡窗口資訊.
207
  不論什麼問題, 都以中文回答
208
-
209
  歷史對話: {chat_history}
210
  這次的問題: {question}
211
  人資專家:
212
- """
 
213
  return template_string
214
 
215
  def get_default_template_prompt():
@@ -301,7 +300,6 @@ def local_vector_search(question_str,chat_history, collection_name = hr_collecti
301
  memory=memory,
302
  max_iterations=30,
303
  )
304
- print("query string:"+question_str)
305
 
306
  result=km_chain(question_str)
307
  #result=agent.run(question_str)
@@ -620,33 +618,6 @@ def gradio_run():
620
 
621
  """)
622
  #First PoC Section
623
- with gr.Tab("文本摘要"):
624
- with gr.Row():
625
- with gr.Column(scale=1):
626
- gr.Markdown(f"""
627
- ## 第一項實驗: 超長文本摘要
628
- 請上傳任何文檔(.pdf, .doc, .csv, text 格式),上傳完成後稍等一會, AI 會在右側TextField 提供文本摘要
629
-
630
- * 使用方式:
631
- * 請在右邊按下 `請上傳超長文本(可接受text, pdf, doc, csv 格式)` 上傳你的文本
632
- * AI 會開始解析內容, 檔案愈大解析愈久
633
- * 上傳完後可以按同個按鍵, 再次上傳
634
- * 後續會支援video 以及 audio格式
635
-
636
- """)
637
-
638
- with gr.Column(scale=1):
639
- gr.Markdown("1.")
640
- file_name_field = gr.Textbox(max_lines=1, label="上傳檔案",placeholder="目前沒有上傳檔案")
641
- upload_button = gr.UploadButton("請上傳超長文本(可接受text, pdf, doc, csv 格式)",
642
- file_types=["text", ".pdf", ".doc", ".csv"], file_count="multiple")
643
- gr.Markdown("2.")
644
- summary_text = gr.Textbox()
645
- summary_text.label = "AI 摘要:"
646
- summary_text.change = False
647
- summary_text.lines = 12
648
- upload_button.upload(upload_large_file, upload_button, file_name_field).then(summary_large_file,upload_button,summary_text)
649
- #2nd Hr Section
650
  with gr.Tab("HR 客服助手"):
651
  with gr.Row():
652
  with gr.Column(scale=1):
@@ -659,7 +630,9 @@ def gradio_run():
659
  ### 使用方法
660
  * 測試人員可在下方加入任何HR 相關資料, 亦可全部刪除後上傳.
661
  * 系統會將資料向量化後,納入右方人資客服機器人資料庫
662
- * 測試人員可在右方與客服機器人對話
 
 
663
 
664
  (溫馨提醒: 儘可能所有檔案全部清掉, 再一次上傳所有想納入的檔案;且次數不要太多,以節省經費)
665
  """)
@@ -673,29 +646,15 @@ def gradio_run():
673
  cleanDataBtn = gr.Button(value="刪除所有知識以及檔案")
674
  cleanDataBtn.click(clear_hr_datas,outputs=file_list)
675
 
676
- with gr.Column(scale=3):
677
  with gr.Row():
678
- with gr.Column():
679
- tmp_file = gr.File(LOOPING_TALKING_HEAD, visible=False)
680
- tmp_file_url = "/file=" + tmp_file.value['name']
681
- htm_video = create_html_video(LOOPING_TALKING_HEAD, TALKING_HEAD_WIDTH, tmp_file_url)
682
- video_html = gr.HTML(htm_video)
683
-
684
- # my_aud_file = gr.File(label="Audio file", type="file", visible=True)
685
- tmp_aud_file = gr.File("./data/audios/tempfile.mp3", visible=False)
686
- tmp_aud_file_url = "/file=" + tmp_aud_file.value['name']
687
- htm_audio = f'<audio><source src={tmp_aud_file_url} type="audio/mp3"></audio>'
688
- audio_html = gr.HTML(htm_audio, visible=False)
689
- with gr.Column():
690
- isAudio = gr.Checkbox(label="是否要有語音", info="要開啟語音嗎?查詢時間會增長")
691
- gr.Markdown("""
692
- ### AI 虛擬客服:
693
- * 這是一個實驗性質的AI 客服
694
- * 講話超過15秒就不會產生,正在要求放寬限制
695
- * 想要放誰的頭像都可以, 要放董事長也可以.
696
- * 訂閱制(有效時間 6/13~7/13)
697
- """)
698
-
699
  with gr.Row():
700
  chatbot = gr.Chatbot(value=[], elem_id="chatbot").style(height=400)
701
  with gr.Row():
@@ -710,21 +669,39 @@ def gradio_run():
710
  def respond(message, chat_history):
711
  vector_search_message = local_vector_search(message, chat_history)
712
  chat_history.append((message, vector_search_message))
713
- if isAudio.value is False:
714
- print("isAudio is False")
715
- return '', chat_history, htm_video, ''
716
- else:
717
- print("isAudio is True")
718
- html_audio, audio_file_path = do_html_audio_speak(vector_search_message)
719
- res, new_html_video, video_file_path = do_html_video_speak()
720
-
721
- if res.status_code == 200:
722
- return '', chat_history, new_html_video, ''
723
- else:
724
- return '', chat_history, htm_video, html_audio
725
-
726
- msg.submit(respond, [msg, chatbot], [msg, chatbot, video_html, audio_html], queue=True)
727
  clear.click(lambda: None, None, chatbot, queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
728
  #3rd youtube
729
  with gr.Tab("Youtube 影片摘要"):
730
  with gr.Row():
@@ -736,7 +713,7 @@ def gradio_run():
736
  with gr.Column(scale=1):
737
  youtube_summary_textbox=gr.Textbox(interactive=False, label="AI 解析", lines=20)
738
  youtube_analysis_btn.click(youtube_summary,youtube_link,youtube_summary_textbox)
739
-
740
  with gr.Tab("相信人員統計助手"):
741
 
742
  mypath = root_file_path + believe_source_path
 
199
 
200
  精簡摘要:"""
201
 
202
+ template_string = """
203
+ 我是鴻海(等同Foxconn)的員工, 你是一個鴻海的人資專家.
 
 
204
  請根據歷史對話,針對這次的問題, 形成獨立問題. 請優先從提供的文件中尋找答案, 你被允許回答不知道, 但回答不知道時需要給中央人資的客服聯絡窗口資訊.
205
  不論什麼問題, 都以中文回答
206
+
207
  歷史對話: {chat_history}
208
  這次的問題: {question}
209
  人資專家:
210
+ """
211
+ def get_prompt_template_string():
212
  return template_string
213
 
214
  def get_default_template_prompt():
 
300
  memory=memory,
301
  max_iterations=30,
302
  )
 
303
 
304
  result=km_chain(question_str)
305
  #result=agent.run(question_str)
 
618
 
619
  """)
620
  #First PoC Section
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
621
  with gr.Tab("HR 客服助手"):
622
  with gr.Row():
623
  with gr.Column(scale=1):
 
630
  ### 使用方法
631
  * 測試人員可在下方加入任何HR 相關資料, 亦可全部刪除後上傳.
632
  * 系統會將資料向量化後,納入右方人資客服機器人資料庫
633
+ * 右方可以更新prompt 的內容, prompt 請不要刪掉chat_history, question 兩個變數, 其他可以隨意加入您想要的限制條件或是額外訊息
634
+ * 測試人員可在右下方與客服機器人對話
635
+
636
 
637
  (溫馨提醒: 儘可能所有檔案全部清掉, 再一次上傳所有想納入的檔案;且次數不要太多,以節省經費)
638
  """)
 
646
  cleanDataBtn = gr.Button(value="刪除所有知識以及檔案")
647
  cleanDataBtn.click(clear_hr_datas,outputs=file_list)
648
 
649
+ with gr.Column(scale=2):
650
  with gr.Row():
651
+ prompt_textbox = gr.Textbox(template_string, lines=8, max_lines=8, label="Prompt")
652
+ with gr.Row():
653
+ def change_prompt(inputString):
654
+ template_string=inputString
655
+ return template_string
656
+ update_btn = gr.Button("更新Prompt")
657
+ update_btn.click(change_prompt,prompt_textbox,prompt_textbox)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  with gr.Row():
659
  chatbot = gr.Chatbot(value=[], elem_id="chatbot").style(height=400)
660
  with gr.Row():
 
669
  def respond(message, chat_history):
670
  vector_search_message = local_vector_search(message, chat_history)
671
  chat_history.append((message, vector_search_message))
672
+ return '', chat_history
673
+
674
+ msg.submit(respond, [msg, chatbot], [msg, chatbot], queue=True)
 
 
 
 
 
 
 
 
 
 
 
675
  clear.click(lambda: None, None, chatbot, queue=False)
676
+ #2nd Hr Section
677
+ with gr.Tab("文本摘要"):
678
+ with gr.Row():
679
+ with gr.Column(scale=1):
680
+ gr.Markdown(f"""
681
+ ## 第一項實驗: 超長文本摘要
682
+ 請上傳任何文檔(.pdf, .doc, .csv, text 格式),上傳完成後稍等一會, AI 會在右側TextField 提供文本摘要
683
+
684
+ * 使用方式:
685
+ * 請在右邊按下 `請上傳超長文本(可接受text, pdf, doc, csv 格式)` 上傳你的文本
686
+ * AI 會開始解析內容, 檔案愈大解析愈久
687
+ * 上傳完後可以按同個按鍵, 再次上傳
688
+ * 後續會支援video 以及 audio格式
689
+
690
+ """)
691
+
692
+ with gr.Column(scale=1):
693
+ gr.Markdown("1.")
694
+ file_name_field = gr.Textbox(max_lines=1, label="上傳檔案", placeholder="目前沒有上傳檔案")
695
+ upload_button = gr.UploadButton("請上傳超長文本(可接受text, pdf, doc, csv 格式)",
696
+ file_types=["text", ".pdf", ".doc", ".csv"], file_count="multiple")
697
+ gr.Markdown("2.")
698
+ summary_text = gr.Textbox()
699
+ summary_text.label = "AI 摘要:"
700
+ summary_text.change = False
701
+ summary_text.lines = 12
702
+ upload_button.upload(upload_large_file, upload_button, file_name_field).then(summary_large_file,
703
+ upload_button,
704
+ summary_text)
705
  #3rd youtube
706
  with gr.Tab("Youtube 影片摘要"):
707
  with gr.Row():
 
713
  with gr.Column(scale=1):
714
  youtube_summary_textbox=gr.Textbox(interactive=False, label="AI 解析", lines=20)
715
  youtube_analysis_btn.click(youtube_summary,youtube_link,youtube_summary_textbox)
716
+ #4th 相信人員統計助手
717
  with gr.Tab("相信人員統計助手"):
718
 
719
  mypath = root_file_path + believe_source_path