File size: 6,925 Bytes
352d473 c672d1b 5cb8fb6 352d473 34c5540 75c603a 34c5540 75c603a f9f18b4 34c5540 f9f18b4 34c5540 f9f18b4 34c5540 2d41771 34c5540 2d41771 34c5540 2d41771 34c5540 2d41771 34c5540 75c603a 34c5540 5cb8fb6 34c5540 5cb8fb6 34c5540 efc4ecf 34c5540 75c603a 34c5540 75c603a 34c5540 f9f18b4 34c5540 75c603a 34c5540 75c603a 34c5540 75c603a 34c5540 5cb8fb6 34c5540 473251f 35e8298 2d41771 75c603a a05bcb9 75c603a f2e07fb 75c603a 5f147cb 75c603a 34c5540 f73c0d1 f9f18b4 35e8298 34c5540 75c603a 2d41771 34c5540 2d41771 34c5540 35e8298 75c603a 34c5540 f9f18b4 34c5540 f9f18b4 35e8298 f73c0d1 a05bcb9 f9f18b4 5cb8fb6 34c5540 a05bcb9 f9f18b4 34c5540 75c603a f9f18b4 f73c0d1 34c5540 f73c0d1 75c603a 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 |
import streamlit as st
import json
from typing import Dict, List, Any
def format_project_response(project: dict) -> str:
"""Format project details with clear separation"""
response = [f"\n• {project['name']}:"]
response.append(f" Description: {project['description']}")
if 'skills_used' in project:
response.append(f"\n Technologies Used:")
response.append(f" {', '.join(project['skills_used'])}")
if 'status' in project:
response.append(f"\n Current Status: {project['status']}")
if 'confidentiality_note' in project:
response.append(f" Note: {project['confidentiality_note']}")
return '\n'.join(response) + '\n'
def get_philosophical_response(query: str, knowledge_base: dict) -> str:
"""Handle philosophical or market-related queries"""
query_lower = query.lower()
# Market-related response
if any(word in query_lower for word in ['market', 'job', 'opportunity', 'down']):
return """I believe success in any market comes down to quality of effort and preparation. While the market may have cycles, I focus on:
• Continuous Skill Development:
- Building practical projects that solve real problems
- Staying updated with latest ML/AI trends
- Enhancing my technical portfolio
• Value Proposition:
- Unique combination of business and technical skills
- Focus on practical implementation
- Strong problem-solving approach
I see this period as an opportunity to strengthen my skills and build more impactful projects."""
# Off-topic response
if any(word in query_lower for word in ['weather', 'temperature', 'climate']):
return """I'm focused on discussing my ML/AI journey and projects. For weather information, I'd recommend checking local weather services.
Would you like to know about:
• My ML projects and technical skills?
• My journey from commerce to tech?
• My approach to the current job market?"""
return None # Return None if not a philosophical query
def generate_response(query: str, knowledge_base: dict) -> str:
"""Enhanced response generation with better handling of various queries"""
query_lower = query.lower()
# First check for philosophical/off-topic queries
philosophical_response = get_philosophical_response(query, knowledge_base)
if philosophical_response:
return philosophical_response
# Handle project listing requests
if any(word in query_lower for word in ['list', 'project', 'portfolio', 'built', 'created', 'developed']):
response_parts = ["Here are my key projects:"]
# Major Projects
response_parts.append("\nMajor Projects (In Development):")
for project in knowledge_base['projects']['major_projects']:
response_parts.append(format_project_response(project))
# Algorithm Projects
response_parts.append("\nCompleted Algorithm Implementation Projects:")
for project in knowledge_base['projects']['algorithm_practice_projects']:
response_parts.append(format_project_response(project))
response = '\n'.join(response_parts)
# Add relevant links
if 'online_presence' in knowledge_base.get('personal_details', {}):
response += f"\n\nView my complete portfolio: {knowledge_base['personal_details']['online_presence']['portfolio']}"
return response
# [Rest of your existing response handlers]
def main():
st.title("💬 Chat with Manyue's Portfolio")
# Initialize session state
if "messages" not in st.session_state:
st.session_state.messages = []
if "knowledge_base" not in st.session_state:
try:
with open('knowledge_base.json', 'r', encoding='utf-8') as f:
st.session_state.knowledge_base = json.load(f)
except FileNotFoundError:
st.error("Knowledge base file not found.")
return
# Display welcome message
if "displayed_welcome" not in st.session_state:
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 to see how my profile matches!
""")
st.session_state.displayed_welcome = True
# Create two columns with proper sizing
col1, col2 = st.columns([3, 1])
with col1:
# Chat container for better scrolling
chat_container = st.container()
with chat_container:
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 or paste a job description...", key="chat_input"):
# Add user message
with st.chat_message("user"):
st.markdown(prompt)
st.session_state.messages.append({"role": "user", "content": prompt})
# Generate and display response
with st.chat_message("assistant"):
try:
response = generate_response(prompt, st.session_state.knowledge_base)
st.markdown(response)
st.session_state.messages.append({"role": "assistant", "content": response})
except Exception as e:
st.error(f"An error occurred: {str(e)}")
with col2:
st.subheader("Quick Questions")
example_questions = [
"Tell me about your ML projects",
"What are your technical skills?",
"What makes you stand out?",
"What's your journey into ML?",
"Your view on the current market?"
]
# Handle quick questions with proper keys
for i, question in enumerate(example_questions):
if st.button(question, key=f"btn_{i}"):
with st.chat_message("user"):
st.markdown(question)
st.session_state.messages.append({"role": "user", "content": question})
with st.chat_message("assistant"):
try:
response = generate_response(question, st.session_state.knowledge_base)
st.markdown(response)
st.session_state.messages.append({"role": "assistant", "content": response})
except Exception as e:
st.error(f"An error occurred: {str(e)}")
st.rerun()
st.markdown("---")
if st.button("Clear Chat", key="clear_chat"):
st.session_state.messages = []
st.rerun()
if __name__ == "__main__":
main() |