Update app.py
Browse filesLet test changes made on top of a working version
app.py
CHANGED
@@ -20,7 +20,7 @@ def format_project_response(project: dict, indent_level: int = 0) -> str:
|
|
20 |
if 'confidentiality_note' in project:
|
21 |
response.append(f"{indent} Note: {project['confidentiality_note']}")
|
22 |
|
23 |
-
return '\n'.join(response) + '\n'
|
24 |
|
25 |
def format_skills_response(skills: dict) -> str:
|
26 |
"""Format skills with proper hierarchy and spacing"""
|
@@ -98,14 +98,14 @@ def analyze_job_description(text: str, knowledge_base: dict) -> str:
|
|
98 |
my_relevant_skills.append(" - Experienced in building ML models from scratch (demonstrated in algorithm practice projects)")
|
99 |
|
100 |
response_parts.extend(my_relevant_skills)
|
101 |
-
response_parts.append("")
|
102 |
|
103 |
# Business Understanding
|
104 |
response_parts.append("• Business Acumen:")
|
105 |
response_parts.append(" - Commerce background provides strong understanding of business requirements")
|
106 |
response_parts.append(" - Experience in translating business needs into technical solutions")
|
107 |
response_parts.append(" - Proven ability to communicate technical findings to business stakeholders")
|
108 |
-
response_parts.append("")
|
109 |
|
110 |
# Project Experience
|
111 |
response_parts.append("• Relevant Project Experience:")
|
@@ -118,7 +118,7 @@ def analyze_job_description(text: str, knowledge_base: dict) -> str:
|
|
118 |
relevant_projects.append(" - Created multiple ML models from scratch, including predictive analytics for Ola")
|
119 |
|
120 |
response_parts.extend(relevant_projects)
|
121 |
-
response_parts.append("")
|
122 |
|
123 |
# Education and Additional Qualifications
|
124 |
response_parts.append("• Additional Strengths:")
|
@@ -137,20 +137,20 @@ def format_story_response(knowledge_base: dict) -> str:
|
|
137 |
response_parts.append(f" - Commerce degree from {knowledge_base['education']['undergraduate']['institution']}")
|
138 |
response_parts.append(f" - Currently at {knowledge_base['education']['postgraduate'][0]['institution']}")
|
139 |
response_parts.append(f" - Also enrolled at {knowledge_base['education']['postgraduate'][1]['institution']}")
|
140 |
-
response_parts.append("")
|
141 |
|
142 |
# Career Transition
|
143 |
response_parts.append("• Career Transition:")
|
144 |
transition = next((qa['answer'] for qa in knowledge_base['frequently_asked_questions']
|
145 |
if 'transition' in qa['question'].lower()), '')
|
146 |
-
response_parts.append(f" - {transition[:200]}...")
|
147 |
-
response_parts.append("")
|
148 |
|
149 |
# Current Focus
|
150 |
response_parts.append("• Current Focus:")
|
151 |
response_parts.append(" - Building practical ML projects")
|
152 |
response_parts.append(" - Advancing AI/ML education in Canada")
|
153 |
-
response_parts.append("")
|
154 |
|
155 |
# Goals
|
156 |
response_parts.append("• Future Goals:")
|
@@ -160,12 +160,35 @@ def format_story_response(knowledge_base: dict) -> str:
|
|
160 |
|
161 |
return '\n'.join(response_parts)
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
def add_relevant_links(response: str, query: str, knowledge_base: dict) -> str:
|
164 |
"""Add relevant links based on query context"""
|
165 |
query_lower = query.lower()
|
166 |
links = []
|
167 |
|
168 |
-
# Add links strategically based on context
|
169 |
if any(word in query_lower for word in ['project', 'portfolio', 'work']):
|
170 |
links.append(f"\nView my complete portfolio: {knowledge_base['personal_details']['online_presence']['portfolio']}")
|
171 |
|
@@ -182,8 +205,35 @@ def add_relevant_links(response: str, query: str, knowledge_base: dict) -> str:
|
|
182 |
|
183 |
return response
|
184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
def generate_response(query: str, knowledge_base: dict) -> str:
|
186 |
-
"""
|
187 |
query_lower = query.lower()
|
188 |
|
189 |
# Handle project listing requests
|
@@ -218,27 +268,15 @@ def generate_response(query: str, knowledge_base: dict) -> str:
|
|
218 |
|
219 |
# Handle standout/unique qualities queries
|
220 |
elif any(word in query_lower for word in ['stand out', 'unique', 'different', 'special']):
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
response_parts.append("")
|
231 |
-
|
232 |
-
response_parts.append("• Technical Depth:")
|
233 |
-
response_parts.append(" - Strong foundation in ML/AI principles")
|
234 |
-
response_parts.append(" - Experience with end-to-end project implementation")
|
235 |
-
response_parts.append("")
|
236 |
-
|
237 |
-
response_parts.append("• Innovation Focus:")
|
238 |
-
response_parts.append(" - Developing novel solutions in ML/AI")
|
239 |
-
response_parts.append(" - Emphasis on practical impact")
|
240 |
-
|
241 |
-
return '\n'.join(response_parts)
|
242 |
|
243 |
# Default response
|
244 |
return (f"I'm {knowledge_base['personal_details']['professional_summary']}\n\n"
|
@@ -274,8 +312,8 @@ def main():
|
|
274 |
""")
|
275 |
st.session_state.displayed_welcome = True
|
276 |
|
277 |
-
# Create two columns
|
278 |
-
col1, col2 = st.columns([
|
279 |
|
280 |
with col1:
|
281 |
# Display chat messages
|
@@ -300,7 +338,7 @@ def main():
|
|
300 |
st.rerun()
|
301 |
|
302 |
with col2:
|
303 |
-
st.
|
304 |
example_questions = [
|
305 |
"Tell me about your ML projects",
|
306 |
"What are your technical skills?",
|
@@ -310,12 +348,17 @@ def main():
|
|
310 |
]
|
311 |
|
312 |
for question in example_questions:
|
313 |
-
if st.button(question):
|
314 |
st.session_state.messages.append({"role": "user", "content": question})
|
|
|
|
|
|
|
|
|
|
|
315 |
st.rerun()
|
316 |
|
317 |
st.markdown("---")
|
318 |
-
if st.button("Clear Chat"):
|
319 |
st.session_state.messages = []
|
320 |
st.rerun()
|
321 |
|
|
|
20 |
if 'confidentiality_note' in project:
|
21 |
response.append(f"{indent} Note: {project['confidentiality_note']}")
|
22 |
|
23 |
+
return '\n'.join(response) + '\n'
|
24 |
|
25 |
def format_skills_response(skills: dict) -> str:
|
26 |
"""Format skills with proper hierarchy and spacing"""
|
|
|
98 |
my_relevant_skills.append(" - Experienced in building ML models from scratch (demonstrated in algorithm practice projects)")
|
99 |
|
100 |
response_parts.extend(my_relevant_skills)
|
101 |
+
response_parts.append("")
|
102 |
|
103 |
# Business Understanding
|
104 |
response_parts.append("• Business Acumen:")
|
105 |
response_parts.append(" - Commerce background provides strong understanding of business requirements")
|
106 |
response_parts.append(" - Experience in translating business needs into technical solutions")
|
107 |
response_parts.append(" - Proven ability to communicate technical findings to business stakeholders")
|
108 |
+
response_parts.append("")
|
109 |
|
110 |
# Project Experience
|
111 |
response_parts.append("• Relevant Project Experience:")
|
|
|
118 |
relevant_projects.append(" - Created multiple ML models from scratch, including predictive analytics for Ola")
|
119 |
|
120 |
response_parts.extend(relevant_projects)
|
121 |
+
response_parts.append("")
|
122 |
|
123 |
# Education and Additional Qualifications
|
124 |
response_parts.append("• Additional Strengths:")
|
|
|
137 |
response_parts.append(f" - Commerce degree from {knowledge_base['education']['undergraduate']['institution']}")
|
138 |
response_parts.append(f" - Currently at {knowledge_base['education']['postgraduate'][0]['institution']}")
|
139 |
response_parts.append(f" - Also enrolled at {knowledge_base['education']['postgraduate'][1]['institution']}")
|
140 |
+
response_parts.append("")
|
141 |
|
142 |
# Career Transition
|
143 |
response_parts.append("• Career Transition:")
|
144 |
transition = next((qa['answer'] for qa in knowledge_base['frequently_asked_questions']
|
145 |
if 'transition' in qa['question'].lower()), '')
|
146 |
+
response_parts.append(f" - {transition[:200]}...")
|
147 |
+
response_parts.append("")
|
148 |
|
149 |
# Current Focus
|
150 |
response_parts.append("• Current Focus:")
|
151 |
response_parts.append(" - Building practical ML projects")
|
152 |
response_parts.append(" - Advancing AI/ML education in Canada")
|
153 |
+
response_parts.append("")
|
154 |
|
155 |
# Goals
|
156 |
response_parts.append("• Future Goals:")
|
|
|
160 |
|
161 |
return '\n'.join(response_parts)
|
162 |
|
163 |
+
def format_standout_response() -> str:
|
164 |
+
"""Format response about standout qualities"""
|
165 |
+
response_parts = ["What Makes Me Stand Out:\n"]
|
166 |
+
response_parts.append("• Unique Background:")
|
167 |
+
response_parts.append(" - Successfully transitioned from commerce to tech")
|
168 |
+
response_parts.append(" - Blend of business acumen and technical expertise")
|
169 |
+
response_parts.append("")
|
170 |
+
|
171 |
+
response_parts.append("• Practical Experience:")
|
172 |
+
response_parts.append(" - Built multiple ML projects from scratch")
|
173 |
+
response_parts.append(" - Focus on real-world applications")
|
174 |
+
response_parts.append("")
|
175 |
+
|
176 |
+
response_parts.append("• Technical Depth:")
|
177 |
+
response_parts.append(" - Strong foundation in ML/AI principles")
|
178 |
+
response_parts.append(" - Experience with end-to-end project implementation")
|
179 |
+
response_parts.append("")
|
180 |
+
|
181 |
+
response_parts.append("• Innovation Focus:")
|
182 |
+
response_parts.append(" - Developing novel solutions in ML/AI")
|
183 |
+
response_parts.append(" - Emphasis on practical impact")
|
184 |
+
|
185 |
+
return '\n'.join(response_parts)
|
186 |
+
|
187 |
def add_relevant_links(response: str, query: str, knowledge_base: dict) -> str:
|
188 |
"""Add relevant links based on query context"""
|
189 |
query_lower = query.lower()
|
190 |
links = []
|
191 |
|
|
|
192 |
if any(word in query_lower for word in ['project', 'portfolio', 'work']):
|
193 |
links.append(f"\nView my complete portfolio: {knowledge_base['personal_details']['online_presence']['portfolio']}")
|
194 |
|
|
|
205 |
|
206 |
return response
|
207 |
|
208 |
+
def handle_market_conditions(knowledge_base: dict) -> str:
|
209 |
+
"""Handle market condition related queries with perspective"""
|
210 |
+
market_outlook = knowledge_base['personal_details']['perspectives']['market_outlook']
|
211 |
+
|
212 |
+
response = [
|
213 |
+
market_outlook['job_market'],
|
214 |
+
market_outlook['value_proposition'],
|
215 |
+
market_outlook['strategy']
|
216 |
+
]
|
217 |
+
|
218 |
+
return '\n\n'.join(response)
|
219 |
+
|
220 |
+
def handle_general_query(query: str, knowledge_base: dict) -> str:
|
221 |
+
"""Handle general queries using common_queries section"""
|
222 |
+
query_lower = query.lower()
|
223 |
+
|
224 |
+
# Check for weather-related queries
|
225 |
+
if any(word in query_lower for word in ['weather', 'temperature', 'climate']):
|
226 |
+
return knowledge_base['personal_details']['common_queries']['weather']
|
227 |
+
|
228 |
+
# Check for market-related queries
|
229 |
+
if any(word in query_lower for word in ['market', 'job market', 'opportunities']):
|
230 |
+
return handle_market_conditions(knowledge_base)
|
231 |
+
|
232 |
+
# Default to personal summary for truly general queries
|
233 |
+
return knowledge_base['personal_details']['professional_summary']
|
234 |
+
|
235 |
def generate_response(query: str, knowledge_base: dict) -> str:
|
236 |
+
"""Enhanced response generation with better query handling"""
|
237 |
query_lower = query.lower()
|
238 |
|
239 |
# Handle project listing requests
|
|
|
268 |
|
269 |
# Handle standout/unique qualities queries
|
270 |
elif any(word in query_lower for word in ['stand out', 'unique', 'different', 'special']):
|
271 |
+
return format_standout_response()
|
272 |
+
|
273 |
+
# Handle market condition queries
|
274 |
+
elif any(phrase in query_lower for phrase in ['market down', 'job market', 'market conditions']):
|
275 |
+
return handle_market_conditions(knowledge_base)
|
276 |
+
|
277 |
+
# Handle general queries
|
278 |
+
elif len(query.split()) < 5 or any(word in query_lower for word in ['weather', 'temperature']):
|
279 |
+
return handle_general_query(query, knowledge_base)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
# Default response
|
282 |
return (f"I'm {knowledge_base['personal_details']['professional_summary']}\n\n"
|
|
|
312 |
""")
|
313 |
st.session_state.displayed_welcome = True
|
314 |
|
315 |
+
# Create two columns with adjusted ratios
|
316 |
+
col1, col2 = st.columns([4, 1])
|
317 |
|
318 |
with col1:
|
319 |
# Display chat messages
|
|
|
338 |
st.rerun()
|
339 |
|
340 |
with col2:
|
341 |
+
st.markdown("### Quick Questions")
|
342 |
example_questions = [
|
343 |
"Tell me about your ML projects",
|
344 |
"What are your technical skills?",
|
|
|
348 |
]
|
349 |
|
350 |
for question in example_questions:
|
351 |
+
if st.button(question, key=f"btn_{question}", use_container_width=True):
|
352 |
st.session_state.messages.append({"role": "user", "content": question})
|
353 |
+
try:
|
354 |
+
response = generate_response(question, st.session_state.knowledge_base)
|
355 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
356 |
+
except Exception as e:
|
357 |
+
st.error(f"An error occurred: {str(e)}")
|
358 |
st.rerun()
|
359 |
|
360 |
st.markdown("---")
|
361 |
+
if st.button("Clear Chat", use_container_width=True):
|
362 |
st.session_state.messages = []
|
363 |
st.rerun()
|
364 |
|