Prospea / chatbot.py
Pranav0111's picture
Create chatbot.py
4421377 verified
raw
history blame
6.59 kB
import streamlit as st
import requests
from typing import List, Dict
import json
class ChatbotManager:
def __init__(self):
if 'chat_history' not in st.session_state:
st.session_state.chat_history = []
if 'chat_initialized' not in st.session_state:
st.session_state.chat_initialized = False
def initialize_chat(self):
"""Initialize the chat with a welcome message"""
if not st.session_state.chat_initialized:
welcome_message = {
"role": "assistant",
"content": "Hello! I'm your AI Business Mentor. I can help you with business strategy, market analysis, product development, marketing insights, and more. What would you like to discuss today?"
}
st.session_state.chat_history.append(welcome_message)
st.session_state.chat_initialized = True
def add_message(self, role: str, content: str):
"""Add a message to the chat history"""
message = {"role": role, "content": content}
st.session_state.chat_history.append(message)
def get_chat_history(self) -> List[Dict]:
"""Get the current chat history"""
return st.session_state.chat_history
def clear_chat(self):
"""Clear the chat history"""
st.session_state.chat_history = []
st.session_state.chat_initialized = False
def generate_business_response(self, user_input: str) -> str:
"""
Generate a business-focused response based on user input
This is a simple rule-based system that can be enhanced with actual AI models
"""
user_input_lower = user_input.lower()
# Business strategy keywords
if any(keyword in user_input_lower for keyword in ['strategy', 'plan', 'planning', 'roadmap']):
return """Great question about business strategy! Here are some key considerations:
1. **Market Analysis**: Understand your target market, competitors, and industry trends
2. **Value Proposition**: Clearly define what unique value you provide
3. **Resource Allocation**: Determine how to best use your time, money, and team
4. **Growth Strategy**: Plan for sustainable scaling and expansion
5. **Risk Management**: Identify potential challenges and mitigation strategies
What specific aspect of strategy would you like to dive deeper into?"""
# Marketing keywords
elif any(keyword in user_input_lower for keyword in ['marketing', 'promotion', 'advertising', 'brand']):
return """Marketing is crucial for business success! Here's a framework to consider:
1. **Target Audience**: Define your ideal customer personas
2. **Channels**: Choose the right mix of digital and traditional channels
3. **Content Strategy**: Create valuable, engaging content
4. **Budget Allocation**: Distribute resources across channels effectively
5. **Metrics & Analytics**: Track performance and ROI
What's your current marketing challenge or goal?"""
# Product development keywords
elif any(keyword in user_input_lower for keyword in ['product', 'development', 'features', 'mvp']):
return """Product development is exciting! Here's a structured approach:
1. **Market Research**: Validate demand and understand user needs
2. **MVP Strategy**: Start with core features and iterate
3. **User Feedback**: Continuously gather and incorporate feedback
4. **Competitive Analysis**: Learn from competitors' successes and failures
5. **Roadmap Planning**: Prioritize features based on impact and effort
What stage is your product in, and what specific guidance do you need?"""
# Financial keywords
elif any(keyword in user_input_lower for keyword in ['finance', 'funding', 'revenue', 'profit', 'investment']):
return """Financial planning is the backbone of any successful business:
1. **Revenue Streams**: Diversify how you generate income
2. **Cost Management**: Track and optimize your expenses
3. **Cash Flow**: Maintain healthy cash flow for operations
4. **Funding Options**: Consider bootstrapping, loans, or investors
5. **Financial Projections**: Create realistic forecasts and budgets
What specific financial aspect would you like to explore?"""
# Team/HR keywords
elif any(keyword in user_input_lower for keyword in ['team', 'hiring', 'employee', 'culture', 'management']):
return """Building a strong team is essential for growth:
1. **Hiring Strategy**: Define roles clearly and hire for culture fit
2. **Team Culture**: Foster collaboration and shared values
3. **Performance Management**: Set clear expectations and provide feedback
4. **Development**: Invest in training and career growth
5. **Retention**: Create an environment where people want to stay
What team-related challenges are you facing?"""
# Startup keywords
elif any(keyword in user_input_lower for keyword in ['startup', 'entrepreneur', 'launch', 'idea']):
return """Launching a startup is an exciting journey! Key steps to consider:
1. **Idea Validation**: Test your concept with potential customers
2. **Business Model**: Define how you'll make money
3. **Legal Structure**: Choose the right business entity
4. **Minimum Viable Product**: Build and test quickly
5. **Network Building**: Connect with mentors, advisors, and peers
What stage are you at in your startup journey?"""
# General business advice
else:
return f"""Thank you for your question about "{user_input}".
As your AI Business Mentor, I'm here to help with various aspects of business including:
• **Strategy & Planning** - Business models, roadmaps, competitive analysis
• **Marketing & Sales** - Customer acquisition, branding, digital marketing
• **Product Development** - MVP creation, feature prioritization, user feedback
• **Finance & Operations** - Budgeting, funding, process optimization
• **Team & Leadership** - Hiring, culture building, management practices
Could you provide more specific details about what you'd like to explore? The more context you give me, the better I can tailor my advice to your situation."""
def format_message_for_display(self, message: Dict) -> str:
"""Format a message for display in the chat interface"""
role = message["role"]
content = message["content"]
if role == "user":
return f"**You:** {content}"
else:
return f"**AI Mentor:** {content}"