Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import json
|
3 |
from typing import Dict, List, Any
|
4 |
-
import re
|
5 |
|
6 |
# Initialize Streamlit page configuration
|
7 |
st.set_page_config(
|
@@ -10,151 +9,177 @@ st.set_page_config(
|
|
10 |
layout="wide"
|
11 |
)
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
'mathematics', 'post graduate', 'certification'
|
29 |
-
],
|
30 |
-
'experience': [
|
31 |
-
'year', 'experience', 'background', 'industry', 'startup', 'enterprise'
|
32 |
-
]
|
33 |
-
}
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
#
|
49 |
-
|
50 |
-
if any(my_skill in skill or skill in my_skill
|
51 |
-
for my_skill in my_skills)]
|
52 |
|
53 |
-
#
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# Find relevant projects
|
59 |
relevant_projects = []
|
60 |
for project in knowledge_base['professional_experience']['projects']:
|
61 |
project_skills = set(s.lower() for s in project['skills_used'])
|
62 |
-
if any(skill in
|
63 |
relevant_projects.append(project)
|
64 |
-
|
65 |
-
# Check education match
|
66 |
-
education_matches = []
|
67 |
-
for edu in knowledge_base['education']['postgraduate']:
|
68 |
-
if any(req in edu['course_name'].lower() for req in requirements['education']):
|
69 |
-
education_matches.append(edu)
|
70 |
-
|
71 |
return {
|
72 |
-
'
|
73 |
-
'matching_soft_skills': matching_soft_skills,
|
74 |
'relevant_projects': relevant_projects[:2],
|
75 |
-
'
|
76 |
-
'background_story': knowledge_base['frequently_asked_questions'][0]['answer'] # Transition story
|
77 |
}
|
78 |
|
79 |
def generate_response(query: str, knowledge_base: dict) -> str:
|
80 |
"""Generate enhanced responses using the knowledge base"""
|
81 |
query_lower = query.lower()
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# Handle job descriptions or role requirements
|
84 |
-
|
85 |
['requirements', 'qualifications', 'looking for', 'job description', 'responsibilities']):
|
|
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
# Highlight relevant project
|
102 |
-
if match_analysis['relevant_projects']:
|
103 |
-
project = match_analysis['relevant_projects'][0]
|
104 |
-
response_parts.append(f"My project '{project['name']}' demonstrates my capabilities as {project['description']}")
|
105 |
-
|
106 |
-
# Add education and Canadian context
|
107 |
-
response_parts.append("I'm completing advanced AI/ML education in Canada through Georgian College and George Brown College, gaining cutting-edge knowledge in ML engineering and practical implementation.")
|
108 |
-
|
109 |
-
# Add forward-looking statement
|
110 |
-
response_parts.append("I'm actively expanding my ML expertise through hands-on projects and am ready to contribute to innovative ML solutions in the Canadian tech industry.")
|
111 |
-
|
112 |
-
return ' '.join(response_parts)
|
113 |
-
|
114 |
-
# Handle specific company/role queries
|
115 |
-
elif any(word in query_lower for word in ['role', 'fit', 'job', 'position', 'company']):
|
116 |
-
company_name = None
|
117 |
-
words = query.split()
|
118 |
-
for word in words:
|
119 |
-
if word[0].isupper() and word.lower() not in ['i', 'ml', 'ai', 'nlp']:
|
120 |
-
company_name = word
|
121 |
-
break
|
122 |
-
|
123 |
-
projects = knowledge_base['professional_experience']['projects']
|
124 |
-
skills = knowledge_base['skills']['technical_skills']
|
125 |
-
goals = knowledge_base['goals_and_aspirations']['short_term']
|
126 |
-
|
127 |
-
response = [
|
128 |
-
f"{'As a candidate for ' + company_name if company_name else 'As an ML engineer candidate'}, I bring a unique combination of technical expertise and business understanding from my commerce background.",
|
129 |
-
f"My strongest project is my {projects[0]['name']}, where {projects[0]['description']}",
|
130 |
-
f"I've developed expertise in {', '.join(skills[:3])}, applying these skills in real-world projects.",
|
131 |
-
"With my Canadian AI/ML education and practical project experience, I'm well-prepared to contribute to innovative ML solutions.",
|
132 |
-
f"I'm actively {goals[0].lower()} and expanding my portfolio with industry-relevant projects."
|
133 |
-
]
|
134 |
-
|
135 |
-
return ' '.join(response)
|
136 |
|
137 |
# Handle specific skill queries
|
138 |
elif any(word in query_lower for word in ['skill', 'know', 'experience', 'expert']):
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
# Handle background/journey queries
|
145 |
-
elif any(word in query_lower for word in ['background', 'journey', 'story']):
|
146 |
-
transition = next((qa['answer'] for qa in knowledge_base['frequently_asked_questions']
|
147 |
-
if 'transition' in qa['question'].lower()), '')
|
148 |
-
return f"{transition[:300]}... This unique journey gives me both technical expertise and business understanding, valuable for ML engineering roles."
|
149 |
|
150 |
# Default response
|
151 |
-
return f"I'm {knowledge_base['personal_details']['full_name']},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
# Load and cache knowledge base
|
154 |
@st.cache_data
|
155 |
def load_knowledge_base():
|
156 |
try:
|
157 |
-
with open('
|
158 |
return json.load(f)
|
159 |
except FileNotFoundError:
|
160 |
st.error("Knowledge base file not found.")
|
|
|
1 |
import streamlit as st
|
2 |
import json
|
3 |
from typing import Dict, List, Any
|
|
|
4 |
|
5 |
# Initialize Streamlit page configuration
|
6 |
st.set_page_config(
|
|
|
9 |
layout="wide"
|
10 |
)
|
11 |
|
12 |
+
# Helper functions for formatting responses
|
13 |
+
def get_project_details(project: dict) -> str:
|
14 |
+
"""Format project details in a clear, structured way"""
|
15 |
+
return (
|
16 |
+
f"• {project['name']}\n"
|
17 |
+
f" Description: {project['description']}\n"
|
18 |
+
f" Skills: {', '.join(project['skills_used'])}\n"
|
19 |
+
f" Status: {project['status']}"
|
20 |
+
)
|
21 |
+
|
22 |
+
def get_skills_by_category(knowledge_base: dict) -> Dict[str, List[str]]:
|
23 |
+
"""Organize skills by category with examples"""
|
24 |
+
skills = knowledge_base['skills']
|
25 |
+
projects = knowledge_base['professional_experience']['projects']
|
26 |
|
27 |
+
skill_examples = {}
|
28 |
+
for skill in skills['technical_skills']:
|
29 |
+
related_projects = [p['name'] for p in projects
|
30 |
+
if skill.lower() in [s.lower() for s in p['skills_used']]]
|
31 |
+
if related_projects:
|
32 |
+
skill_examples[skill] = related_projects[0]
|
33 |
+
return skill_examples
|
34 |
+
|
35 |
+
def format_story_response(knowledge_base: dict) -> str:
|
36 |
+
"""Format the background story in a clear, structured way"""
|
37 |
+
education = knowledge_base['education']
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
story = [
|
40 |
+
"Here's my journey from commerce to ML/AI:",
|
41 |
+
"• Education Background:",
|
42 |
+
f" - Graduated with a Commerce degree from {education['Undergraduate'][0]['institution']}",
|
43 |
+
"• Career Transition:",
|
44 |
+
" - Started as a Programmer Trainee at Cognizant despite no prior coding experience",
|
45 |
+
" - Excelled in development roles and discovered passion for technology",
|
46 |
+
"• Current Path:",
|
47 |
+
f" - Pursuing {education['postgraduate'][0]['course_name']} at {education['postgraduate'][0]['institution']}",
|
48 |
+
f" - Also enrolled in {education['postgraduate'][1]['course_name']} at {education['postgraduate'][1]['institution']}",
|
49 |
+
"• Goal:",
|
50 |
+
" - Combining business acumen with ML/AI expertise to create impactful solutions"
|
51 |
+
]
|
52 |
+
return '\n'.join(story)
|
53 |
+
|
54 |
+
def format_project_list(knowledge_base: dict) -> str:
|
55 |
+
"""Format project list in a clear, structured way"""
|
56 |
+
projects = knowledge_base['professional_experience']['projects']
|
57 |
|
58 |
+
response = ["My Portfolio Projects:"]
|
59 |
+
for project in projects:
|
60 |
+
response.extend([
|
61 |
+
f"\n{project['name']}",
|
62 |
+
f"• Description: {project['description']}",
|
63 |
+
f"• Technologies: {', '.join(project['skills_used'])}",
|
64 |
+
f"• Current Status: {project['status']}",
|
65 |
+
"---"
|
66 |
+
])
|
67 |
+
return '\n'.join(response)
|
68 |
+
|
69 |
+
def format_standout_qualities(knowledge_base: dict) -> str:
|
70 |
+
"""Format standout qualities in a clear, structured way"""
|
71 |
+
qualities = [
|
72 |
+
"What Makes Me Stand Out:",
|
73 |
+
"\n1. Unique Background",
|
74 |
+
" • Successfully transitioned from commerce to tech",
|
75 |
+
" • Bring both business acumen and technical expertise",
|
76 |
+
"\n2. Practical Experience",
|
77 |
+
f" • Developed {len(knowledge_base['professional_experience']['projects'])} significant ML projects",
|
78 |
+
" • Real-world implementation experience from Cognizant",
|
79 |
+
"\n3. Canadian Education",
|
80 |
+
" • Advanced AI/ML education in Canada",
|
81 |
+
" • Up-to-date with latest industry practices",
|
82 |
+
"\n4. Technical Expertise",
|
83 |
+
f" • Strong foundation in {', '.join(knowledge_base['skills']['technical_skills'][:3])}",
|
84 |
+
" • Hands-on experience with ML model deployment",
|
85 |
+
"\n5. Business Perspective",
|
86 |
+
" • Understanding of both technical and business requirements",
|
87 |
+
" • Can bridge gap between technical and business teams"
|
88 |
+
]
|
89 |
+
return '\n'.join(qualities)
|
90 |
+
|
91 |
+
def analyze_job_description(text: str, knowledge_base: dict) -> dict:
|
92 |
+
"""Analyze job description and match with candidate's profile"""
|
93 |
+
text_lower = text.lower()
|
94 |
|
95 |
+
# Extract key skills from knowledge base
|
96 |
+
my_skills = set(s.lower() for s in knowledge_base['skills']['technical_skills'])
|
|
|
|
|
97 |
|
98 |
+
# Common ML/AI job related keywords
|
99 |
+
ml_keywords = {
|
100 |
+
'machine learning', 'deep learning', 'artificial intelligence', 'ai', 'ml',
|
101 |
+
'neural networks', 'nlp', 'computer vision', 'data science',
|
102 |
+
'python', 'pytorch', 'tensorflow', 'scikit-learn'
|
103 |
+
}
|
104 |
|
105 |
+
# Find mentioned skills in JD
|
106 |
+
found_skills = []
|
107 |
+
for skill in my_skills:
|
108 |
+
if skill in text_lower:
|
109 |
+
found_skills.append(skill)
|
110 |
+
|
111 |
# Find relevant projects
|
112 |
relevant_projects = []
|
113 |
for project in knowledge_base['professional_experience']['projects']:
|
114 |
project_skills = set(s.lower() for s in project['skills_used'])
|
115 |
+
if any(skill in text_lower for skill in project_skills):
|
116 |
relevant_projects.append(project)
|
117 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
return {
|
119 |
+
'matching_skills': found_skills,
|
|
|
120 |
'relevant_projects': relevant_projects[:2],
|
121 |
+
'is_ml_role': any(keyword in text_lower for keyword in ml_keywords)
|
|
|
122 |
}
|
123 |
|
124 |
def generate_response(query: str, knowledge_base: dict) -> str:
|
125 |
"""Generate enhanced responses using the knowledge base"""
|
126 |
query_lower = query.lower()
|
127 |
|
128 |
+
# Handle project listing requests
|
129 |
+
if any(word in query_lower for word in ['list', 'project', 'portfolio', 'built', 'created', 'developed']):
|
130 |
+
return format_project_list(knowledge_base)
|
131 |
+
|
132 |
+
# Handle background/journey queries
|
133 |
+
elif any(word in query_lower for word in ['background', 'journey', 'story', 'transition']):
|
134 |
+
return format_story_response(knowledge_base)
|
135 |
+
|
136 |
+
# Handle standout/unique qualities queries
|
137 |
+
elif any(word in query_lower for word in ['stand out', 'unique', 'different', 'special']):
|
138 |
+
return format_standout_qualities(knowledge_base)
|
139 |
+
|
140 |
# Handle job descriptions or role requirements
|
141 |
+
elif len(query.split()) > 20 or any(phrase in query_lower for phrase in
|
142 |
['requirements', 'qualifications', 'looking for', 'job description', 'responsibilities']):
|
143 |
+
analysis = analyze_job_description(query, knowledge_base)
|
144 |
|
145 |
+
if analysis['is_ml_role']:
|
146 |
+
response_parts = []
|
147 |
+
response_parts.append("Based on the job description, here's how my profile aligns:")
|
148 |
+
|
149 |
+
if analysis['matching_skills']:
|
150 |
+
response_parts.append(f"\n• Technical Skills Match:\n - I have experience with: {', '.join(analysis['matching_skills'])}")
|
151 |
+
|
152 |
+
if analysis['relevant_projects']:
|
153 |
+
project = analysis['relevant_projects'][0]
|
154 |
+
response_parts.append(f"\n• Relevant Project Experience:\n - {project['name']}: {project['description']}")
|
155 |
+
|
156 |
+
response_parts.append("\n• Additional Qualifications:\n - Advanced AI/ML education in Canada\n - Unique background combining business and technical expertise")
|
157 |
+
|
158 |
+
return '\n'.join(response_parts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
# Handle specific skill queries
|
161 |
elif any(word in query_lower for word in ['skill', 'know', 'experience', 'expert']):
|
162 |
+
skill_examples = get_skills_by_category(knowledge_base)
|
163 |
+
response = ["My Technical Skills:"]
|
164 |
+
for skill, project in skill_examples.items():
|
165 |
+
response.append(f"• {skill} - Applied in {project}")
|
166 |
+
return '\n'.join(response)
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
# Default response
|
169 |
+
return (f"I'm {knowledge_base['personal_details']['full_name']}, "
|
170 |
+
f"{knowledge_base['personal_details']['professional_summary']}\n\n"
|
171 |
+
"You can ask me about:\n"
|
172 |
+
"• My projects and portfolio\n"
|
173 |
+
"• My journey from commerce to ML/AI\n"
|
174 |
+
"• My technical skills and experience\n"
|
175 |
+
"• My fit for ML/AI roles\n"
|
176 |
+
"Or paste a job description to see how my profile matches!")
|
177 |
|
178 |
# Load and cache knowledge base
|
179 |
@st.cache_data
|
180 |
def load_knowledge_base():
|
181 |
try:
|
182 |
+
with open('manny_knowledge_base.json', 'r', encoding='utf-8') as f:
|
183 |
return json.load(f)
|
184 |
except FileNotFoundError:
|
185 |
st.error("Knowledge base file not found.")
|