Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ base_questions = [
|
|
| 27 |
# ============================ Forward 模式问题 ============================
|
| 28 |
forward_additional_questions = [
|
| 29 |
("bg_info", """那么接下来我会需要你提供一些你的资料,并分享一些你的性格和喜好。请先告诉我,你的学校、年级、专业,和主修课程是什么?如果能提供你的选课表或resume就更好啦。"""),
|
| 30 |
-
("work_value", """非常好!那你认为
|
| 31 |
("personality_summary", "用几句话总结你的性格:比如外向/内向?喜欢挑战?注重细节?讨厌重复吗?"),
|
| 32 |
("dream_day", "再描述一下你理想工作的一天是什么样:在哪工作?做什么?和谁合作?忙还是闲?更自由还是更有秩序?")
|
| 33 |
]
|
|
@@ -94,8 +94,8 @@ def answer_abc_questions(selected, bg_info, wv, ps, dd):
|
|
| 94 |
学生目前想要的额外信息模块:{', '.join(desired_parts)}
|
| 95 |
请分别按顺序为每个模块写一段分析和建议,可以使用Markdown分段形式。
|
| 96 |
(A: 专业/选课方向 & 求职入门建议部分的回答请根据学生的学术背景信息分析学生已经有的能力,然后根据其选择的职业方向分析该学生未来的选课应该注重什么课程方向,提示学生课程名称和关键词)
|
| 97 |
-
(
|
| 98 |
-
(
|
| 99 |
|
| 100 |
请只回答用户所选模块,不要回答未选的模块。
|
| 101 |
"""
|
|
@@ -249,12 +249,18 @@ def recommend_3jobs_for_direction(direction, bg_info, wv, ps, dd):
|
|
| 249 |
)
|
| 250 |
output_text = resp.choices[0].message.content
|
| 251 |
|
| 252 |
-
#
|
|
|
|
| 253 |
user_profile["recommended_jobs"] = [
|
| 254 |
f"{direction} - 职业A",
|
| 255 |
f"{direction} - 职业B",
|
| 256 |
f"{direction} - 职业C"
|
| 257 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
return output_text
|
| 259 |
except Exception as e:
|
| 260 |
return f"推荐具体职业时出错: {str(e)}"
|
|
@@ -301,7 +307,8 @@ def recommend_3directions():
|
|
| 301 |
)
|
| 302 |
output_text = resp.choices[0].message.content
|
| 303 |
|
| 304 |
-
#
|
|
|
|
| 305 |
user_profile["recommended_directions"] = [
|
| 306 |
"方向1",
|
| 307 |
"方向2",
|
|
@@ -312,7 +319,7 @@ def recommend_3directions():
|
|
| 312 |
return f"多方向推荐出错: {str(e)}"
|
| 313 |
|
| 314 |
|
| 315 |
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 316 |
def generate_system_prompt():
|
| 317 |
mode = user_profile["mode"]
|
| 318 |
sc = user_profile["specific_career"]
|
|
@@ -363,7 +370,6 @@ def predict(message, history):
|
|
| 363 |
global recommendation_round
|
| 364 |
global forward_deep_dive_done
|
| 365 |
global roadmap_offered, roadmap_done
|
| 366 |
-
|
| 367 |
global direction_chosen, jobs_recommended, job_chosen
|
| 368 |
global post_career_detail_asked, post_career_detail_done
|
| 369 |
|
|
@@ -453,7 +459,8 @@ def predict(message, history):
|
|
| 453 |
|
| 454 |
# ~~~~~~~~~ Forward模式 ~~~~~~~~~
|
| 455 |
else:
|
| 456 |
-
|
|
|
|
| 457 |
# 收集 4个基础问题
|
| 458 |
if forward_index > 0 and forward_index <= len(forward_additional_questions):
|
| 459 |
prev_key = forward_additional_questions[forward_index - 1][0]
|
|
@@ -478,6 +485,7 @@ def predict(message, history):
|
|
| 478 |
sel_dir = user_profile["recommended_directions"][idx]
|
| 479 |
user_profile["selected_direction"] = sel_dir
|
| 480 |
direction_chosen = True
|
|
|
|
| 481 |
return recommend_3jobs_for_direction(
|
| 482 |
direction=sel_dir,
|
| 483 |
bg_info=user_profile["bg_info"] or "",
|
|
@@ -497,8 +505,8 @@ def predict(message, history):
|
|
| 497 |
else:
|
| 498 |
return "请回复1/2/3选择方向,或输入'换'来重新推荐"
|
| 499 |
|
| 500 |
-
#
|
| 501 |
-
elif direction_chosen and
|
| 502 |
choice = message.strip().lower()
|
| 503 |
if choice in ["1","2","3"]:
|
| 504 |
idx = int(choice) - 1
|
|
@@ -524,7 +532,7 @@ def predict(message, history):
|
|
| 524 |
"\n- B:本校资源利用建议" \
|
| 525 |
"\n- C:实习 & networking 积累" \
|
| 526 |
"\n如果你想查看其中一个或多个,请输入 A / B / C / AB / BC / AC / ABC" \
|
| 527 |
-
"\n如果都不需要,请回复
|
| 528 |
else:
|
| 529 |
return "无效的选项,请重新输入1/2/3或'换'"
|
| 530 |
elif choice == "换":
|
|
@@ -570,7 +578,7 @@ def predict(message, history):
|
|
| 570 |
|
| 571 |
elif roadmap_offered and not roadmap_done:
|
| 572 |
ans = message.strip().lower()
|
| 573 |
-
if ans
|
| 574 |
roadmap_done = True
|
| 575 |
forward_done = True
|
| 576 |
return do_time_roadmap()
|
|
@@ -606,7 +614,6 @@ def predict(message, history):
|
|
| 606 |
# 兜底
|
| 607 |
return "信息收集完毕,如还未得到最终回复,请再输入任意文字继续。"
|
| 608 |
|
| 609 |
-
|
| 610 |
# ============================ Gradio UI ============================
|
| 611 |
import gradio as gr
|
| 612 |
|
|
|
|
| 27 |
# ============================ Forward 模式问题 ============================
|
| 28 |
forward_additional_questions = [
|
| 29 |
("bg_info", """那么接下来我会需要你提供一些你的资料,并分享一些你的性格和喜好。请先告诉我,你的学校、年级、专业,和主修课程是什么?如果能提供你的选课表或resume就更好啦。"""),
|
| 30 |
+
("work_value", """非常好!那你认为"工作"的意义是什么?你觉得一份理想的工作,应该带来哪些价值或满足感?(例如:帮助他人、赚大钱、自由时间、个人成长、创意空间等)"""),
|
| 31 |
("personality_summary", "用几句话总结你的性格:比如外向/内向?喜欢挑战?注重细节?讨厌重复吗?"),
|
| 32 |
("dream_day", "再描述一下你理想工作的一天是什么样:在哪工作?做什么?和谁合作?忙还是闲?更自由还是更有秩序?")
|
| 33 |
]
|
|
|
|
| 94 |
学生目前想要的额外信息模块:{', '.join(desired_parts)}
|
| 95 |
请分别按顺序为每个模块写一段分析和建议,可以使用Markdown分段形式。
|
| 96 |
(A: 专业/选课方向 & 求职入门建议部分的回答请根据学生的学术背景信息分析学生已经有的能力,然后根据其选择的职业方向分析该学生未来的选课应该注重什么课程方向,提示学生课程名称和关键词)
|
| 97 |
+
('B: 本校资源利用建议'部分的回答请你从3个方面回答学生,包括1.如何利用学校的career service;2.如何关注学校与职业准备和证书考试相关的club、组织和平台;3.学生如何与学校的及其所在专业的校友取得联系和networking技巧)
|
| 98 |
+
('C: 实习 & Experience积累'部分的回答请你从申请internship的平台、达成目前职业目标需要的internship方向,申请需要的资料和准备技巧、通过networking获得实习或者学生工作经历的策略)
|
| 99 |
|
| 100 |
请只回答用户所选模块,不要回答未选的模块。
|
| 101 |
"""
|
|
|
|
| 249 |
)
|
| 250 |
output_text = resp.choices[0].message.content
|
| 251 |
|
| 252 |
+
# 示例:从回复中解析出职业名称
|
| 253 |
+
# 这里为简单起见使用模拟数据,实际应用中可以从output_text中解析
|
| 254 |
user_profile["recommended_jobs"] = [
|
| 255 |
f"{direction} - 职业A",
|
| 256 |
f"{direction} - 职业B",
|
| 257 |
f"{direction} - 职业C"
|
| 258 |
]
|
| 259 |
+
|
| 260 |
+
# 设置为已经推荐过职业
|
| 261 |
+
global jobs_recommended
|
| 262 |
+
jobs_recommended = True
|
| 263 |
+
|
| 264 |
return output_text
|
| 265 |
except Exception as e:
|
| 266 |
return f"推荐具体职业时出错: {str(e)}"
|
|
|
|
| 307 |
)
|
| 308 |
output_text = resp.choices[0].message.content
|
| 309 |
|
| 310 |
+
# 示例:从回复中解析方向名称
|
| 311 |
+
# 这里为简单起见使用模拟数据,实际应用中可以从output_text中解析
|
| 312 |
user_profile["recommended_directions"] = [
|
| 313 |
"方向1",
|
| 314 |
"方向2",
|
|
|
|
| 319 |
return f"多方向推荐出错: {str(e)}"
|
| 320 |
|
| 321 |
|
| 322 |
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 生成系统提示 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 323 |
def generate_system_prompt():
|
| 324 |
mode = user_profile["mode"]
|
| 325 |
sc = user_profile["specific_career"]
|
|
|
|
| 370 |
global recommendation_round
|
| 371 |
global forward_deep_dive_done
|
| 372 |
global roadmap_offered, roadmap_done
|
|
|
|
| 373 |
global direction_chosen, jobs_recommended, job_chosen
|
| 374 |
global post_career_detail_asked, post_career_detail_done
|
| 375 |
|
|
|
|
| 459 |
|
| 460 |
# ~~~~~~~~~ Forward模式 ~~~~~~~~~
|
| 461 |
else:
|
| 462 |
+
# 前期处理:收集信息和推荐大方向
|
| 463 |
+
if in_forward_flow and not direction_chosen:
|
| 464 |
# 收集 4个基础问题
|
| 465 |
if forward_index > 0 and forward_index <= len(forward_additional_questions):
|
| 466 |
prev_key = forward_additional_questions[forward_index - 1][0]
|
|
|
|
| 485 |
sel_dir = user_profile["recommended_directions"][idx]
|
| 486 |
user_profile["selected_direction"] = sel_dir
|
| 487 |
direction_chosen = True
|
| 488 |
+
# 不在这里设置jobs_recommended=True,而是在函数内部设置
|
| 489 |
return recommend_3jobs_for_direction(
|
| 490 |
direction=sel_dir,
|
| 491 |
bg_info=user_profile["bg_info"] or "",
|
|
|
|
| 505 |
else:
|
| 506 |
return "请回复1/2/3选择方向,或输入'换'来重新推荐"
|
| 507 |
|
| 508 |
+
# 已推荐具体职业 -> 等待用户选择
|
| 509 |
+
elif direction_chosen and jobs_recommended and not job_chosen:
|
| 510 |
choice = message.strip().lower()
|
| 511 |
if choice in ["1","2","3"]:
|
| 512 |
idx = int(choice) - 1
|
|
|
|
| 532 |
"\n- B:本校资源利用建议" \
|
| 533 |
"\n- C:实习 & networking 积累" \
|
| 534 |
"\n如果你想查看其中一个或多个,请输入 A / B / C / AB / BC / AC / ABC" \
|
| 535 |
+
"\n如果都不需要,请回复"不需要"。"
|
| 536 |
else:
|
| 537 |
return "无效的选项,请重新输入1/2/3或'换'"
|
| 538 |
elif choice == "换":
|
|
|
|
| 578 |
|
| 579 |
elif roadmap_offered and not roadmap_done:
|
| 580 |
ans = message.strip().lower()
|
| 581 |
+
if ans in ["要", "yes", "y"]:
|
| 582 |
roadmap_done = True
|
| 583 |
forward_done = True
|
| 584 |
return do_time_roadmap()
|
|
|
|
| 614 |
# 兜底
|
| 615 |
return "信息收集完毕,如还未得到最终回复,请再输入任意文字继续。"
|
| 616 |
|
|
|
|
| 617 |
# ============================ Gradio UI ============================
|
| 618 |
import gradio as gr
|
| 619 |
|