Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- utils/utils/api_clients.py +24 -0
- utils/utils/constants.py +11 -0
- utils/utils/data_helpers.py +174 -0
- utils/utils/embedding_model.py +5 -0
- utils/utils/summarizer.py +5 -0
utils/utils/api_clients.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from openai import OpenAI
|
3 |
+
from pinecone import Pinecone
|
4 |
+
|
5 |
+
|
6 |
+
def initialize_api_clients():
|
7 |
+
pc = Pinecone(api_key=os.getenv("PINECONE_API_KEY"))
|
8 |
+
pine_index = pc.Index("career-buddy-memo")
|
9 |
+
APIFY_TOKEN = os.environ.get("APIFY_TOKEN")
|
10 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
|
11 |
+
TAVILY_API_KEY = os.getenv("TAVILY_API_KEY", "")
|
12 |
+
client = OpenAI(api_key=OPENAI_API_KEY)
|
13 |
+
|
14 |
+
return pc, pine_index, APIFY_TOKEN, OPENAI_API_KEY, TAVILY_API_KEY, client
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
def unload_model(model):
|
19 |
+
# This is a placeholder for actual model unloading logic
|
20 |
+
# In a real scenario, this would depend on the specific model and framework
|
21 |
+
print(f"[DEBUG] Unloading model: {model}")
|
22 |
+
del model
|
23 |
+
|
24 |
+
|
utils/utils/constants.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
TASK_DIFFICULTIES = ["Simple", "Moderate", "Challenging"]
|
2 |
+
TASK_TAGS = ["Critical π΄", "Important π ", "Optional π’"]
|
3 |
+
reward_pool = ["Ice Cream π¦", "Watch Party π¬", "Spa Day πββοΈ"]
|
4 |
+
task_data, claimed_rewards, available_rewards = [], [], []
|
5 |
+
memo_data = []
|
6 |
+
completed_tasks = set()
|
7 |
+
completed_steps_box = set ()
|
8 |
+
|
9 |
+
visual_steps = []
|
10 |
+
last_reset = datetime.date.today()
|
11 |
+
|
utils/utils/data_helpers.py
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
import datetime
|
3 |
+
import difflib
|
4 |
+
from utils.constants import memo_data, task_data, completed_tasks
|
5 |
+
|
6 |
+
def smart_label_converter(step_label):
|
7 |
+
if step_label.lower().startswith("milestone:"):
|
8 |
+
return "π― Build: " + step_label[len("milestone:"):].strip()
|
9 |
+
elif step_label.lower().startswith("action:"):
|
10 |
+
return "π Research: " + step_label[len("action:"):].strip()
|
11 |
+
elif step_label.lower().startswith("resource:"):
|
12 |
+
return "π Learn: " + step_label[len("resource:"):].strip()
|
13 |
+
else:
|
14 |
+
return step_label
|
15 |
+
|
16 |
+
def extract_actions_from_feedback(feedback_text, source="AI"):
|
17 |
+
sentences = re.split(r'[.?!]\s+', feedback_text)
|
18 |
+
actions = []
|
19 |
+
|
20 |
+
for sentence in sentences:
|
21 |
+
lower = sentence.lower()
|
22 |
+
if any(kw in lower for kw in ["fix", "add", "update", "change", "optimize", "remove", "improve", "include", "enhance", "refactor"]):
|
23 |
+
cleaned = sentence.strip("β’- ").strip().capitalize()
|
24 |
+
if cleaned:
|
25 |
+
actions.append({"type": "Action", "text": cleaned, "source": source})
|
26 |
+
|
27 |
+
return actions
|
28 |
+
|
29 |
+
def render_memo():
|
30 |
+
if not memo_data:
|
31 |
+
return "π No roadmap data yet."
|
32 |
+
|
33 |
+
grouped = {"Milestone": [], "Resource": [], "Action": []}
|
34 |
+
for item in memo_data:
|
35 |
+
grouped[item["type"]].append(item)
|
36 |
+
|
37 |
+
output = ""
|
38 |
+
if grouped["Milestone"]:
|
39 |
+
output += "### π― Milestones\n"
|
40 |
+
for m in grouped["Milestone"]:
|
41 |
+
output += f"- {m['text']}\n"
|
42 |
+
|
43 |
+
if grouped["Resource"]:
|
44 |
+
output += "\n### π Resources\n"
|
45 |
+
for r in grouped["Resource"]:
|
46 |
+
output += f"- {r['text']}\n"
|
47 |
+
|
48 |
+
if grouped["Action"]:
|
49 |
+
output += "\n### π Actions\n"
|
50 |
+
for a in grouped["Action"]:
|
51 |
+
output += f"- {a['text']} \n π [Add to Tasks]\n"
|
52 |
+
|
53 |
+
return output
|
54 |
+
|
55 |
+
def convert_actions_to_tasks():
|
56 |
+
added = 0
|
57 |
+
for item in memo_data:
|
58 |
+
if item["type"] == "Action":
|
59 |
+
task_data.append({
|
60 |
+
"Task": item["text"],
|
61 |
+
"Duration": 1,
|
62 |
+
"Difficulty": "Simple",
|
63 |
+
"Tag": "Important π ",
|
64 |
+
"Points": 10
|
65 |
+
})
|
66 |
+
added += 1
|
67 |
+
# Assuming display_tasks() is a Gradio component update, it will be handled in app.py
|
68 |
+
return "Tasks converted!"
|
69 |
+
|
70 |
+
course_suggestions = {
|
71 |
+
"data analyst": [
|
72 |
+
("Google Data Analytics Professional Certificate", "https://www.coursera.org/professional-certificates/google-data-analytics"),
|
73 |
+
("IBM Data Analyst Professional Certificate", "https://www.coursera.org/professional-certificates/ibm-data-analyst"),
|
74 |
+
("Introduction to Data Analytics by IBM", "https://www.coursera.org/learn/introduction-to-data-analytics"),
|
75 |
+
("Excel Basics for Data Analysis by IBM", "https://www.coursera.org/learn/excel-basics-data-analysis"),
|
76 |
+
("Data Analysis using Excel and Tableau by EntryLevel", "https://www.entrylevel.net/post/beginner-data-analysis-courses-by-platform-with-certificates")
|
77 |
+
],
|
78 |
+
"ux designer": [
|
79 |
+
("Google UX Design Professional Certificate", "https://www.coursera.org/professional-certificates/google-ux-design"),
|
80 |
+
("Introduction to UI and UX Design by Codecademy", "https://www.codecademy.com/learn/intro-to-ui-ux"),
|
81 |
+
("UX Design Institute's Introduction to UX Design", "https://www.uxdesigninstitute.com/blog/best-free-ux-design-courses-in-2022/"),
|
82 |
+
("Introduction to User Experience Design by Georgia Tech", "https://www.coursera.org/learn/user-experience-design"),
|
83 |
+
("CareerFoundry UX Design Program", "https://careerfoundry.com/en/blog/ux-design/ux-design-course-online/")
|
84 |
+
],
|
85 |
+
"software engineer": [
|
86 |
+
("Introduction to Software Engineering by IBM", "https://www.coursera.org/learn/introduction-to-software-engineering"),
|
87 |
+
("Python for Everybody Specialization by University of Michigan", "https://www.coursera.org/specializations/python"),
|
88 |
+
("Full-Stack Engineer Career Path by Codecademy", "https://www.codecademy.com/learn/paths/full-stack-engineer-career-path"),
|
89 |
+
("Software Engineering for Beginners by Udemy", "https://www.udemy.com/course/software-engineering-for-beginners/"),
|
90 |
+
("Software Engineering Bootcamp by TripleTen", "https://tripleten.com/software-engineer/")
|
91 |
+
],
|
92 |
+
"digital marketing": [
|
93 |
+
("Fundamentals of Digital Marketing by Google Digital Garage", "https://learndigital.withgoogle.com/digitalgarage/course/digital-marketing"),
|
94 |
+
("Digital Marketing Specialization by Coursera", "https://www.coursera.org/specializations/digital-marketing"),
|
95 |
+
("The Complete Digital Marketing Course by Udemy", "https://www.udemy.com/course/learn-digital-marketing-course/"),
|
96 |
+
("Digital Marketing Fundamentals by University of Edinburgh on edX", "https://www.edx.org/course/digital-marketing-fundamentals"),
|
97 |
+
("Digital Marketing Course by CareerFoundry", "https://careerfoundry.com/en/blog/digital-marketing/online-digital-marketing-courses/")
|
98 |
+
],
|
99 |
+
"project manager": [
|
100 |
+
("Google Project Management Professional Certificate", "https://www.coursera.org/professional-certificates/google-project-management"),
|
101 |
+
("Foundations of Project Management by Coursera", "https://www.coursera.org/learn/project-management-foundations"),
|
102 |
+
("Project Management Basics by PMI", "https://www.pmi.org/learning/free-online-courses"),
|
103 |
+
("Introduction to Project Management by University of Adelaide on edX", "https://www.edx.org/course/introduction-to-project-management"),
|
104 |
+
("Project Management Principles and Practices Specialization by Coursera", "https://www.coursera.org/specializations/project-management")
|
105 |
+
]
|
106 |
+
}
|
107 |
+
|
108 |
+
def get_courses_for_goal(goal_key):
|
109 |
+
if goal_key not in course_suggestions:
|
110 |
+
match = difflib.get_close_matches(goal_key, course_suggestions.keys(), n=1, cutoff=0.6)
|
111 |
+
if match:
|
112 |
+
goal_key = match[0]
|
113 |
+
return course_suggestions.get(goal_key, [])
|
114 |
+
|
115 |
+
class RoadmapUnlockManager:
|
116 |
+
def __init__(self):
|
117 |
+
self.weekly_steps = {}
|
118 |
+
self.current_week = "Week 1"
|
119 |
+
self.completed_tasks = set()
|
120 |
+
|
121 |
+
def load_steps(self, steps: list[str]):
|
122 |
+
self.weekly_steps = {}
|
123 |
+
current_label = None
|
124 |
+
|
125 |
+
for step in steps:
|
126 |
+
stripped = step.strip().strip("*")
|
127 |
+
if stripped.lower().startswith("week"):
|
128 |
+
current_label = stripped.split(":")[0].strip()
|
129 |
+
self.weekly_steps[current_label] = []
|
130 |
+
elif current_label:
|
131 |
+
self.weekly_steps[current_label].append(stripped)
|
132 |
+
|
133 |
+
self.current_week = list(self.weekly_steps.keys())[0] if self.weekly_steps else "Week 1"
|
134 |
+
self.completed_tasks.clear()
|
135 |
+
|
136 |
+
def get_current_choices(self):
|
137 |
+
return [
|
138 |
+
s for s in self.weekly_steps.get(self.current_week, [])
|
139 |
+
if not s.lower().startswith("week") and not s.startswith("**")
|
140 |
+
]
|
141 |
+
|
142 |
+
def get_current_week_title(self):
|
143 |
+
return f"**π
Current Focus: {self.current_week}**"
|
144 |
+
|
145 |
+
def update_completion(self, selected):
|
146 |
+
self.completed_tasks.update(selected)
|
147 |
+
all_current = set(self.get_current_choices())
|
148 |
+
if all_current.issubset(self.completed_tasks):
|
149 |
+
return self._unlock_next_week()
|
150 |
+
return f"β
Progress: {len(self.completed_tasks)}/{len(all_current)}"
|
151 |
+
|
152 |
+
def _unlock_next_week(self):
|
153 |
+
weeks = list(self.weekly_steps.keys())
|
154 |
+
current_index = weeks.index(self.current_week)
|
155 |
+
if current_index + 1 < len(weeks):
|
156 |
+
self.current_week = weeks[current_index + 1]
|
157 |
+
self.completed_tasks.clear()
|
158 |
+
return f"π All tasks done! Unlocked: {self.current_week}"
|
159 |
+
return "β
All weeks completed!"
|
160 |
+
|
161 |
+
def greet_user(uid, goal):
|
162 |
+
feedback = f"β
Welcome back, **{uid}**!"
|
163 |
+
# Assuming recall_from_memory will be moved to memo.py or a separate data handling module
|
164 |
+
# For now, keep it as a placeholder or import if already moved
|
165 |
+
# recalled = recall_from_memory(uid, goal)
|
166 |
+
return feedback #, recalled
|
167 |
+
|
168 |
+
def clean_text(text):
|
169 |
+
if not isinstance(text, str):
|
170 |
+
return ""
|
171 |
+
text = text.encode('utf-8', 'ignore').decode('utf-8', 'ignore')
|
172 |
+
text = re.sub(r'[^\x00-\x7F]+', '', text)
|
173 |
+
return text.strip()
|
174 |
+
|
utils/utils/embedding_model.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
2 |
+
|
3 |
+
def initialize_embedding_model():
|
4 |
+
return HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
5 |
+
|
utils/utils/summarizer.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
def initialize_summarizer():
|
4 |
+
return pipeline("summarization", model="facebook/bart-large-cnn")
|
5 |
+
|