Pranav0111 commited on
Commit
4421377
·
verified ·
1 Parent(s): 4979c72

Create chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +139 -0
chatbot.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from typing import List, Dict
4
+ import json
5
+
6
+
7
+ class ChatbotManager:
8
+ def __init__(self):
9
+ if 'chat_history' not in st.session_state:
10
+ st.session_state.chat_history = []
11
+ if 'chat_initialized' not in st.session_state:
12
+ st.session_state.chat_initialized = False
13
+
14
+ def initialize_chat(self):
15
+ """Initialize the chat with a welcome message"""
16
+ if not st.session_state.chat_initialized:
17
+ welcome_message = {
18
+ "role": "assistant",
19
+ "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?"
20
+ }
21
+ st.session_state.chat_history.append(welcome_message)
22
+ st.session_state.chat_initialized = True
23
+
24
+ def add_message(self, role: str, content: str):
25
+ """Add a message to the chat history"""
26
+ message = {"role": role, "content": content}
27
+ st.session_state.chat_history.append(message)
28
+
29
+ def get_chat_history(self) -> List[Dict]:
30
+ """Get the current chat history"""
31
+ return st.session_state.chat_history
32
+
33
+ def clear_chat(self):
34
+ """Clear the chat history"""
35
+ st.session_state.chat_history = []
36
+ st.session_state.chat_initialized = False
37
+
38
+ def generate_business_response(self, user_input: str) -> str:
39
+ """
40
+ Generate a business-focused response based on user input
41
+ This is a simple rule-based system that can be enhanced with actual AI models
42
+ """
43
+ user_input_lower = user_input.lower()
44
+
45
+ # Business strategy keywords
46
+ if any(keyword in user_input_lower for keyword in ['strategy', 'plan', 'planning', 'roadmap']):
47
+ return """Great question about business strategy! Here are some key considerations:
48
+
49
+ 1. **Market Analysis**: Understand your target market, competitors, and industry trends
50
+ 2. **Value Proposition**: Clearly define what unique value you provide
51
+ 3. **Resource Allocation**: Determine how to best use your time, money, and team
52
+ 4. **Growth Strategy**: Plan for sustainable scaling and expansion
53
+ 5. **Risk Management**: Identify potential challenges and mitigation strategies
54
+
55
+ What specific aspect of strategy would you like to dive deeper into?"""
56
+
57
+ # Marketing keywords
58
+ elif any(keyword in user_input_lower for keyword in ['marketing', 'promotion', 'advertising', 'brand']):
59
+ return """Marketing is crucial for business success! Here's a framework to consider:
60
+
61
+ 1. **Target Audience**: Define your ideal customer personas
62
+ 2. **Channels**: Choose the right mix of digital and traditional channels
63
+ 3. **Content Strategy**: Create valuable, engaging content
64
+ 4. **Budget Allocation**: Distribute resources across channels effectively
65
+ 5. **Metrics & Analytics**: Track performance and ROI
66
+
67
+ What's your current marketing challenge or goal?"""
68
+
69
+ # Product development keywords
70
+ elif any(keyword in user_input_lower for keyword in ['product', 'development', 'features', 'mvp']):
71
+ return """Product development is exciting! Here's a structured approach:
72
+
73
+ 1. **Market Research**: Validate demand and understand user needs
74
+ 2. **MVP Strategy**: Start with core features and iterate
75
+ 3. **User Feedback**: Continuously gather and incorporate feedback
76
+ 4. **Competitive Analysis**: Learn from competitors' successes and failures
77
+ 5. **Roadmap Planning**: Prioritize features based on impact and effort
78
+
79
+ What stage is your product in, and what specific guidance do you need?"""
80
+
81
+ # Financial keywords
82
+ elif any(keyword in user_input_lower for keyword in ['finance', 'funding', 'revenue', 'profit', 'investment']):
83
+ return """Financial planning is the backbone of any successful business:
84
+
85
+ 1. **Revenue Streams**: Diversify how you generate income
86
+ 2. **Cost Management**: Track and optimize your expenses
87
+ 3. **Cash Flow**: Maintain healthy cash flow for operations
88
+ 4. **Funding Options**: Consider bootstrapping, loans, or investors
89
+ 5. **Financial Projections**: Create realistic forecasts and budgets
90
+
91
+ What specific financial aspect would you like to explore?"""
92
+
93
+ # Team/HR keywords
94
+ elif any(keyword in user_input_lower for keyword in ['team', 'hiring', 'employee', 'culture', 'management']):
95
+ return """Building a strong team is essential for growth:
96
+
97
+ 1. **Hiring Strategy**: Define roles clearly and hire for culture fit
98
+ 2. **Team Culture**: Foster collaboration and shared values
99
+ 3. **Performance Management**: Set clear expectations and provide feedback
100
+ 4. **Development**: Invest in training and career growth
101
+ 5. **Retention**: Create an environment where people want to stay
102
+
103
+ What team-related challenges are you facing?"""
104
+
105
+ # Startup keywords
106
+ elif any(keyword in user_input_lower for keyword in ['startup', 'entrepreneur', 'launch', 'idea']):
107
+ return """Launching a startup is an exciting journey! Key steps to consider:
108
+
109
+ 1. **Idea Validation**: Test your concept with potential customers
110
+ 2. **Business Model**: Define how you'll make money
111
+ 3. **Legal Structure**: Choose the right business entity
112
+ 4. **Minimum Viable Product**: Build and test quickly
113
+ 5. **Network Building**: Connect with mentors, advisors, and peers
114
+
115
+ What stage are you at in your startup journey?"""
116
+
117
+ # General business advice
118
+ else:
119
+ return f"""Thank you for your question about "{user_input}".
120
+
121
+ As your AI Business Mentor, I'm here to help with various aspects of business including:
122
+
123
+ • **Strategy & Planning** - Business models, roadmaps, competitive analysis
124
+ • **Marketing & Sales** - Customer acquisition, branding, digital marketing
125
+ • **Product Development** - MVP creation, feature prioritization, user feedback
126
+ • **Finance & Operations** - Budgeting, funding, process optimization
127
+ • **Team & Leadership** - Hiring, culture building, management practices
128
+
129
+ 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."""
130
+
131
+ def format_message_for_display(self, message: Dict) -> str:
132
+ """Format a message for display in the chat interface"""
133
+ role = message["role"]
134
+ content = message["content"]
135
+
136
+ if role == "user":
137
+ return f"**You:** {content}"
138
+ else:
139
+ return f"**AI Mentor:** {content}"