Update app.py
Browse files
app.py
CHANGED
|
@@ -217,3 +217,58 @@ def predict(message, history):
|
|
| 217 |
|
| 218 |
return "信息收集完毕,若尚未得到最终回复,请输入任意文字以继续。"
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
return "信息收集完毕,若尚未得到最终回复,请输入任意文字以继续。"
|
| 219 |
|
| 220 |
+
# ============================ Gradio UI ============================
|
| 221 |
+
with gr.Blocks() as demo:
|
| 222 |
+
gr.Markdown("""
|
| 223 |
+
# 🎓 AI 职业规划助手
|
| 224 |
+
欢迎!我是你的职业发展向导~请回答几个问题,我将为你定制专属的职业探索建议!
|
| 225 |
+
""")
|
| 226 |
+
|
| 227 |
+
chatbot = gr.Chatbot()
|
| 228 |
+
msg = gr.Textbox(placeholder="请输入你的回答...", label=None)
|
| 229 |
+
send = gr.Button("发送 🚀")
|
| 230 |
+
reset = gr.Button("🔄 重新开始")
|
| 231 |
+
|
| 232 |
+
def add_user_message(message, history):
|
| 233 |
+
history = history or []
|
| 234 |
+
history.append({"role": "user", "content": message})
|
| 235 |
+
return "", history
|
| 236 |
+
|
| 237 |
+
def add_bot_response(history):
|
| 238 |
+
message = history[-1]["content"]
|
| 239 |
+
reply = predict(message, history[:-1])
|
| 240 |
+
history.append({"role": "assistant", "content": reply})
|
| 241 |
+
return history
|
| 242 |
+
|
| 243 |
+
send.click(add_user_message, [msg, chatbot], [msg, chatbot]).then(
|
| 244 |
+
add_bot_response, chatbot, chatbot
|
| 245 |
+
)
|
| 246 |
+
msg.submit(add_user_message, [msg, chatbot], [msg, chatbot]).then(
|
| 247 |
+
add_bot_response, chatbot, chatbot
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
def reset_state():
|
| 251 |
+
global current_q_index, questions
|
| 252 |
+
global in_forward_flow, in_backward_flow
|
| 253 |
+
global forward_index, backward_index
|
| 254 |
+
global forward_done, backward_done, forward_recommendation_given
|
| 255 |
+
current_q_index = 0
|
| 256 |
+
questions = base_questions[:]
|
| 257 |
+
for key in user_profile:
|
| 258 |
+
user_profile[key] = None
|
| 259 |
+
in_forward_flow = in_backward_flow = False
|
| 260 |
+
forward_index = backward_index = 0
|
| 261 |
+
forward_done = backward_done = False
|
| 262 |
+
forward_recommendation_given = False
|
| 263 |
+
return []
|
| 264 |
+
|
| 265 |
+
reset.click(reset_state, outputs=chatbot)
|
| 266 |
+
|
| 267 |
+
def auto_intro():
|
| 268 |
+
return [{"role": "assistant", "content": base_questions[0][1]}]
|
| 269 |
+
|
| 270 |
+
demo.load(auto_intro, outputs=chatbot)
|
| 271 |
+
|
| 272 |
+
demo.launch()
|
| 273 |
+
|
| 274 |
+
|