Manyue-DataScientist commited on
Commit
efc4ecf
·
verified ·
1 Parent(s): c1d307a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -114
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
- def extract_key_requirements(text: str) -> Dict[str, List[str]]:
14
- """Extract key requirements from text"""
15
- text_lower = text.lower()
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- categories = {
18
- 'technical_skills': [
19
- 'python', 'machine learning', 'deep learning', 'nlp', 'neural networks',
20
- 'data science', 'sql', 'tensorflow', 'pytorch', 'scikit-learn', 'data analysis'
21
- ],
22
- 'soft_skills': [
23
- 'communication', 'teamwork', 'leadership', 'problem solving', 'analytical',
24
- 'collaborative', 'independent', 'innovative'
25
- ],
26
- 'education': [
27
- 'master', 'phd', 'bachelor', 'degree', 'computer science', 'statistics',
28
- 'mathematics', 'post graduate', 'certification'
29
- ],
30
- 'experience': [
31
- 'year', 'experience', 'background', 'industry', 'startup', 'enterprise'
32
- ]
33
- }
34
 
35
- found = {category: [] for category in categories}
36
- for category, keywords in categories.items():
37
- for keyword in keywords:
38
- if keyword in text_lower:
39
- found[category].append(keyword)
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- return found
42
-
43
- def analyze_profile_match(requirements: Dict[str, List[str]], knowledge_base: dict) -> Dict[str, Any]:
44
- """Analyze how well the profile matches requirements"""
45
- my_skills = set(s.lower() for s in knowledge_base['skills']['technical_skills'])
46
- my_soft_skills = set(s.lower() for s in knowledge_base['skills']['soft_skills'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- # Match technical skills
49
- matching_tech_skills = [skill for skill in requirements['technical_skills']
50
- if any(my_skill in skill or skill in my_skill
51
- for my_skill in my_skills)]
52
 
53
- # Match soft skills
54
- matching_soft_skills = [skill for skill in requirements['soft_skills']
55
- if any(my_skill in skill or skill in my_skill
56
- for my_skill in my_soft_skills)]
 
 
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 ' '.join(requirements['technical_skills']) for skill in project_skills):
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
- 'matching_tech_skills': matching_tech_skills,
73
- 'matching_soft_skills': matching_soft_skills,
74
  'relevant_projects': relevant_projects[:2],
75
- 'education_matches': education_matches,
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
- if len(query.split()) > 20 or any(phrase in query_lower for phrase in
85
  ['requirements', 'qualifications', 'looking for', 'job description', 'responsibilities']):
 
86
 
87
- requirements = extract_key_requirements(query)
88
- match_analysis = analyze_profile_match(requirements, knowledge_base)
89
-
90
- response_parts = []
91
-
92
- # Start with unique background if it's an ML role
93
- if any(skill in query_lower for skill in ['machine learning', 'ml', 'ai', 'data science']):
94
- transition_story = match_analysis['background_story']
95
- response_parts.append(f"With my unique transition from commerce to ML/AI, {transition_story[:200]}...")
96
-
97
- # Add technical alignment
98
- if match_analysis['matching_tech_skills']:
99
- response_parts.append(f"I have hands-on experience with key technical requirements including {', '.join(match_analysis['matching_tech_skills'])}.")
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
- tech_skills = knowledge_base['skills']['technical_skills']
140
- projects = knowledge_base['professional_experience']['projects']
141
-
142
- return f"My core technical stack includes {', '.join(tech_skills[:5])}. I've applied these skills in real-world projects like my {projects[0]['name']}, which {projects[0]['description']}. I'm currently enhancing my ML expertise through advanced studies in Canada and practical project implementation."
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']}, a Machine Learning Engineer candidate with a unique background in commerce and technology. {knowledge_base['personal_details']['professional_summary']}"
 
 
 
 
 
 
 
152
 
153
  # Load and cache knowledge base
154
  @st.cache_data
155
  def load_knowledge_base():
156
  try:
157
- with open('knowledge_base.json', 'r', encoding='utf-8') as f:
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.")