mgbam commited on
Commit
2c362d2
Β·
verified Β·
1 Parent(s): 309eec4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -43
app.py CHANGED
@@ -1,78 +1,72 @@
 
 
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)
 
1
+ # app.py – BizIntel AI Ultra (GeminiΒ 1.5Β Pro, selectable date column)
2
+
3
  import os
4
  import tempfile
5
+ import pandas as pd
6
  import streamlit as st
7
  import google.generativeai as genai
8
 
9
  from tools.csv_parser import parse_csv_tool
10
  from tools.plot_generator import plot_sales_tool
11
+ from tools.forecaster import forecast_tool # must accept date_col param
12
 
13
  # ──────────────────────────────────────────────────────────────
14
+ # 1. GEMINI CONFIG (1.5‑pro, temperature 0.7)
15
  # ──────────────────────────────────────────────────────────────
16
  genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
17
+ gemini = genai.GenerativeModel(
18
+ model="gemini-1.5-pro-latest",
19
+ temperature=0.7,
20
+ top_p=0.9,
21
+ response_mime_type="text/markdown",
22
+ )
23
 
24
  # ──────────────────────────────────────────────────────────────
25
+ # 2. STREAMLIT PAGE SETUP
26
  # ──────────────────────────────────────────────────────────────
27
+ st.set_page_config(page_title="BizIntel AI Ultra – GeminiΒ 1.5Β Pro", layout="wide")
28
+ st.title("πŸ“Š BizIntelΒ AIΒ Ultra – Advanced Analytics Pipeline")
29
 
30
  TEMP_DIR = tempfile.gettempdir()
31
 
32
  # ──────────────────────────────────────────────────────────────
33
+ # 3. CSV UPLOAD
34
  # ──────────────────────────────────────────────────────────────
35
+ csv_file = st.file_uploader("Upload a CSV file (≀ 200β€―MB)", type=["csv"])
36
+ if not csv_file:
37
+ st.info("⬆️ Upload a CSV to begin.")
38
  st.stop()
39
 
40
+ csv_path = os.path.join(TEMP_DIR, csv_file.name)
41
  with open(csv_path, "wb") as f:
42
+ f.write(csv_file.read())
43
  st.success("CSV saved to temporary storage βœ…")
44
 
45
+ # Preview first rows for column selection
46
+ df_preview = pd.read_csv(csv_path, nrows=5)
47
+ st.dataframe(df_preview)
48
+
49
  # ──────────────────────────────────────────────────────────────
50
+ # 4. DATE COLUMN CHOICE
51
  # ──────────────────────────────────────────────────────────────
52
+ date_col = st.selectbox("Choose the date/time column for forecasting", df_preview.columns)
 
 
53
 
54
  # ──────────────────────────────────────────────────────────────
55
+ # 5. RUN LOCAL TOOLS
56
  # ──────────────────────────────────────────────────────────────
57
+ with st.spinner("Parsing CSV…"):
58
+ summary_text = parse_csv_tool(csv_path)
 
 
 
 
 
 
59
 
60
+ with st.spinner("Generating sales trend chart…"):
61
+ trend_msg = plot_sales_tool(csv_path) # creates sales_plot.png
 
62
 
63
+ with st.spinner("Forecasting future metrics…"):
64
+ forecast_text = forecast_tool(csv_path, date_col=date_col) # ← passes chosen column
 
 
65
 
66
  # ──────────────────────────────────────────────────────────────
67
+ # 6. GEMINI 1.5‑PRO STRATEGY (stream)
68
  # ──────────────────────────────────────────────────────────────
69
+ prompt = f"""
70
+ You are BizIntel Strategist AI.
 
 
 
 
 
 
71
 
72
+ **CSV SUMMARY**