HelenaXH commited on
Commit
c54bedc
·
verified ·
1 Parent(s): c0379f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -835,15 +835,17 @@ footer {
835
  send = gr.Button("发送 🚀", elem_id="custom-send")
836
  reset = gr.Button("🔄 重新开始")
837
 
 
838
  def add_user_message(m, hist):
839
  hist = hist or []
840
- hist.append({"role":"user","content":m})
841
  return "", hist
842
 
 
843
  def add_bot_response(hist):
844
  user_msg = hist[-1]["content"]
845
  bot_msg = predict(user_msg, hist[:-1])
846
- hist.append({"role":"assistant","content":bot_msg})
847
  return hist
848
 
849
  send.click(add_user_message, [msg, chatbot], [msg, chatbot]) \
@@ -852,6 +854,7 @@ footer {
852
  msg.submit(add_user_message, [msg, chatbot], [msg, chatbot]) \
853
  .then(add_bot_response, chatbot, chatbot)
854
 
 
855
  def reset_state():
856
  global current_q_index, questions
857
  global in_forward_flow, in_backward_flow
@@ -861,7 +864,6 @@ footer {
861
  global recommendation_round
862
  global forward_deep_dive_done
863
  global roadmap_offered, roadmap_done
864
-
865
  global direction_chosen, jobs_recommended, job_chosen
866
  global post_career_detail_asked, post_career_detail_done
867
 
@@ -892,8 +894,9 @@ footer {
892
 
893
  reset.click(reset_state, outputs=chatbot)
894
 
 
895
  def auto_first():
896
- return [{"role":"assistant","content": questions[0][1]}]
897
 
898
  demo.load(auto_first, outputs=chatbot)
899
- demo.launch()
 
835
  send = gr.Button("发送 🚀", elem_id="custom-send")
836
  reset = gr.Button("🔄 重新开始")
837
 
838
+ # 用户输入后将其加入历史
839
  def add_user_message(m, hist):
840
  hist = hist or []
841
+ hist.append({"role": "user", "content": m})
842
  return "", hist
843
 
844
+ # 自动调用主逻辑函数
845
  def add_bot_response(hist):
846
  user_msg = hist[-1]["content"]
847
  bot_msg = predict(user_msg, hist[:-1])
848
+ hist.append({"role": "assistant", "content": bot_msg})
849
  return hist
850
 
851
  send.click(add_user_message, [msg, chatbot], [msg, chatbot]) \
 
854
  msg.submit(add_user_message, [msg, chatbot], [msg, chatbot]) \
855
  .then(add_bot_response, chatbot, chatbot)
856
 
857
+ # 重置状态逻辑
858
  def reset_state():
859
  global current_q_index, questions
860
  global in_forward_flow, in_backward_flow
 
864
  global recommendation_round
865
  global forward_deep_dive_done
866
  global roadmap_offered, roadmap_done
 
867
  global direction_chosen, jobs_recommended, job_chosen
868
  global post_career_detail_asked, post_career_detail_done
869
 
 
894
 
895
  reset.click(reset_state, outputs=chatbot)
896
 
897
+ # 首次加载时自动触发欢迎提问
898
  def auto_first():
899
+ return [{"role": "assistant", "content": questions[0][1]}]
900
 
901
  demo.load(auto_first, outputs=chatbot)
902
+ demo.launch()