BizIntel_AI / app.py
mgbam's picture
Update app.py
309eec4 verified
raw
history blame
4.09 kB
import os
import tempfile
import streamlit as st
import google.generativeai as genai
from tools.csv_parser import parse_csv_tool
from tools.plot_generator import plot_sales_tool
from tools.forecaster import forecast_tool
# ──────────────────────────────────────────────────────────────
# 0. CONFIGURE GEMINI
# ──────────────────────────────────────────────────────────────
genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
gemini = genai.GenerativeModel("gemini-pro")
# ──────────────────────────────────────────────────────────────
# 1. STREAMLIT SETUP
# ──────────────────────────────────────────────────────────────
st.set_page_config(page_title="BizIntel AI Ultra – Lite", layout="wide")
st.title("πŸ“Š BizIntel AI Ultra – Quick Analytics Pipeline")
TEMP_DIR = tempfile.gettempdir()
# ──────────────────────────────────────────────────────────────
# 2. CSV UPLOAD
# ──────────────────────────────────────────────────────────────
uploaded_csv = st.file_uploader("Upload a CSV file", type=["csv"])
if not uploaded_csv:
st.info("Upload a CSV to begin.")
st.stop()
csv_path = os.path.join(TEMP_DIR, uploaded_csv.name)
with open(csv_path, "wb") as f:
f.write(uploaded_csv.read())
st.success("CSV saved to temporary storage βœ…")
# ──────────────────────────────────────────────────────────────
# 3. LOCAL TOOL PROCESSING
# ──────────────────────────────────────────────────────────────
summary_text = parse_csv_tool(csv_path)
plot_msg = plot_sales_tool(csv_path) # creates sales_plot.png
forecast_text = forecast_tool(csv_path) # creates forecast_plot.png
# ──────────────────────────────────────────────────────────────
# 4. GEMINI STRATEGY GENERATION
# ──────────────────────────────────────────────────────────────
prompt = f"""
You are BizIntel Strategist AI.
CSV SUMMARY:
{summary_text}
FORECAST OUTPUT:
{forecast_text}
Using the data above, produce:
1. Key insights (bullet list)
2. Three actionable strategies to improve business performance.
Be concise and insightful.
"""
strategy = gemini.generate_content(prompt).text
# ──────────────────────────────────────────────────────────────
# 5. DISPLAY RESULTS
# ──────────────────────────────────────────────────────────────
st.subheader("πŸ“‘ Data Summary")
st.text(summary_text)
if os.path.exists("sales_plot.png"):
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
if os.path.exists("forecast_plot.png"):
st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True)
st.subheader("πŸš€ Strategy Recommendations")
st.markdown(strategy)