mgbam commited on
Commit
309eec4
Β·
verified Β·
1 Parent(s): 97b2402

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -38
app.py CHANGED
@@ -1,57 +1,78 @@
1
- import os, tempfile, streamlit as st, pandas as pd
 
 
2
  import google.generativeai as genai
 
3
  from tools.csv_parser import parse_csv_tool
4
  from tools.plot_generator import plot_sales_tool
5
  from tools.forecaster import forecast_tool
6
 
7
- # Configure Gemini
8
- import os
 
9
  genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
10
- model = genai.GenerativeModel("gemini-pro")
11
 
12
- st.set_page_config(page_title="BizIntel AI Ultra", layout="wide")
13
- st.title("πŸ“Š BizIntel AI Ultra – Emergency Pipeline")
 
 
 
14
 
15
  TEMP_DIR = tempfile.gettempdir()
16
 
17
- # 1. CSV upload
18
- csv = st.file_uploader("Upload CSV", ["csv"])
19
- if csv:
20
- csv_path = os.path.join(TEMP_DIR, csv.name)
21
- with open(csv_path, "wb") as f:
22
- f.write(csv.read())
23
- st.success("CSV saved βœ…")
 
 
 
 
 
24
 
25
- # 2. Run local tools
26
- summary = parse_csv_tool(csv_path)
27
- plot_msg = plot_sales_tool(csv_path)
28
- forecast_msg = forecast_tool(csv_path)
 
 
29
 
30
- # 3. Strategy via Gemini
31
- prompt = f"""
32
- You are a business strategist AI.
33
- CSV SUMMARY:
34
- {summary}
35
 
36
- FORECAST:
37
- {forecast_msg}
38
 
39
- Provide key insights and 3 actionable strategies.
40
- """
41
 
42
- strat = model.generate_content(prompt).text
 
 
43
 
44
- # 4. Display results
45
- st.subheader("πŸ“ Data Summary")
46
- st.text(summary)
47
 
48
- if "Generated sales_plot.png" in plot_msg and os.path.exists("sales_plot.png"):
49
- st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
50
 
51
- if "Generated forecast_plot.png" in forecast_msg and os.path.exists("forecast_plot.png"):
52
- st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True)
 
 
 
53
 
54
- st.subheader("πŸš€ Strategy Recommendations")
55
- st.markdown(strat)
56
- else:
57
- st.info("Upload a CSV to begin.")
 
 
 
 
 
1
+ import os
2
+ import tempfile
3
+ import streamlit as st
4
  import google.generativeai as genai
5
+
6
  from tools.csv_parser import parse_csv_tool
7
  from tools.plot_generator import plot_sales_tool
8
  from tools.forecaster import forecast_tool
9
 
10
+ # ──────────────────────────────────────────────────────────────
11
+ # 0. CONFIGURE GEMINI
12
+ # ──────────────────────────────────────────────────────────────
13
  genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
14
+ gemini = genai.GenerativeModel("gemini-pro")
15
 
16
+ # ──────────────────────────────────────────────────────────────
17
+ # 1. STREAMLIT SETUP
18
+ # ──────────────────────────────────────────────────────────────
19
+ st.set_page_config(page_title="BizIntel AI Ultra – Lite", layout="wide")
20
+ st.title("πŸ“Š BizIntel AI Ultra – Quick Analytics Pipeline")
21
 
22
  TEMP_DIR = tempfile.gettempdir()
23
 
24
+ # ──────────────────────────────────────────────────────────────
25
+ # 2. CSV UPLOAD
26
+ # ──────────────────────────────────────────────────────────────
27
+ uploaded_csv = st.file_uploader("Upload a CSV file", type=["csv"])
28
+ if not uploaded_csv:
29
+ st.info("Upload a CSV to begin.")
30
+ st.stop()
31
+
32
+ csv_path = os.path.join(TEMP_DIR, uploaded_csv.name)
33
+ with open(csv_path, "wb") as f:
34
+ f.write(uploaded_csv.read())
35
+ st.success("CSV saved to temporary storage βœ…")
36
 
37
+ # ──────────────────────────────────────────────────────────────
38
+ # 3. LOCAL TOOL PROCESSING
39
+ # ──────────────────────────────────────────────────────────────
40
+ summary_text = parse_csv_tool(csv_path)
41
+ plot_msg = plot_sales_tool(csv_path) # creates sales_plot.png
42
+ forecast_text = forecast_tool(csv_path) # creates forecast_plot.png
43
 
44
+ # ──────────────────────────────────────────────────────────────
45
+ # 4. GEMINI STRATEGY GENERATION
46
+ # ──────────────────────────────────────────────────────────────
47
+ prompt = f"""
48
+ You are BizIntel Strategist AI.
49
 
50
+ CSV SUMMARY:
51
+ {summary_text}
52
 
53
+ FORECAST OUTPUT:
54
+ {forecast_text}
55
 
56
+ Using the data above, produce:
57
+ 1. Key insights (bullet list)
58
+ 2. Three actionable strategies to improve business performance.
59
 
60
+ Be concise and insightful.
61
+ """
 
62
 
63
+ strategy = gemini.generate_content(prompt).text
 
64
 
65
+ # ──────────────────────────────────────────────────────────────
66
+ # 5. DISPLAY RESULTS
67
+ # ──────────────────────────────────────────────────────���───────
68
+ st.subheader("πŸ“‘ Data Summary")
69
+ st.text(summary_text)
70
 
71
+ if os.path.exists("sales_plot.png"):
72
+ st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
73
+
74
+ if os.path.exists("forecast_plot.png"):
75
+ st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True)
76
+
77
+ st.subheader("πŸš€ Strategy Recommendations")
78
+ st.markdown(strategy)