Spaces:
Sleeping
Sleeping
import os, tempfile, streamlit as st, pandas as pd | |
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 | |
# Configure Gemini | |
import os | |
genai.configure(api_key=os.getenv("GEMINI_APIKEY")) | |
model = genai.GenerativeModel("gemini-pro") | |
st.set_page_config(page_title="BizIntel AI Ultra", layout="wide") | |
st.title("π BizIntel AI UltraΒ β Emergency Pipeline") | |
TEMP_DIR = tempfile.gettempdir() | |
# 1. CSV upload | |
csv = st.file_uploader("Upload CSV", ["csv"]) | |
if csv: | |
csv_path = os.path.join(TEMP_DIR, csv.name) | |
with open(csv_path, "wb") as f: | |
f.write(csv.read()) | |
st.success("CSV saved β ") | |
# 2. Run local tools | |
summary = parse_csv_tool(csv_path) | |
plot_msg = plot_sales_tool(csv_path) | |
forecast_msg = forecast_tool(csv_path) | |
# 3. Strategy via Gemini | |
prompt = f""" | |
You are a business strategist AI. | |
CSV SUMMARY: | |
{summary} | |
FORECAST: | |
{forecast_msg} | |
Provide key insights and 3 actionable strategies. | |
""" | |
strat = model.generate_content(prompt).text | |
# 4. Display results | |
st.subheader("π Data Summary") | |
st.text(summary) | |
if "Generated sales_plot.png" in plot_msg and os.path.exists("sales_plot.png"): | |
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True) | |
if "Generated forecast_plot.png" in forecast_msg and os.path.exists("forecast_plot.png"): | |
st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True) | |
st.subheader("π Strategy Recommendations") | |
st.markdown(strat) | |
else: | |
st.info("Upload a CSV to begin.") | |