Spaces:
Sleeping
Sleeping
File size: 4,089 Bytes
309eec4 10c7dea 309eec4 10c7dea 309eec4 10c7dea 309eec4 67e3963 309eec4 67e3963 72a73ff 309eec4 10c7dea 309eec4 10c7dea 309eec4 10c7dea 309eec4 10c7dea 309eec4 10c7dea 309eec4 10c7dea 309eec4 10c7dea 309eec4 67e3963 309eec4 67e3963 309eec4 |
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 74 75 76 77 78 79 |
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)
|