|
import streamlit as st |
|
import json |
|
from typing import Dict, List, Any |
|
|
|
|
|
st.set_page_config( |
|
page_title="Manyue's Portfolio Chatbot", |
|
page_icon="🤖", |
|
layout="wide" |
|
) |
|
|
|
|
|
def get_project_details(project: dict) -> str: |
|
"""Format project details in a clear, structured way""" |
|
return ( |
|
f"• {project['name']}\n" |
|
f" Description: {project['description']}\n" |
|
f" Skills: {', '.join(project['skills_used'])}\n" |
|
f" Status: {project['status']}" |
|
) |
|
|
|
def get_skills_by_category(knowledge_base: dict) -> Dict[str, List[str]]: |
|
"""Organize skills by category with examples""" |
|
skills = knowledge_base['skills'] |
|
projects = knowledge_base['professional_experience']['projects'] |
|
|
|
skill_examples = {} |
|
for skill in skills['technical_skills']: |
|
related_projects = [p['name'] for p in projects |
|
if skill.lower() in [s.lower() for s in p['skills_used']]] |
|
if related_projects: |
|
skill_examples[skill] = related_projects[0] |
|
return skill_examples |
|
|
|
def format_story_response(knowledge_base: dict) -> str: |
|
"""Format the background story in a clear, structured way""" |
|
education = knowledge_base['education'] |
|
|
|
story = [ |
|
"Here's my journey from commerce to ML/AI:", |
|
"• Education Background:", |
|
f" - Graduated with a Commerce degree from {education['Undergraduate'][0]['institution']}", |
|
"• Career Transition:", |
|
" - Started as a Programmer Trainee at Cognizant despite no prior coding experience", |
|
" - Excelled in development roles and discovered passion for technology", |
|
"• Current Path:", |
|
f" - Pursuing {education['postgraduate'][0]['course_name']} at {education['postgraduate'][0]['institution']}", |
|
f" - Also enrolled in {education['postgraduate'][1]['course_name']} at {education['postgraduate'][1]['institution']}", |
|
"• Goal:", |
|
" - Combining business acumen with ML/AI expertise to create impactful solutions" |
|
] |
|
return '\n'.join(story) |
|
|
|
def format_project_list(knowledge_base: dict) -> str: |
|
"""Format project list in a clear, structured way""" |
|
projects = knowledge_base['professional_experience']['projects'] |
|
|
|
response = ["My Portfolio Projects:"] |
|
for project in projects: |
|
response.extend([ |
|
f"\n{project['name']}", |
|
f"• Description: {project['description']}", |
|
f"• Technologies: {', '.join(project['skills_used'])}", |
|
f"• Current Status: {project['status']}", |
|
"---" |
|
]) |
|
return '\n'.join(response) |
|
|
|
def format_standout_qualities(knowledge_base: dict) -> str: |
|
"""Format standout qualities in a clear, structured way""" |
|
qualities = [ |
|
"What Makes Me Stand Out:", |
|
"\n1. Unique Background", |
|
" • Successfully transitioned from commerce to tech", |
|
" • Bring both business acumen and technical expertise", |
|
"\n2. Practical Experience", |
|
f" • Developed {len(knowledge_base['professional_experience']['projects'])} significant ML projects", |
|
" • Real-world implementation experience from Cognizant", |
|
"\n3. Canadian Education", |
|
" • Advanced AI/ML education in Canada", |
|
" • Up-to-date with latest industry practices", |
|
"\n4. Technical Expertise", |
|
f" • Strong foundation in {', '.join(knowledge_base['skills']['technical_skills'][:3])}", |
|
" • Hands-on experience with ML model deployment", |
|
"\n5. Business Perspective", |
|
" • Understanding of both technical and business requirements", |
|
" • Can bridge gap between technical and business teams" |
|
] |
|
return '\n'.join(qualities) |
|
|
|
def analyze_job_description(text: str, knowledge_base: dict) -> dict: |
|
"""Analyze job description and match with candidate's profile""" |
|
text_lower = text.lower() |
|
|
|
|
|
my_skills = set(s.lower() for s in knowledge_base['skills']['technical_skills']) |
|
|
|
|
|
ml_keywords = { |
|
'machine learning', 'deep learning', 'artificial intelligence', 'ai', 'ml', |
|
'neural networks', 'nlp', 'computer vision', 'data science', |
|
'python', 'pytorch', 'tensorflow', 'scikit-learn' |
|
} |
|
|
|
|
|
found_skills = [] |
|
for skill in my_skills: |
|
if skill in text_lower: |
|
found_skills.append(skill) |
|
|
|
|
|
relevant_projects = [] |
|
for project in knowledge_base['professional_experience']['projects']: |
|
project_skills = set(s.lower() for s in project['skills_used']) |
|
if any(skill in text_lower for skill in project_skills): |
|
relevant_projects.append(project) |
|
|
|
return { |
|
'matching_skills': found_skills, |
|
'relevant_projects': relevant_projects[:2], |
|
'is_ml_role': any(keyword in text_lower for keyword in ml_keywords) |
|
} |
|
|
|
def generate_response(query: str, knowledge_base: dict) -> str: |
|
"""Generate enhanced responses using the knowledge base""" |
|
query_lower = query.lower() |
|
|
|
|
|
if any(word in query_lower for word in ['list', 'project', 'portfolio', 'built', 'created', 'developed']): |
|
return format_project_list(knowledge_base) |
|
|
|
|
|
elif any(word in query_lower for word in ['background', 'journey', 'story', 'transition']): |
|
return format_story_response(knowledge_base) |
|
|
|
|
|
elif any(word in query_lower for word in ['stand out', 'unique', 'different', 'special']): |
|
return format_standout_qualities(knowledge_base) |
|
|
|
|
|
elif len(query.split()) > 20 or any(phrase in query_lower for phrase in |
|
['requirements', 'qualifications', 'looking for', 'job description', 'responsibilities']): |
|
analysis = analyze_job_description(query, knowledge_base) |
|
|
|
if analysis['is_ml_role']: |
|
response_parts = [] |
|
response_parts.append("Based on the job description, here's how my profile aligns:") |
|
|
|
if analysis['matching_skills']: |
|
response_parts.append(f"\n• Technical Skills Match:\n - I have experience with: {', '.join(analysis['matching_skills'])}") |
|
|
|
if analysis['relevant_projects']: |
|
project = analysis['relevant_projects'][0] |
|
response_parts.append(f"\n• Relevant Project Experience:\n - {project['name']}: {project['description']}") |
|
|
|
response_parts.append("\n• Additional Qualifications:\n - Advanced AI/ML education in Canada\n - Unique background combining business and technical expertise") |
|
|
|
return '\n'.join(response_parts) |
|
|
|
|
|
elif any(word in query_lower for word in ['skill', 'know', 'experience', 'expert']): |
|
skill_examples = get_skills_by_category(knowledge_base) |
|
response = ["My Technical Skills:"] |
|
for skill, project in skill_examples.items(): |
|
response.append(f"• {skill} - Applied in {project}") |
|
return '\n'.join(response) |
|
|
|
|
|
return (f"I'm {knowledge_base['personal_details']['full_name']}, " |
|
f"{knowledge_base['personal_details']['professional_summary']}\n\n" |
|
"You can ask me about:\n" |
|
"• My projects and portfolio\n" |
|
"• My journey from commerce to ML/AI\n" |
|
"• My technical skills and experience\n" |
|
"• My fit for ML/AI roles\n" |
|
"Or paste a job description to see how my profile matches!") |
|
|
|
|
|
@st.cache_data |
|
def load_knowledge_base(): |
|
try: |
|
with open('knowledge_base.json', 'r', encoding='utf-8') as f: |
|
return json.load(f) |
|
except FileNotFoundError: |
|
st.error("Knowledge base file not found.") |
|
return {} |
|
|
|
def initialize_session_state(): |
|
"""Initialize session state variables""" |
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
if "knowledge_base" not in st.session_state: |
|
st.session_state.knowledge_base = load_knowledge_base() |
|
|
|
def main(): |
|
st.title("💬 Chat with Manyue's Portfolio") |
|
st.write(""" |
|
Hi! I'm Manyue's AI assistant. I can tell you about: |
|
- My journey from commerce to ML/AI |
|
- My technical skills and projects |
|
- My fit for ML/AI roles |
|
- You can also paste job descriptions, and I'll show how my profile matches! |
|
""") |
|
|
|
|
|
initialize_session_state() |
|
|
|
|
|
col1, col2 = st.columns([3, 1]) |
|
|
|
with col1: |
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"]): |
|
st.markdown(message["content"]) |
|
|
|
|
|
if prompt := st.chat_input("Ask me anything about Manyue's experience or paste a job description..."): |
|
|
|
st.session_state.messages.append({"role": "user", "content": prompt}) |
|
with st.chat_message("user"): |
|
st.markdown(prompt) |
|
|
|
|
|
with st.chat_message("assistant"): |
|
response = generate_response(prompt, st.session_state.knowledge_base) |
|
st.markdown(response) |
|
st.session_state.messages.append({"role": "assistant", "content": response}) |
|
|
|
with col2: |
|
st.subheader("Quick Questions") |
|
example_questions = [ |
|
"Tell me about your ML projects", |
|
"What are your technical skills?", |
|
"Why should we hire you as an ML Engineer?", |
|
"What's your journey into ML?", |
|
"Paste a job description to see how I match!" |
|
] |
|
|
|
for question in example_questions: |
|
if st.button(question): |
|
st.session_state.messages.append({"role": "user", "content": question}) |
|
st.experimental_rerun() |
|
|
|
st.markdown("---") |
|
if st.button("Clear Chat"): |
|
st.session_state.messages = [] |
|
st.experimental_rerun() |
|
|
|
if __name__ == "__main__": |
|
main() |