Spaces:
Sleeping
Sleeping
File size: 4,073 Bytes
72a73ff 67e3963 72a73ff 2683b5b 72a73ff 67e3963 b411743 67e3963 2683b5b 72a73ff b411743 2683b5b b411743 67e3963 72a73ff 67e3963 2683b5b 72a73ff 2683b5b 67e3963 b411743 67e3963 72a73ff b411743 2683b5b b411743 72a73ff b411743 67e3963 72a73ff 2683b5b b411743 2683b5b b411743 72a73ff b411743 72a73ff 2683b5b b411743 72a73ff 67e3963 2683b5b 72a73ff |
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
from agents.analytics_pipeline import analytics_coordinator
from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# PAGE CONFIG
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
st.set_page_config(page_title="BizIntel AI Ultra", layout="wide")
st.title("π BizIntel AI UltraΒ β Business Intelligence Agent")
# Writable directory inside HuggingΒ Face container
TEMP_DIR = tempfile.gettempdir()
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1. DATA SOURCE SELECTION (CSV or DB)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
input_source = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"])
csv_path: str | None = None
if input_source == "Upload CSV":
uploaded_csv = st.file_uploader("Upload CSV", type="csv")
if uploaded_csv:
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 β
")
elif input_source == "Connect to SQL Database":
engine = st.selectbox("Database engine", SUPPORTED_ENGINES)
conn_str = st.text_input("SQLAlchemy connection string")
if conn_str:
tables = list_tables(conn_str)
if tables:
table_name = st.selectbox("Choose a table", tables)
if table_name:
csv_path = fetch_data_from_db(conn_str, table_name)
st.success(f"Fetched **{table_name}** as CSV β
")
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 2. OPTIONAL IMAGE UPLOAD & PREVIEW
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
st.markdown("---")
st.subheader("π· Optional: Upload an Image for Preview / Future Analysis")
img_file = st.file_uploader(
"Upload an image (PNG/JPG)", type=["png", "jpg", "jpeg"], key="img"
)
if img_file:
img_path = os.path.join(TEMP_DIR, img_file.name)
with open(img_path, "wb") as f:
f.write(img_file.read())
st.image(img_path, caption="Uploaded Image", use_column_width=True)
# πΒ To analyse with a vision agent later, call it here with `img_path`.
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 3. RUN ANALYTICS PIPELINE
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
if csv_path:
st.markdown("---")
st.info("Running analytics pipelineβ¦ β³")
# Google ADK agents now use .invoke() (sync) instead of .run()
report = analytics_coordinator.invoke(input=csv_path)
st.subheader("π Analysis & Strategy Report")
st.text(report)
# Display charts saved by tool functions (if any)
for plot_name, caption in [
("sales_plot.png", "Sales Trend"),
("forecast_plot.png", "Forecast Chart"),
]:
plot_path = os.path.join(TEMP_DIR, plot_name)
if os.path.exists(plot_path):
st.image(plot_path, caption=caption, use_column_width=True)
|