File size: 2,412 Bytes
8171765
 
67e3963
 
 
 
b411743
67e3963
72a73ff
 
8171765
 
0472dbd
67e3963
8171765
0472dbd
 
 
72a73ff
0472dbd
5cc8a1b
67e3963
0472dbd
8171765
5cc8a1b
 
8171765
 
 
 
 
b411743
8171765
b411743
0472dbd
5cc8a1b
8171765
 
5cc8a1b
8171765
b411743
8171765
72a73ff
b411743
0472dbd
 
 
8171765
0472dbd
 
 
b411743
 
72a73ff
67e3963
8171765
 
 
5cc8a1b
 
0472dbd
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
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)