Pranav0111 commited on
Commit
0986c90
·
verified ·
1 Parent(s): 899f7e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +136 -23
app.py CHANGED
@@ -6,6 +6,13 @@ import numpy as np
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):
@@ -177,33 +184,135 @@ def render_analytics():
177
  for col, (metric, value) in zip(cols, metrics.items()):
178
  col.metric(metric, f"{value:.2f}")
179
 
180
- def render_brainstorm():
181
- st.header("🧠 Product Brainstorm")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
- # Product selection
184
- products = ["Product A", "Product B", "Product C", "Add New Product"]
185
- selected_product = st.selectbox("Select Product", products)
186
 
187
- if selected_product == "Add New Product":
188
- with st.form("new_product"):
189
- st.subheader("Add New Product")
190
- product_name = st.text_input("Product Name")
191
- product_desc = st.text_area("Product Description")
192
- product_category = st.selectbox("Category", ["Category A", "Category B", "Category C"])
 
 
 
 
 
 
 
 
 
 
 
193
 
194
- if st.form_submit_button("Add Product"):
195
- st.success(f"Product '{product_name}' added successfully!")
196
  else:
197
- st.subheader(f"Analysis for {selected_product}")
198
-
199
- # Sample metrics
200
- col1, col2, col3 = st.columns(3)
201
- with col1:
202
- st.metric("Sales", "$12,345", "+10%")
203
- with col2:
204
- st.metric("Reviews", "4.5/5", "+0.2")
205
- with col3:
206
- st.metric("Engagement", "89%", "-2%")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
 
208
  def render_chat():
209
  st.header("💬 Business Assistant")
@@ -259,6 +368,10 @@ def main():
259
  render_brainstorm()
260
  elif page == "Chat":
261
  render_chat()
 
 
 
 
262
 
263
  if __name__ == "__main__":
264
  main()
 
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):
 
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.")
285
+
286
  else:
287
+ if st.session_state.products:
288
+ for prod_id, product in st.session_state.products.items():
289
+ with st.expander(f"🎯 {product['data']['name']}"):
290
+ col1, col2 = st.columns(2)
291
+
292
+ with col1:
293
+ st.subheader("Product Details")
294
+ st.write(f"Category: {product['data']['category']}")
295
+ st.write(f"Target: {', '.join(product['data']['target_audience'])}")
296
+ st.write(f"Description: {product['data']['description']}")
297
+
298
+ with col2:
299
+ st.subheader("Insights")
300
+ st.metric("Opportunity Score", f"{product['insights']['market_opportunity']}/10")
301
+ st.metric("Suggested Price", f"${product['insights']['suggested_price']}")
302
+
303
+ st.write("**Risk Factors:**")
304
+ for risk in product['insights']['risk_factors']:
305
+ st.write(f"- {risk}")
306
+
307
+ st.write("**Next Steps:**")
308
+ for step in product['insights']['next_steps']:
309
+ st.write(f"- {step}")
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")
 
368
  render_brainstorm()
369
  elif page == "Chat":
370
  render_chat()
371
+ #
372
+ # In your main() function, update this line:
373
+ elif page == "Brainstorm":
374
+ render_brainstorm_page() # Changed from render_brainstorm()
375
 
376
  if __name__ == "__main__":
377
  main()