Spaces:
Sleeping
Sleeping
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) | |