Spaces:
Sleeping
Sleeping
File size: 1,687 Bytes
10c7dea 67e3963 10c7dea 67e3963 72a73ff 10c7dea 67e3963 10c7dea 67e3963 10c7dea 0472dbd 10c7dea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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.")
|