Spaces:
Sleeping
Sleeping
File size: 4,118 Bytes
2c362d2 309eec4 2c362d2 309eec4 10c7dea 309eec4 10c7dea 2c362d2 10c7dea 309eec4 2c362d2 309eec4 10c7dea 2c362d2 67e3963 309eec4 2c362d2 309eec4 2c362d2 67e3963 72a73ff 309eec4 2c362d2 309eec4 2c362d2 309eec4 2c362d2 309eec4 2c362d2 309eec4 10c7dea 2c362d2 309eec4 2c362d2 309eec4 2c362d2 10c7dea 309eec4 2c362d2 309eec4 2c362d2 10c7dea 2c362d2 10c7dea 2c362d2 67e3963 309eec4 2c362d2 309eec4 2c362d2 309eec4 2c362d2 |
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# app.py β BizIntel AI Ultra (GeminiΒ 1.5Β Pro, selectable date column)
import os
import tempfile
import pandas as pd
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 # must accept date_col param
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1. GEMINI CONFIG (1.5βpro, temperature 0.7)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
gemini = genai.GenerativeModel(
model="gemini-1.5-pro-latest",
temperature=0.7,
top_p=0.9,
response_mime_type="text/markdown",
)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 2. STREAMLIT PAGE SETUP
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
st.set_page_config(page_title="BizIntel AI Ultra β GeminiΒ 1.5Β Pro", layout="wide")
st.title("π BizIntelΒ AIΒ UltraΒ β Advanced Analytics Pipeline")
TEMP_DIR = tempfile.gettempdir()
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 3. CSV UPLOAD
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
csv_file = st.file_uploader("Upload a CSV file (β€β―200β―MB)", type=["csv"])
if not csv_file:
st.info("β¬οΈ Upload a CSV to begin.")
st.stop()
csv_path = os.path.join(TEMP_DIR, csv_file.name)
with open(csv_path, "wb") as f:
f.write(csv_file.read())
st.success("CSV saved to temporary storage β
")
# Preview first rows for column selection
df_preview = pd.read_csv(csv_path, nrows=5)
st.dataframe(df_preview)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 4. DATE COLUMN CHOICE
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
date_col = st.selectbox("Choose the date/time column for forecasting", df_preview.columns)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 5. RUN LOCAL TOOLS
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
with st.spinner("Parsing CSVβ¦"):
summary_text = parse_csv_tool(csv_path)
with st.spinner("Generating sales trend chartβ¦"):
trend_msg = plot_sales_tool(csv_path) # creates sales_plot.png
with st.spinner("Forecasting future metricsβ¦"):
forecast_text = forecast_tool(csv_path, date_col=date_col) # β passes chosen column
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 6. GEMINI 1.5βPRO STRATEGY (stream)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
prompt = f"""
You are BizIntel Strategist AI.
**CSV SUMMARY**
|