Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
import os, tempfile, streamlit as st
|
|
|
2 |
from agents.analytics_pipeline import analytics_coordinator
|
3 |
from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES
|
4 |
|
@@ -7,11 +8,11 @@ st.title("π BizIntel AI UltraΒ β Business Intelligence Agent")
|
|
7 |
|
8 |
TEMP_DIR = tempfile.gettempdir()
|
9 |
|
10 |
-
# ββ
|
11 |
-
|
12 |
csv_path = None
|
13 |
|
14 |
-
if
|
15 |
up = st.file_uploader("Upload CSV", ["csv"])
|
16 |
if up:
|
17 |
csv_path = os.path.join(TEMP_DIR, up.name)
|
@@ -20,49 +21,31 @@ if source == "Upload CSV":
|
|
20 |
st.success("CSV saved β
")
|
21 |
|
22 |
else:
|
23 |
-
|
24 |
conn = st.text_input("SQLAlchemy connection string")
|
25 |
if conn:
|
26 |
-
|
27 |
-
|
28 |
-
if
|
29 |
-
csv_path = fetch_data_from_db(conn,
|
30 |
-
st.success(f"Fetched **{
|
31 |
|
32 |
-
# ββ
|
33 |
st.markdown("---")
|
34 |
img = st.file_uploader("Optional image (PNG/JPG)", ["png", "jpg", "jpeg"])
|
35 |
if img:
|
36 |
-
|
37 |
-
with open(
|
38 |
f.write(img.read())
|
39 |
-
st.image(
|
40 |
|
41 |
-
# ββ
|
42 |
if csv_path:
|
43 |
st.markdown("---")
|
44 |
st.info("Running analytics pipelineβ¦")
|
45 |
|
46 |
-
# Discover an executable method
|
47 |
-
cand_methods = ["invoke", "run", "execute", "chat", "__call__"]
|
48 |
-
exec_fn = None
|
49 |
-
for m in cand_methods:
|
50 |
-
if hasattr(analytics_coordinator, m) and callable(getattr(analytics_coordinator, m)):
|
51 |
-
exec_fn = getattr(analytics_coordinator, m)
|
52 |
-
break
|
53 |
-
|
54 |
-
if exec_fn is None:
|
55 |
-
st.error("Cannot find an execution method on LlmAgent. Available attrs:\n"
|
56 |
-
+ ", ".join(dir(analytics_coordinator)))
|
57 |
-
st.stop()
|
58 |
-
|
59 |
-
# Determine if function expects keyword or positional arg
|
60 |
-
sig = inspect.signature(exec_fn)
|
61 |
try:
|
62 |
-
|
63 |
-
report = exec_fn(input=csv_path)
|
64 |
-
else:
|
65 |
-
report = exec_fn(csv_path)
|
66 |
except Exception as e:
|
67 |
st.error(f"Agent execution failed: {e}")
|
68 |
st.stop()
|
@@ -70,8 +53,9 @@ if csv_path:
|
|
70 |
st.subheader("π Analysis & Strategy Report")
|
71 |
st.text(report)
|
72 |
|
73 |
-
# Show charts if
|
74 |
-
for name, cap in [("sales_plot.png", "Sales Trend"),
|
|
|
75 |
p = os.path.join(TEMP_DIR, name)
|
76 |
if os.path.exists(p):
|
77 |
st.image(p, caption=cap, use_column_width=True)
|
|
|
1 |
+
import os, tempfile, streamlit as st
|
2 |
+
from google.adk.runner import run_agent_sync # β NEW
|
3 |
from agents.analytics_pipeline import analytics_coordinator
|
4 |
from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES
|
5 |
|
|
|
8 |
|
9 |
TEMP_DIR = tempfile.gettempdir()
|
10 |
|
11 |
+
# ββ Data source βββββββββββββββββββββββββββββββββββββββββββββββ
|
12 |
+
src = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"])
|
13 |
csv_path = None
|
14 |
|
15 |
+
if src == "Upload CSV":
|
16 |
up = st.file_uploader("Upload CSV", ["csv"])
|
17 |
if up:
|
18 |
csv_path = os.path.join(TEMP_DIR, up.name)
|
|
|
21 |
st.success("CSV saved β
")
|
22 |
|
23 |
else:
|
24 |
+
eng = st.selectbox("DB engine", SUPPORTED_ENGINES)
|
25 |
conn = st.text_input("SQLAlchemy connection string")
|
26 |
if conn:
|
27 |
+
tbls = list_tables(conn)
|
28 |
+
tbl = st.selectbox("Table", tbls) if tbls else None
|
29 |
+
if tbl:
|
30 |
+
csv_path = fetch_data_from_db(conn, tbl)
|
31 |
+
st.success(f"Fetched **{tbl}** as CSV β
")
|
32 |
|
33 |
+
# ββ Optional image preview ββββββββββββββββββββββββββββββββββββ
|
34 |
st.markdown("---")
|
35 |
img = st.file_uploader("Optional image (PNG/JPG)", ["png", "jpg", "jpeg"])
|
36 |
if img:
|
37 |
+
img_path = os.path.join(TEMP_DIR, img.name)
|
38 |
+
with open(img_path, "wb") as f:
|
39 |
f.write(img.read())
|
40 |
+
st.image(img_path, use_column_width=True)
|
41 |
|
42 |
+
# ββ Run pipeline via ADK runner βββββββββββββββββββββββββββββββ
|
43 |
if csv_path:
|
44 |
st.markdown("---")
|
45 |
st.info("Running analytics pipelineβ¦")
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
try:
|
48 |
+
report = run_agent_sync(agent=analytics_coordinator, input_data=csv_path)
|
|
|
|
|
|
|
49 |
except Exception as e:
|
50 |
st.error(f"Agent execution failed: {e}")
|
51 |
st.stop()
|
|
|
53 |
st.subheader("π Analysis & Strategy Report")
|
54 |
st.text(report)
|
55 |
|
56 |
+
# Show charts if generated
|
57 |
+
for name, cap in [("sales_plot.png", "Sales Trend"),
|
58 |
+
("forecast_plot.png", "Forecast Chart")]:
|
59 |
p = os.path.join(TEMP_DIR, name)
|
60 |
if os.path.exists(p):
|
61 |
st.image(p, caption=cap, use_column_width=True)
|