Pranav0111 commited on
Commit
fcb1801
·
verified ·
1 Parent(s): 2cf497c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -103
app.py CHANGED
@@ -6,13 +6,6 @@ import numpy as np
6
  from datetime import datetime, timedelta
7
  from typing import Dict, List, Any
8
 
9
- # --- Brainstorm Class ---
10
- class BrainstormManager:
11
- def __init__(self):
12
- # Initialize session state for products
13
- if 'products' not in st.session_state:
14
- st.session_state.products = {}
15
-
16
  # --- Data Processing Class ---
17
  class DataProcessor:
18
  def __init__(self):
@@ -69,6 +62,78 @@ class DataProcessor:
69
 
70
  return fig
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  # --- Sample Data Generation ---
73
  def generate_sample_data():
74
  dates = pd.date_range(start='2024-01-01', end='2024-01-31', freq='D')
@@ -85,7 +150,6 @@ def render_dashboard():
85
  st.header("📊 Performance Dashboard")
86
  data = generate_sample_data()
87
 
88
- # KPI Metrics
89
  col1, col2, col3, col4 = st.columns(4)
90
  with col1:
91
  st.metric("Total Revenue", f"${data['Revenue'].sum():,.2f}")
@@ -96,7 +160,6 @@ def render_dashboard():
96
  with col4:
97
  st.metric("Active Days", len(data))
98
 
99
- # Charts
100
  col1, col2 = st.columns(2)
101
  with col1:
102
  st.subheader("Revenue Trend")
@@ -113,8 +176,6 @@ def render_analytics():
113
  st.header("🔍 Data Analytics")
114
 
115
  processor = DataProcessor()
116
-
117
- # File upload
118
  uploaded_file = st.file_uploader("Upload your CSV data", type=['csv'])
119
 
120
  if uploaded_file is not None:
@@ -123,13 +184,11 @@ def render_analytics():
123
 
124
  tabs = st.tabs(["Data Preview", "Statistics", "Visualization", "Metrics"])
125
 
126
- # Data Preview Tab
127
  with tabs[0]:
128
  st.subheader("Data Preview")
129
  st.dataframe(processor.data.head())
130
  st.info(f"Total rows: {len(processor.data)}, Total columns: {len(processor.data.columns)}")
131
 
132
- # Statistics Tab
133
  with tabs[1]:
134
  st.subheader("Basic Statistics")
135
  stats = processor.get_basic_stats()
@@ -138,7 +197,6 @@ def render_analytics():
138
  st.subheader("Missing Values")
139
  st.write(stats['missing_values'])
140
 
141
- # Visualization Tab
142
  with tabs[2]:
143
  st.subheader("Create Visualization")
144
  col1, col2, col3 = st.columns(3)
@@ -167,7 +225,6 @@ def render_analytics():
167
  )
168
  st.plotly_chart(fig, use_container_width=True)
169
 
170
- # Metrics Tab
171
  with tabs[3]:
172
  st.subheader("Column Metrics")
173
  selected_col = st.selectbox("Select column", processor.numeric_columns)
@@ -184,101 +241,24 @@ def render_analytics():
184
  for col, (metric, value) in zip(cols, metrics.items()):
185
  col.metric(metric, f"{value:.2f}")
186
 
187
-
188
-
189
-
190
- def generate_product_form(self) -> Dict:
191
- """Generate dynamic form fields for product input"""
192
- with st.form("product_form"):
193
- basic_info = {
194
- "name": st.text_input("Product Name"),
195
- "category": st.selectbox("Category", ["Digital", "Physical", "Service"]),
196
- "description": st.text_area("Description"),
197
- "target_audience": st.multiselect("Target Audience",
198
- ["Students", "Professionals", "Businesses", "Seniors", "Youth"]),
199
- "price_range": st.slider("Price Range ($)", 0, 1000, (50, 200)),
200
- "launch_date": st.date_input("Expected Launch Date")
201
- }
202
-
203
- st.subheader("Market Analysis")
204
- market_analysis = {
205
- "competitors": st.text_area("Main Competitors (one per line)"),
206
- "unique_features": st.text_area("Unique Selling Points"),
207
- "market_size": st.selectbox("Market Size",
208
- ["Small", "Medium", "Large", "Enterprise"]),
209
- "growth_potential": st.slider("Growth Potential", 1, 10)
210
- }
211
-
212
- submitted = st.form_submit_button("Save Product")
213
- return basic_info, market_analysis, submitted
214
-
215
- def analyze_product(self, product_data: Dict) -> Dict:
216
- """Generate insights based on product data"""
217
- insights = {
218
- "market_opportunity": self._calculate_opportunity_score(product_data),
219
- "suggested_price": self._suggest_price(product_data),
220
- "risk_factors": self._identify_risks(product_data),
221
- "next_steps": self._generate_next_steps(product_data)
222
- }
223
- return insights
224
-
225
- def _calculate_opportunity_score(self, data: Dict) -> int:
226
- score = 0
227
- if data.get("market_size") == "Large":
228
- score += 3
229
- if len(data.get("target_audience", [])) >= 2:
230
- score += 2
231
- if data.get("growth_potential", 0) > 7:
232
- score += 2
233
- return min(score, 10)
234
-
235
- def _suggest_price(self, data: Dict) -> float:
236
- base_price = sum(data.get("price_range", (0, 0))) / 2
237
- if data.get("market_size") == "Enterprise":
238
- base_price *= 1.5
239
- return round(base_price, 2)
240
-
241
- def _identify_risks(self, data: Dict) -> List[str]:
242
- risks = []
243
- if data.get("competitors"):
244
- risks.append("Competitive market - differentiation crucial")
245
- if len(data.get("target_audience", [])) < 2:
246
- risks.append("Narrow target audience - consider expansion")
247
- return risks
248
-
249
- def _generate_next_steps(self, data: Dict) -> List[str]:
250
- steps = [
251
- "Create detailed product specification",
252
- "Develop MVP timeline",
253
- "Plan marketing strategy"
254
- ]
255
- if data.get("market_size") == "Enterprise":
256
- steps.append("Prepare enterprise sales strategy")
257
- return steps
258
-
259
  def render_brainstorm_page():
260
  st.title("Product Brainstorm Hub")
261
  manager = BrainstormManager()
262
 
263
- # View/Create toggle
264
  action = st.sidebar.radio("Action", ["View Products", "Create New Product"])
265
 
266
  if action == "Create New Product":
267
  basic_info, market_analysis, submitted = manager.generate_product_form()
268
 
269
  if submitted:
270
- # Combine form data
271
  product_data = {**basic_info, **market_analysis}
272
-
273
- # Generate insights
274
  insights = manager.analyze_product(product_data)
275
 
276
- # Store product
277
  product_id = f"prod_{len(st.session_state.products)}"
278
  st.session_state.products[product_id] = {
279
  "data": product_data,
280
  "insights": insights,
281
- "created_at": str(datetime.datetime.now())
282
  }
283
 
284
  st.success("Product added! View insights in the Products tab.")
@@ -310,37 +290,27 @@ def render_brainstorm_page():
310
  else:
311
  st.info("No products yet. Create one to get started!")
312
 
313
- # Usage in main app
314
- if __name__ == "__main__":
315
- render_brainstorm_page()
316
-
317
  def render_chat():
318
  st.header("💬 Business Assistant")
319
 
320
- # Initialize chat history
321
  if "messages" not in st.session_state:
322
  st.session_state.messages = []
323
 
324
- # Display chat history
325
  for message in st.session_state.messages:
326
  with st.chat_message(message["role"]):
327
  st.markdown(message["content"])
328
 
329
- # Chat input
330
  if prompt := st.chat_input("Ask about your business..."):
331
  st.session_state.messages.append({"role": "user", "content": prompt})
332
  with st.chat_message("user"):
333
  st.markdown(prompt)
334
 
335
- # Simple response (placeholder for LLM integration)
336
  response = f"Thank you for your question about '{prompt}'. The LLM integration will be implemented soon."
337
 
338
  with st.chat_message("assistant"):
339
  st.markdown(response)
340
  st.session_state.messages.append({"role": "assistant", "content": response})
341
 
342
-
343
- #main file
344
  def main():
345
  st.set_page_config(
346
  page_title="Prospira",
 
6
  from datetime import datetime, timedelta
7
  from typing import Dict, List, Any
8
 
 
 
 
 
 
 
 
9
  # --- Data Processing Class ---
10
  class DataProcessor:
11
  def __init__(self):
 
62
 
63
  return fig
64
 
65
+ class BrainstormManager:
66
+ def __init__(self):
67
+ if 'products' not in st.session_state:
68
+ st.session_state.products = {}
69
+
70
+ def generate_product_form(self) -> Dict:
71
+ with st.form("product_form"):
72
+ basic_info = {
73
+ "name": st.text_input("Product Name"),
74
+ "category": st.selectbox("Category", ["Digital", "Physical", "Service"]),
75
+ "description": st.text_area("Description"),
76
+ "target_audience": st.multiselect("Target Audience",
77
+ ["Students", "Professionals", "Businesses", "Seniors", "Youth"]),
78
+ "price_range": st.slider("Price Range ($)", 0, 1000, (50, 200)),
79
+ "launch_date": st.date_input("Expected Launch Date")
80
+ }
81
+
82
+ st.subheader("Market Analysis")
83
+ market_analysis = {
84
+ "competitors": st.text_area("Main Competitors (one per line)"),
85
+ "unique_features": st.text_area("Unique Selling Points"),
86
+ "market_size": st.selectbox("Market Size",
87
+ ["Small", "Medium", "Large", "Enterprise"]),
88
+ "growth_potential": st.slider("Growth Potential", 1, 10)
89
+ }
90
+
91
+ submitted = st.form_submit_button("Save Product")
92
+ return basic_info, market_analysis, submitted
93
+
94
+ def analyze_product(self, product_data: Dict) -> Dict:
95
+ insights = {
96
+ "market_opportunity": self._calculate_opportunity_score(product_data),
97
+ "suggested_price": self._suggest_price(product_data),
98
+ "risk_factors": self._identify_risks(product_data),
99
+ "next_steps": self._generate_next_steps(product_data)
100
+ }
101
+ return insights
102
+
103
+ def _calculate_opportunity_score(self, data: Dict) -> int:
104
+ score = 0
105
+ if data.get("market_size") == "Large":
106
+ score += 3
107
+ if len(data.get("target_audience", [])) >= 2:
108
+ score += 2
109
+ if data.get("growth_potential", 0) > 7:
110
+ score += 2
111
+ return min(score, 10)
112
+
113
+ def _suggest_price(self, data: Dict) -> float:
114
+ base_price = sum(data.get("price_range", (0, 0))) / 2
115
+ if data.get("market_size") == "Enterprise":
116
+ base_price *= 1.5
117
+ return round(base_price, 2)
118
+
119
+ def _identify_risks(self, data: Dict) -> List[str]:
120
+ risks = []
121
+ if data.get("competitors"):
122
+ risks.append("Competitive market - differentiation crucial")
123
+ if len(data.get("target_audience", [])) < 2:
124
+ risks.append("Narrow target audience - consider expansion")
125
+ return risks
126
+
127
+ def _generate_next_steps(self, data: Dict) -> List[str]:
128
+ steps = [
129
+ "Create detailed product specification",
130
+ "Develop MVP timeline",
131
+ "Plan marketing strategy"
132
+ ]
133
+ if data.get("market_size") == "Enterprise":
134
+ steps.append("Prepare enterprise sales strategy")
135
+ return steps
136
+
137
  # --- Sample Data Generation ---
138
  def generate_sample_data():
139
  dates = pd.date_range(start='2024-01-01', end='2024-01-31', freq='D')
 
150
  st.header("📊 Performance Dashboard")
151
  data = generate_sample_data()
152
 
 
153
  col1, col2, col3, col4 = st.columns(4)
154
  with col1:
155
  st.metric("Total Revenue", f"${data['Revenue'].sum():,.2f}")
 
160
  with col4:
161
  st.metric("Active Days", len(data))
162
 
 
163
  col1, col2 = st.columns(2)
164
  with col1:
165
  st.subheader("Revenue Trend")
 
176
  st.header("🔍 Data Analytics")
177
 
178
  processor = DataProcessor()
 
 
179
  uploaded_file = st.file_uploader("Upload your CSV data", type=['csv'])
180
 
181
  if uploaded_file is not None:
 
184
 
185
  tabs = st.tabs(["Data Preview", "Statistics", "Visualization", "Metrics"])
186
 
 
187
  with tabs[0]:
188
  st.subheader("Data Preview")
189
  st.dataframe(processor.data.head())
190
  st.info(f"Total rows: {len(processor.data)}, Total columns: {len(processor.data.columns)}")
191
 
 
192
  with tabs[1]:
193
  st.subheader("Basic Statistics")
194
  stats = processor.get_basic_stats()
 
197
  st.subheader("Missing Values")
198
  st.write(stats['missing_values'])
199
 
 
200
  with tabs[2]:
201
  st.subheader("Create Visualization")
202
  col1, col2, col3 = st.columns(3)
 
225
  )
226
  st.plotly_chart(fig, use_container_width=True)
227
 
 
228
  with tabs[3]:
229
  st.subheader("Column Metrics")
230
  selected_col = st.selectbox("Select column", processor.numeric_columns)
 
241
  for col, (metric, value) in zip(cols, metrics.items()):
242
  col.metric(metric, f"{value:.2f}")
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  def render_brainstorm_page():
245
  st.title("Product Brainstorm Hub")
246
  manager = BrainstormManager()
247
 
 
248
  action = st.sidebar.radio("Action", ["View Products", "Create New Product"])
249
 
250
  if action == "Create New Product":
251
  basic_info, market_analysis, submitted = manager.generate_product_form()
252
 
253
  if submitted:
 
254
  product_data = {**basic_info, **market_analysis}
 
 
255
  insights = manager.analyze_product(product_data)
256
 
 
257
  product_id = f"prod_{len(st.session_state.products)}"
258
  st.session_state.products[product_id] = {
259
  "data": product_data,
260
  "insights": insights,
261
+ "created_at": str(datetime.now())
262
  }
263
 
264
  st.success("Product added! View insights in the Products tab.")
 
290
  else:
291
  st.info("No products yet. Create one to get started!")
292
 
 
 
 
 
293
  def render_chat():
294
  st.header("💬 Business Assistant")
295
 
 
296
  if "messages" not in st.session_state:
297
  st.session_state.messages = []
298
 
 
299
  for message in st.session_state.messages:
300
  with st.chat_message(message["role"]):
301
  st.markdown(message["content"])
302
 
 
303
  if prompt := st.chat_input("Ask about your business..."):
304
  st.session_state.messages.append({"role": "user", "content": prompt})
305
  with st.chat_message("user"):
306
  st.markdown(prompt)
307
 
 
308
  response = f"Thank you for your question about '{prompt}'. The LLM integration will be implemented soon."
309
 
310
  with st.chat_message("assistant"):
311
  st.markdown(response)
312
  st.session_state.messages.append({"role": "assistant", "content": response})
313
 
 
 
314
  def main():
315
  st.set_page_config(
316
  page_title="Prospira",