File size: 10,516 Bytes
352d473
c672d1b
5cb8fb6
352d473
a05bcb9
35e8298
f73c0d1
35e8298
a05bcb9
35e8298
352d473
efc4ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
5cb8fb6
efc4ecf
 
 
 
 
 
 
 
 
 
 
5cb8fb6
efc4ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cb8fb6
efc4ecf
 
 
 
 
 
 
 
 
 
5cb8fb6
efc4ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cb8fb6
efc4ecf
 
5cb8fb6
efc4ecf
 
 
 
 
 
5cb8fb6
efc4ecf
 
 
 
 
 
5cb8fb6
 
 
 
efc4ecf
5cb8fb6
efc4ecf
5cb8fb6
efc4ecf
5cb8fb6
efc4ecf
5cb8fb6
 
 
 
 
 
efc4ecf
 
 
 
 
 
 
 
 
 
 
 
5cb8fb6
efc4ecf
5cb8fb6
efc4ecf
5cb8fb6
efc4ecf
 
 
 
 
 
 
 
 
 
 
 
 
 
5cb8fb6
 
 
efc4ecf
 
 
 
 
5cb8fb6
 
efc4ecf
 
 
 
 
 
 
 
473251f
a05bcb9
 
c672d1b
a05bcb9
72dca05
a05bcb9
05ce7a2
 
a05bcb9
473251f
a05bcb9
 
 
 
 
 
 
35e8298
f73c0d1
5cb8fb6
 
 
 
 
 
 
05ce7a2
a05bcb9
 
05ce7a2
a05bcb9
f73c0d1
05ce7a2
35e8298
5cb8fb6
 
 
 
05ce7a2
f73c0d1
5cb8fb6
f73c0d1
35e8298
a05bcb9
 
05ce7a2
a05bcb9
35e8298
5cb8fb6
35e8298
5cb8fb6
05ce7a2
35e8298
f73c0d1
a05bcb9
 
 
5cb8fb6
 
 
a05bcb9
05ce7a2
 
a05bcb9
 
 
05ce7a2
f73c0d1
a05bcb9
f73c0d1
35e8298
352d473
35e8298
5cb8fb6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import streamlit as st
import json
from typing import Dict, List, Any

# Initialize Streamlit page configuration
st.set_page_config(
    page_title="Manyue's Portfolio Chatbot",
    page_icon="🤖",
    layout="wide"
)

# Helper functions for formatting responses
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()
    
    # Extract key skills from knowledge base
    my_skills = set(s.lower() for s in knowledge_base['skills']['technical_skills'])
    
    # Common ML/AI job related keywords
    ml_keywords = {
        'machine learning', 'deep learning', 'artificial intelligence', 'ai', 'ml',
        'neural networks', 'nlp', 'computer vision', 'data science',
        'python', 'pytorch', 'tensorflow', 'scikit-learn'
    }
    
    # Find mentioned skills in JD
    found_skills = []
    for skill in my_skills:
        if skill in text_lower:
            found_skills.append(skill)
            
    # Find relevant projects
    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()
    
    # Handle project listing requests
    if any(word in query_lower for word in ['list', 'project', 'portfolio', 'built', 'created', 'developed']):
        return format_project_list(knowledge_base)
    
    # Handle background/journey queries
    elif any(word in query_lower for word in ['background', 'journey', 'story', 'transition']):
        return format_story_response(knowledge_base)
    
    # Handle standout/unique qualities queries
    elif any(word in query_lower for word in ['stand out', 'unique', 'different', 'special']):
        return format_standout_qualities(knowledge_base)
    
    # Handle job descriptions or role requirements
    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)
    
    # Handle specific skill queries
    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)
    
    # Default 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!")

# Load and cache knowledge base
@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
    initialize_session_state()

    # Create two columns
    col1, col2 = st.columns([3, 1])

    with col1:
        # Display chat messages
        for message in st.session_state.messages:
            with st.chat_message(message["role"]):
                st.markdown(message["content"])

        # Chat input
        if prompt := st.chat_input("Ask me anything about Manyue's experience or paste a job description..."):
            # Add user message
            st.session_state.messages.append({"role": "user", "content": prompt})
            with st.chat_message("user"):
                st.markdown(prompt)

            # Generate and display response
            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()