Spaces:
Sleeping
Sleeping
import os, tempfile, streamlit as st | |
from google.adk.runner import run_agent_sync # β NEW | |
from agents.analytics_pipeline import analytics_coordinator | |
from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES | |
st.set_page_config(page_title="BizIntel AI Ultra", layout="wide") | |
st.title("π BizIntel AI UltraΒ β Business Intelligence Agent") | |
TEMP_DIR = tempfile.gettempdir() | |
# ββ Data source βββββββββββββββββββββββββββββββββββββββββββββββ | |
src = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"]) | |
csv_path = None | |
if src == "Upload CSV": | |
up = st.file_uploader("Upload CSV", ["csv"]) | |
if up: | |
csv_path = os.path.join(TEMP_DIR, up.name) | |
with open(csv_path, "wb") as f: | |
f.write(up.read()) | |
st.success("CSV saved β ") | |
else: | |
eng = st.selectbox("DB engine", SUPPORTED_ENGINES) | |
conn = st.text_input("SQLAlchemy connection string") | |
if conn: | |
tbls = list_tables(conn) | |
tbl = st.selectbox("Table", tbls) if tbls else None | |
if tbl: | |
csv_path = fetch_data_from_db(conn, tbl) | |
st.success(f"Fetched **{tbl}** as CSV β ") | |
# ββ Optional image preview ββββββββββββββββββββββββββββββββββββ | |
st.markdown("---") | |
img = st.file_uploader("Optional image (PNG/JPG)", ["png", "jpg", "jpeg"]) | |
if img: | |
img_path = os.path.join(TEMP_DIR, img.name) | |
with open(img_path, "wb") as f: | |
f.write(img.read()) | |
st.image(img_path, use_column_width=True) | |
# ββ Run pipeline via ADK runner βββββββββββββββββββββββββββββββ | |
if csv_path: | |
st.markdown("---") | |
st.info("Running analytics pipelineβ¦") | |
try: | |
report = run_agent_sync(agent=analytics_coordinator, input_data=csv_path) | |
except Exception as e: | |
st.error(f"Agent execution failed: {e}") | |
st.stop() | |
st.subheader("π Analysis & Strategy Report") | |
st.text(report) | |
# Show charts if generated | |
for name, cap in [("sales_plot.png", "Sales Trend"), | |
("forecast_plot.png", "Forecast Chart")]: | |
p = os.path.join(TEMP_DIR, name) | |
if os.path.exists(p): | |
st.image(p, caption=cap, use_column_width=True) | |