Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,125 +1,84 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import json
|
| 3 |
from typing import Dict, List, Any
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 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
|
| 70 |
-
"""
|
| 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
|
| 96 |
-
my_skills =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
|
| 100 |
-
'
|
| 101 |
-
'
|
| 102 |
-
'
|
| 103 |
}
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
# Find relevant projects
|
| 112 |
relevant_projects = []
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
if
|
|
|
|
|
|
|
| 116 |
relevant_projects.append(project)
|
| 117 |
-
|
| 118 |
-
return
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
def generate_response(query: str, knowledge_base: dict) -> str:
|
| 125 |
"""Generate enhanced responses using the knowledge base"""
|
|
@@ -127,45 +86,105 @@ def generate_response(query: str, knowledge_base: dict) -> str:
|
|
| 127 |
|
| 128 |
# Handle project listing requests
|
| 129 |
if any(word in query_lower for word in ['list', 'project', 'portfolio', 'built', 'created', 'developed']):
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
# Handle
|
| 137 |
-
elif any(
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
# Handle
|
| 141 |
-
elif
|
| 142 |
-
['
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
# Handle specific
|
| 161 |
-
elif any(word in query_lower for word in ['skill', 'know', '
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
-
#
|
| 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"
|
|
@@ -175,35 +194,30 @@ def generate_response(query: str, knowledge_base: dict) -> str:
|
|
| 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('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.")
|
| 186 |
-
return {}
|
| 187 |
-
|
| 188 |
-
def initialize_session_state():
|
| 189 |
-
"""Initialize session state variables"""
|
| 190 |
-
if "messages" not in st.session_state:
|
| 191 |
-
st.session_state.messages = []
|
| 192 |
-
if "knowledge_base" not in st.session_state:
|
| 193 |
-
st.session_state.knowledge_base = load_knowledge_base()
|
| 194 |
-
|
| 195 |
def main():
|
| 196 |
st.title("💬 Chat with Manyue's Portfolio")
|
| 197 |
-
|
| 198 |
-
Hi! I'm Manyue's AI assistant. I can tell you about:
|
| 199 |
-
- My journey from commerce to ML/AI
|
| 200 |
-
- My technical skills and projects
|
| 201 |
-
- My fit for ML/AI roles
|
| 202 |
-
- You can also paste job descriptions, and I'll show how my profile matches!
|
| 203 |
-
""")
|
| 204 |
-
|
| 205 |
# Initialize session state
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
# Create two columns
|
| 209 |
col1, col2 = st.columns([3, 1])
|
|
@@ -213,19 +227,19 @@ def main():
|
|
| 213 |
for message in st.session_state.messages:
|
| 214 |
with st.chat_message(message["role"]):
|
| 215 |
st.markdown(message["content"])
|
| 216 |
-
|
| 217 |
# Chat input
|
| 218 |
-
if prompt := st.chat_input("Ask me anything
|
| 219 |
# Add user message
|
| 220 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 221 |
-
|
| 222 |
-
st.markdown(prompt)
|
| 223 |
-
|
| 224 |
# Generate and display response
|
| 225 |
with st.chat_message("assistant"):
|
| 226 |
response = generate_response(prompt, st.session_state.knowledge_base)
|
| 227 |
st.markdown(response)
|
| 228 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
|
|
|
|
| 229 |
|
| 230 |
with col2:
|
| 231 |
st.subheader("Quick Questions")
|
|
@@ -240,12 +254,12 @@ def main():
|
|
| 240 |
for question in example_questions:
|
| 241 |
if st.button(question):
|
| 242 |
st.session_state.messages.append({"role": "user", "content": question})
|
| 243 |
-
st.
|
| 244 |
|
| 245 |
st.markdown("---")
|
| 246 |
if st.button("Clear Chat"):
|
| 247 |
st.session_state.messages = []
|
| 248 |
-
st.
|
| 249 |
|
| 250 |
if __name__ == "__main__":
|
| 251 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import json
|
| 3 |
from typing import Dict, List, Any
|
| 4 |
+
import re
|
| 5 |
|
| 6 |
+
def format_project_response(project: dict, include_status: bool = True) -> str:
|
| 7 |
+
"""Format a project description with proper status handling"""
|
| 8 |
+
response = [f"• {project['name']}:"]
|
| 9 |
+
response.append(f" - {project['description']}")
|
| 10 |
+
|
| 11 |
+
if 'skills_used' in project:
|
| 12 |
+
response.append(f" - Technologies: {', '.join(project['skills_used'])}")
|
| 13 |
+
|
| 14 |
+
if include_status and 'status' in project:
|
| 15 |
+
if 'development' in project['status'].lower() or 'progress' in project['status'].lower():
|
| 16 |
+
response.append(f" - Currently {project['status']}")
|
| 17 |
+
if 'confidentiality_note' in project:
|
| 18 |
+
response.append(f" - Note: {project['confidentiality_note']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
return '\n'.join(response)
|
| 21 |
|
| 22 |
+
def analyze_job_requirements(text: str, knowledge_base: dict) -> Dict[str, List[str]]:
|
| 23 |
+
"""Analyze job requirements and match with skills"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
text_lower = text.lower()
|
| 25 |
|
| 26 |
+
# Extract skills from knowledge base
|
| 27 |
+
my_skills = {
|
| 28 |
+
'technical': [skill.lower() for skill in knowledge_base['skills']['technical_skills']['machine_learning']['core'] +
|
| 29 |
+
knowledge_base['skills']['technical_skills']['programming']['primary'] +
|
| 30 |
+
knowledge_base['skills']['technical_skills']['data']['databases']],
|
| 31 |
+
'tools': [tool.lower() for tool in knowledge_base['skills']['technical_skills']['programming']['tools'] +
|
| 32 |
+
knowledge_base['skills']['technical_skills']['deployment']['web']],
|
| 33 |
+
'soft_skills': [skill['skill'].lower() for skill in knowledge_base['skills']['soft_skills']]
|
| 34 |
+
}
|
| 35 |
|
| 36 |
+
# Find matching skills in job description
|
| 37 |
+
matches = {
|
| 38 |
+
'technical_matches': [skill for skill in my_skills['technical'] if skill in text_lower],
|
| 39 |
+
'tool_matches': [tool for tool in my_skills['tools'] if tool in text_lower],
|
| 40 |
+
'soft_skill_matches': [skill for skill in my_skills['soft_skills'] if skill in text_lower]
|
| 41 |
}
|
| 42 |
|
| 43 |
+
return matches
|
| 44 |
+
|
| 45 |
+
def find_relevant_projects(requirements: str, projects: List[dict]) -> List[dict]:
|
| 46 |
+
"""Find projects relevant to job requirements"""
|
| 47 |
+
req_lower = requirements.lower()
|
|
|
|
|
|
|
| 48 |
relevant_projects = []
|
| 49 |
+
|
| 50 |
+
for project in projects:
|
| 51 |
+
# Check if project skills or description match requirements
|
| 52 |
+
if any(skill.lower() in req_lower for skill in project['skills_used']) or \
|
| 53 |
+
any(word in project['description'].lower() for word in req_lower.split()):
|
| 54 |
relevant_projects.append(project)
|
| 55 |
+
|
| 56 |
+
return relevant_projects[:2] # Return top 2 most relevant projects
|
| 57 |
+
|
| 58 |
+
def add_relevant_links(response: str, query: str, knowledge_base: dict) -> str:
|
| 59 |
+
"""Add relevant links based on query context"""
|
| 60 |
+
query_lower = query.lower()
|
| 61 |
+
links = []
|
| 62 |
+
|
| 63 |
+
# Add portfolio link for project-related queries
|
| 64 |
+
if any(word in query_lower for word in ['project', 'portfolio', 'work']):
|
| 65 |
+
links.append(f"\nView my complete portfolio: {knowledge_base['personal_details']['online_presence']['portfolio']}")
|
| 66 |
+
|
| 67 |
+
# Add blog link for technical queries
|
| 68 |
+
if any(word in query_lower for word in ['machine learning', 'ml', 'algorithm', 'knn']):
|
| 69 |
+
for post in knowledge_base['personal_details']['online_presence']['blog_posts']:
|
| 70 |
+
if 'link' in post and any(word in post['title'].lower() for word in query_lower.split()):
|
| 71 |
+
links.append(f"\nRelated blog post: {post['link']}")
|
| 72 |
+
break
|
| 73 |
+
|
| 74 |
+
# Add LinkedIn for professional background queries
|
| 75 |
+
if any(word in query_lower for word in ['background', 'experience', 'work']):
|
| 76 |
+
links.append(f"\nConnect with me: {knowledge_base['personal_details']['online_presence']['linkedin']}")
|
| 77 |
+
|
| 78 |
+
if links:
|
| 79 |
+
response += '\n\n' + '\n'.join(links)
|
| 80 |
+
|
| 81 |
+
return response
|
| 82 |
|
| 83 |
def generate_response(query: str, knowledge_base: dict) -> str:
|
| 84 |
"""Generate enhanced responses using the knowledge base"""
|
|
|
|
| 86 |
|
| 87 |
# Handle project listing requests
|
| 88 |
if any(word in query_lower for word in ['list', 'project', 'portfolio', 'built', 'created', 'developed']):
|
| 89 |
+
response_parts = ["Here are my key projects:"]
|
| 90 |
+
|
| 91 |
+
# Major Projects (under development)
|
| 92 |
+
response_parts.append("\nMajor Projects (In Development):")
|
| 93 |
+
for project in knowledge_base['projects']['major_projects']:
|
| 94 |
+
response_parts.append(format_project_response(project))
|
| 95 |
+
|
| 96 |
+
# Algorithm Implementation Projects (completed)
|
| 97 |
+
response_parts.append("\nCompleted Algorithm Implementation Projects:")
|
| 98 |
+
for project in knowledge_base['projects']['algorithm_practice_projects']:
|
| 99 |
+
response_parts.append(format_project_response(project, include_status=False))
|
| 100 |
+
|
| 101 |
+
response = '\n'.join(response_parts)
|
| 102 |
+
return add_relevant_links(response, query, knowledge_base)
|
| 103 |
|
| 104 |
+
# Handle job description analysis
|
| 105 |
+
elif len(query.split()) > 20 and any(phrase in query_lower for phrase in
|
| 106 |
+
['requirements', 'qualifications', 'looking for', 'job description']):
|
| 107 |
+
|
| 108 |
+
skill_matches = analyze_job_requirements(query, knowledge_base)
|
| 109 |
+
relevant_projects = find_relevant_projects(query, knowledge_base['projects']['major_projects'])
|
| 110 |
+
|
| 111 |
+
response_parts = ["Based on the job requirements, here's how my profile aligns:"]
|
| 112 |
+
|
| 113 |
+
# Technical Skills Match
|
| 114 |
+
if skill_matches['technical_matches']:
|
| 115 |
+
response_parts.append("\n• Technical Skills Match:")
|
| 116 |
+
for skill in skill_matches['technical_matches']:
|
| 117 |
+
response_parts.append(f" - Strong proficiency in {skill}")
|
| 118 |
+
|
| 119 |
+
# Tools and Technologies
|
| 120 |
+
if skill_matches['tool_matches']:
|
| 121 |
+
response_parts.append("\n• Relevant Tools/Technologies:")
|
| 122 |
+
for tool in skill_matches['tool_matches']:
|
| 123 |
+
response_parts.append(f" - Experience with {tool}")
|
| 124 |
+
|
| 125 |
+
# Relevant Projects
|
| 126 |
+
if relevant_projects:
|
| 127 |
+
response_parts.append("\n• Relevant Project Experience:")
|
| 128 |
+
for project in relevant_projects:
|
| 129 |
+
response_parts.append(format_project_response(project))
|
| 130 |
+
|
| 131 |
+
# Education and Background
|
| 132 |
+
response_parts.append("\n• Education and Background:")
|
| 133 |
+
response_parts.append(" - Currently pursuing advanced AI/ML education in Canada")
|
| 134 |
+
response_parts.append(" - Unique background combining commerce and technology")
|
| 135 |
+
response_parts.append(" - Strong foundation in practical ML implementation")
|
| 136 |
+
|
| 137 |
+
response = '\n'.join(response_parts)
|
| 138 |
+
return add_relevant_links(response, query, knowledge_base)
|
| 139 |
|
| 140 |
+
# Handle background/story queries
|
| 141 |
+
elif any(word in query_lower for word in ['background', 'journey', 'story', 'transition']):
|
| 142 |
+
transition_story = next((qa['answer'] for qa in knowledge_base['frequently_asked_questions']
|
| 143 |
+
if 'transition' in qa['question'].lower()), '')
|
| 144 |
|
| 145 |
+
response_parts = [
|
| 146 |
+
"My Journey from Commerce to ML/AI:",
|
| 147 |
+
"• Education Background:",
|
| 148 |
+
f" - {knowledge_base['education']['undergraduate']['course_name']} from {knowledge_base['education']['undergraduate']['institution']}",
|
| 149 |
+
"• Career Transition:",
|
| 150 |
+
" - Started as a Programmer Trainee at Cognizant",
|
| 151 |
+
f" - {transition_story[:200]}...",
|
| 152 |
+
"• Current Path:",
|
| 153 |
+
" - Pursuing AI/ML education in Canada",
|
| 154 |
+
" - Building practical ML projects",
|
| 155 |
+
"• Future Goals:",
|
| 156 |
+
" - Aiming to become an ML Engineer in Canada",
|
| 157 |
+
" - Focus on innovative AI solutions"
|
| 158 |
+
]
|
| 159 |
+
|
| 160 |
+
response = '\n'.join(response_parts)
|
| 161 |
+
return add_relevant_links(response, query, knowledge_base)
|
| 162 |
|
| 163 |
+
# Handle skill-specific queries
|
| 164 |
+
elif any(word in query_lower for word in ['skill', 'know', 'technology', 'stack']):
|
| 165 |
+
tech_skills = knowledge_base['skills']['technical_skills']
|
| 166 |
+
|
| 167 |
+
response_parts = ["My Technical Expertise:"]
|
| 168 |
+
|
| 169 |
+
# ML/AI Skills
|
| 170 |
+
response_parts.append("\n• Machine Learning & AI:")
|
| 171 |
+
response_parts.append(f" - Core: {', '.join(tech_skills['machine_learning']['core'])}")
|
| 172 |
+
response_parts.append(f" - Frameworks: {', '.join(tech_skills['machine_learning']['frameworks'])}")
|
| 173 |
+
|
| 174 |
+
# Programming & Tools
|
| 175 |
+
response_parts.append("\n• Programming & Development:")
|
| 176 |
+
response_parts.append(f" - Languages: {', '.join(tech_skills['programming']['primary'])}")
|
| 177 |
+
response_parts.append(f" - Tools: {', '.join(tech_skills['programming']['tools'])}")
|
| 178 |
+
|
| 179 |
+
# Data & Analytics
|
| 180 |
+
response_parts.append("\n• Data & Analytics:")
|
| 181 |
+
response_parts.append(f" - Databases: {', '.join(tech_skills['data']['databases'])}")
|
| 182 |
+
response_parts.append(f" - Visualization: {', '.join(tech_skills['data']['visualization'])}")
|
| 183 |
+
|
| 184 |
+
response = '\n'.join(response_parts)
|
| 185 |
+
return add_relevant_links(response, query, knowledge_base)
|
| 186 |
|
| 187 |
+
# Handle default/unknown queries
|
| 188 |
return (f"I'm {knowledge_base['personal_details']['full_name']}, "
|
| 189 |
f"{knowledge_base['personal_details']['professional_summary']}\n\n"
|
| 190 |
"You can ask me about:\n"
|
|
|
|
| 194 |
"• My fit for ML/AI roles\n"
|
| 195 |
"Or paste a job description to see how my profile matches!")
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
def main():
|
| 198 |
st.title("💬 Chat with Manyue's Portfolio")
|
| 199 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
# Initialize session state
|
| 201 |
+
if "messages" not in st.session_state:
|
| 202 |
+
st.session_state.messages = []
|
| 203 |
+
if "knowledge_base" not in st.session_state:
|
| 204 |
+
try:
|
| 205 |
+
with open('manny_knowledge_base.json', 'r', encoding='utf-8') as f:
|
| 206 |
+
st.session_state.knowledge_base = json.load(f)
|
| 207 |
+
except FileNotFoundError:
|
| 208 |
+
st.error("Knowledge base file not found.")
|
| 209 |
+
return
|
| 210 |
+
|
| 211 |
+
# Display welcome message
|
| 212 |
+
if "displayed_welcome" not in st.session_state:
|
| 213 |
+
st.write("""
|
| 214 |
+
Hi! I'm Manyue's AI assistant. I can tell you about:
|
| 215 |
+
- My journey from commerce to ML/AI
|
| 216 |
+
- My technical skills and projects
|
| 217 |
+
- My fit for ML/AI roles
|
| 218 |
+
- You can also paste job descriptions to see how my profile matches!
|
| 219 |
+
""")
|
| 220 |
+
st.session_state.displayed_welcome = True
|
| 221 |
|
| 222 |
# Create two columns
|
| 223 |
col1, col2 = st.columns([3, 1])
|
|
|
|
| 227 |
for message in st.session_state.messages:
|
| 228 |
with st.chat_message(message["role"]):
|
| 229 |
st.markdown(message["content"])
|
| 230 |
+
|
| 231 |
# Chat input
|
| 232 |
+
if prompt := st.chat_input("Ask me anything or paste a job description..."):
|
| 233 |
# Add user message
|
| 234 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 235 |
+
|
|
|
|
|
|
|
| 236 |
# Generate and display response
|
| 237 |
with st.chat_message("assistant"):
|
| 238 |
response = generate_response(prompt, st.session_state.knowledge_base)
|
| 239 |
st.markdown(response)
|
| 240 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 241 |
+
|
| 242 |
+
st.rerun()
|
| 243 |
|
| 244 |
with col2:
|
| 245 |
st.subheader("Quick Questions")
|
|
|
|
| 254 |
for question in example_questions:
|
| 255 |
if st.button(question):
|
| 256 |
st.session_state.messages.append({"role": "user", "content": question})
|
| 257 |
+
st.rerun()
|
| 258 |
|
| 259 |
st.markdown("---")
|
| 260 |
if st.button("Clear Chat"):
|
| 261 |
st.session_state.messages = []
|
| 262 |
+
st.rerun()
|
| 263 |
|
| 264 |
if __name__ == "__main__":
|
| 265 |
main()
|