Update app.py
Browse files
app.py
CHANGED
|
@@ -72,15 +72,10 @@ top_p_default = 0.95
|
|
| 72 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 73 |
def answer_abc_questions(selected, bg_info, wv, ps, dd):
|
| 74 |
"""
|
| 75 |
-
动态地向OpenAI发起请求,让AI针对“专业/选课方向 & 求职入门(A)”、“本校资源利用(B)”、
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
selected 可能是 "a", "b", "c", "ab", "bc", "abc"等,
|
| 79 |
-
我们用 prompt 让模型只回答用户选中的部分。
|
| 80 |
"""
|
| 81 |
-
# 先把用户选择的模块整理好
|
| 82 |
desired_parts = []
|
| 83 |
-
# 我们会在 prompt 里告诉模型,对于选中的每个部分,都写一段分析
|
| 84 |
if "a" in selected:
|
| 85 |
desired_parts.append("A")
|
| 86 |
if "b" in selected:
|
|
@@ -88,21 +83,9 @@ def answer_abc_questions(selected, bg_info, wv, ps, dd):
|
|
| 88 |
if "c" in selected:
|
| 89 |
desired_parts.append("C")
|
| 90 |
|
| 91 |
-
# 如果用户啥都没选,就直接返回空
|
| 92 |
if not desired_parts:
|
| 93 |
return "好的,你暂时不需要查看A/B/C的专项信息。"
|
| 94 |
|
| 95 |
-
# 构造给模型的描述
|
| 96 |
-
# 让模型只输出用户所选模块的内容
|
| 97 |
-
# 这里可以再根据你的需求,告诉模型每个模块需要写什么要点
|
| 98 |
-
parts_description = {
|
| 99 |
-
"A": "A: 专业/选课方向 & 求职入门建议",
|
| 100 |
-
"B": "B: 本校资源利用建议",
|
| 101 |
-
"C": "C: 实习 & Experience积累(networking)",
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
# 在Prompt中,告诉模型这个人的背景,并要求对每个选中的模块输出详细分析
|
| 105 |
-
# 你可以视情况再加一些具体指令,比如段落格式等
|
| 106 |
prompt_text = f"""
|
| 107 |
你是一位专业的职业规划顾问。以下是学生背景信息,请根据他选择的模块(A/B/C)给出详细分析和建议。
|
| 108 |
学生背景:
|
|
@@ -111,8 +94,13 @@ def answer_abc_questions(selected, bg_info, wv, ps, dd):
|
|
| 111 |
- 性格: {ps}
|
| 112 |
- 理想工作: {dd}
|
| 113 |
|
| 114 |
-
学生目前想要的额外信息模块:{', '.join(desired_parts)}
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
模块说明:
|
| 117 |
A: 专业和选课方向 & 求职入门建议
|
| 118 |
B: 本校资源利用建议(如Career Center、校友资源)
|
|
@@ -120,7 +108,6 @@ C: 实习 & Experience积累(networking)
|
|
| 120 |
|
| 121 |
请只回答用户所选模块,不要回答未选的模块。
|
| 122 |
"""
|
| 123 |
-
|
| 124 |
try:
|
| 125 |
api_key = os.environ.get("API_TOKEN")
|
| 126 |
if not api_key:
|
|
@@ -270,7 +257,6 @@ def recommend_3jobs_for_direction(direction, bg_info, wv, ps, dd):
|
|
| 270 |
top_p=top_p_default,
|
| 271 |
stream=False
|
| 272 |
)
|
| 273 |
-
# 模型返回的文本
|
| 274 |
output_text = resp.choices[0].message.content
|
| 275 |
|
| 276 |
# 这里可以固定或基于返回文本做解析,我这边演示先手动赋值。
|
|
@@ -438,7 +424,6 @@ def predict(message, history):
|
|
| 438 |
global roadmap_offered, roadmap_done
|
| 439 |
|
| 440 |
global direction_chosen, jobs_recommended, job_chosen
|
| 441 |
-
|
| 442 |
global post_career_detail_asked, post_career_detail_done
|
| 443 |
|
| 444 |
# ======================== 初始化 =========================
|
|
@@ -463,8 +448,6 @@ def predict(message, history):
|
|
| 463 |
direction_chosen = False
|
| 464 |
jobs_recommended = False
|
| 465 |
job_chosen = False
|
| 466 |
-
|
| 467 |
-
# 重置 ABC 标记
|
| 468 |
post_career_detail_asked = False
|
| 469 |
post_career_detail_done = False
|
| 470 |
|
|
@@ -578,7 +561,6 @@ def predict(message, history):
|
|
| 578 |
|
| 579 |
# 已选定大方向 -> 推荐了3个具体职业
|
| 580 |
elif direction_chosen and not jobs_recommended and not job_chosen:
|
| 581 |
-
# 此时 message 应该是“AI 给出3个具体职业”后,用户的输入
|
| 582 |
choice = message.strip().lower()
|
| 583 |
if choice in ["1","2","3"]:
|
| 584 |
idx = int(choice) - 1
|
|
@@ -598,6 +580,7 @@ def predict(message, history):
|
|
| 598 |
forward_deep_dive_done = True
|
| 599 |
|
| 600 |
# 关键:现在我们“询问 A/B/C”
|
|
|
|
| 601 |
post_career_detail_asked = True
|
| 602 |
|
| 603 |
return detail_msg + "\n\n我还可以针对以下三方面提供**更深入**的分析建议:" \
|
|
@@ -626,7 +609,7 @@ def predict(message, history):
|
|
| 626 |
else:
|
| 627 |
return "请回复1/2/3选择具体职业,或输入'换'来重新推荐"
|
| 628 |
|
| 629 |
-
# ==============
|
| 630 |
elif post_career_detail_asked and not post_career_detail_done:
|
| 631 |
user_choice = message.strip().lower()
|
| 632 |
if user_choice in ["不需要", "no", "n"]:
|
|
@@ -741,13 +724,18 @@ footer {
|
|
| 741 |
display: none !important;
|
| 742 |
}
|
| 743 |
""") as demo:
|
| 744 |
-
|
|
|
|
| 745 |
gr.HTML("""
|
| 746 |
<div style='display: flex; align-items: center; justify-content: center; gap: 20px; margin-bottom: 10px;'>
|
| 747 |
-
<img src='https://media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExMmFucGwxbmNsd3J5NXV0Y282NXNtMzNsZW5jMm4wNWh6c2dqbXIwdiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l41m18LjqpzxUr2WA/giphy.gif'
|
|
|
|
|
|
|
| 748 |
<div style='text-align: left;'>
|
| 749 |
<h1 style='color:Black; font-size: 36px; margin-bottom: 6px;'>🎓 AI Career Exploration Assistant</h1>
|
| 750 |
-
<p style='font-size: 18px; font-weight:bold; color:#3b82f6; margin-top: 0;margin-left:
|
|
|
|
|
|
|
| 751 |
</div>
|
| 752 |
</div>
|
| 753 |
""")
|
|
@@ -819,4 +807,3 @@ footer {
|
|
| 819 |
|
| 820 |
demo.load(auto_first, outputs=chatbot)
|
| 821 |
demo.launch()
|
| 822 |
-
|
|
|
|
| 72 |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 73 |
def answer_abc_questions(selected, bg_info, wv, ps, dd):
|
| 74 |
"""
|
| 75 |
+
动态地向OpenAI发起请求,让AI针对“专业/选课方向 & 求职入门(A)”、“本校资源利用(B)”、“实习 & networking(C)”
|
| 76 |
+
三个模块,基于用户背景信息做个性化分析。
|
|
|
|
|
|
|
|
|
|
| 77 |
"""
|
|
|
|
| 78 |
desired_parts = []
|
|
|
|
| 79 |
if "a" in selected:
|
| 80 |
desired_parts.append("A")
|
| 81 |
if "b" in selected:
|
|
|
|
| 83 |
if "c" in selected:
|
| 84 |
desired_parts.append("C")
|
| 85 |
|
|
|
|
| 86 |
if not desired_parts:
|
| 87 |
return "好的,你暂时不需要查看A/B/C的专项信息。"
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
prompt_text = f"""
|
| 90 |
你是一位专业的职业规划顾问。以下是学生背景信息,请根据他选择的模块(A/B/C)给出详细分析和建议。
|
| 91 |
学生背景:
|
|
|
|
| 94 |
- 性格: {ps}
|
| 95 |
- 理想工作: {dd}
|
| 96 |
|
| 97 |
+
学生目前想要的额外信息模块:{', '.join(desired_parts)}
|
| 98 |
+
|
| 99 |
+
请分别按顺序为每个模块写一段分析和建议,可以使用Markdown分段形式。
|
| 100 |
+
(A: 专业/选课方向 & 求职入门建议部分的回答请根据学生的学术背景信息分析学生已经有的能力,然后根据其选择的职业方向分析该学生未来的选课应该注重什么课程方向,提示学生课程名称和关键词)
|
| 101 |
+
(‘B: 本校资源利用建议‘部分的回答请你从3个方面回答学生,包括1.如何利用学生所在学校的career service的指导;2.如何关注学校与职业准备和证书考试相关的club、组织和平台;3.学生如何与学校的及其所在专业的校友取得联系和networking技巧)
|
| 102 |
+
(‘C: 实习 & Experience积累’部分的回答请你从申请internship的平台、达成目前职业目标需要的internship方向,申请需要的资料和准备技巧、通过networking获得实习或者学生工作经历的策略)
|
| 103 |
+
|
| 104 |
模块说明:
|
| 105 |
A: 专业和选课方向 & 求职入门建议
|
| 106 |
B: 本校资源利用建议(如Career Center、校友资源)
|
|
|
|
| 108 |
|
| 109 |
请只回答用户所选模块,不要回答未选的模块。
|
| 110 |
"""
|
|
|
|
| 111 |
try:
|
| 112 |
api_key = os.environ.get("API_TOKEN")
|
| 113 |
if not api_key:
|
|
|
|
| 257 |
top_p=top_p_default,
|
| 258 |
stream=False
|
| 259 |
)
|
|
|
|
| 260 |
output_text = resp.choices[0].message.content
|
| 261 |
|
| 262 |
# 这里可以固定或基于返回文本做解析,我这边演示先手动赋值。
|
|
|
|
| 424 |
global roadmap_offered, roadmap_done
|
| 425 |
|
| 426 |
global direction_chosen, jobs_recommended, job_chosen
|
|
|
|
| 427 |
global post_career_detail_asked, post_career_detail_done
|
| 428 |
|
| 429 |
# ======================== 初始化 =========================
|
|
|
|
| 448 |
direction_chosen = False
|
| 449 |
jobs_recommended = False
|
| 450 |
job_chosen = False
|
|
|
|
|
|
|
| 451 |
post_career_detail_asked = False
|
| 452 |
post_career_detail_done = False
|
| 453 |
|
|
|
|
| 561 |
|
| 562 |
# 已选定大方向 -> 推荐了3个具体职业
|
| 563 |
elif direction_chosen and not jobs_recommended and not job_chosen:
|
|
|
|
| 564 |
choice = message.strip().lower()
|
| 565 |
if choice in ["1","2","3"]:
|
| 566 |
idx = int(choice) - 1
|
|
|
|
| 580 |
forward_deep_dive_done = True
|
| 581 |
|
| 582 |
# 关键:现在我们“询问 A/B/C”
|
| 583 |
+
global post_career_detail_asked
|
| 584 |
post_career_detail_asked = True
|
| 585 |
|
| 586 |
return detail_msg + "\n\n我还可以针对以下三方面提供**更深入**的分析建议:" \
|
|
|
|
| 609 |
else:
|
| 610 |
return "请回复1/2/3选择具体职业,或输入'换'来重新推荐"
|
| 611 |
|
| 612 |
+
# ============== 处理 A/B/C答疑 ==============
|
| 613 |
elif post_career_detail_asked and not post_career_detail_done:
|
| 614 |
user_choice = message.strip().lower()
|
| 615 |
if user_choice in ["不需要", "no", "n"]:
|
|
|
|
| 724 |
display: none !important;
|
| 725 |
}
|
| 726 |
""") as demo:
|
| 727 |
+
# 可以在这里加一个带Row的顶部区域
|
| 728 |
+
with gr.Row():
|
| 729 |
gr.HTML("""
|
| 730 |
<div style='display: flex; align-items: center; justify-content: center; gap: 20px; margin-bottom: 10px;'>
|
| 731 |
+
<img src='https://media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExMmFucGwxbmNsd3J5NXV0Y282NXNtMzNsZW5jMm4wNWh6c2dqbXIwdiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/l41m18LjqpzxUr2WA/giphy.gif'
|
| 732 |
+
width='200'
|
| 733 |
+
style='border-radius: 12px; box-shadow: 0 0 10px #3b82f6;'>
|
| 734 |
<div style='text-align: left;'>
|
| 735 |
<h1 style='color:Black; font-size: 36px; margin-bottom: 6px;'>🎓 AI Career Exploration Assistant</h1>
|
| 736 |
+
<p style='font-size: 18px; font-weight:bold; color:#3b82f6; margin-top: 0; margin-left:150px'>
|
| 737 |
+
Hi! Let's Make the Dream Come True 💙
|
| 738 |
+
</p>
|
| 739 |
</div>
|
| 740 |
</div>
|
| 741 |
""")
|
|
|
|
| 807 |
|
| 808 |
demo.load(auto_first, outputs=chatbot)
|
| 809 |
demo.launch()
|
|
|