mgbam commited on
Commit
2683b5b
Β·
verified Β·
1 Parent(s): 72a73ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -5,27 +5,27 @@ from agents.analytics_pipeline import analytics_coordinator
5
  from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES
6
 
7
  # ──────────────────────────────────────────────────────────────
8
- # 0. PAGE CONFIG
9
  # ──────────────────────────────────────────────────────────────
10
  st.set_page_config(page_title="BizIntel AI Ultra", layout="wide")
11
  st.title("πŸ“Š BizIntel AI Ultra – Business Intelligence Agent")
12
 
13
- # Where we'll store any uploaded files (always writable in HF Spaces)
14
  TEMP_DIR = tempfile.gettempdir()
15
 
16
  # ──────────────────────────────────────────────────────────────
17
- # 1. DATA SOURCE SELECTION
18
  # ──────────────────────────────────────────────────────────────
19
  input_source = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"])
20
  csv_path: str | None = None
21
 
22
  if input_source == "Upload CSV":
23
- uploaded_file = st.file_uploader("Upload CSV", type="csv")
24
- if uploaded_file:
25
- csv_path = os.path.join(TEMP_DIR, uploaded_file.name)
26
  with open(csv_path, "wb") as f:
27
- f.write(uploaded_file.read())
28
- st.success("CSV file saved to temporary storage βœ…")
29
 
30
  elif input_source == "Connect to SQL Database":
31
  engine = st.selectbox("Database engine", SUPPORTED_ENGINES)
@@ -39,7 +39,7 @@ elif input_source == "Connect to SQL Database":
39
  st.success(f"Fetched **{table_name}** as CSV βœ…")
40
 
41
  # ──────────────────────────────────────────────────────────────
42
- # 2. OPTIONAL IMAGE UPLOAD & PREVIEW
43
  # ──────────────────────────────────────────────────────────────
44
  st.markdown("---")
45
  st.subheader("πŸ“· Optional: Upload an Image for Preview / Future Analysis")
@@ -53,21 +53,22 @@ if img_file:
53
  with open(img_path, "wb") as f:
54
  f.write(img_file.read())
55
  st.image(img_path, caption="Uploaded Image", use_column_width=True)
56
- # πŸ‘‰ Future hook: pass `img_path` to a vision agent here.
57
 
58
  # ──────────────────────────────────────────────────────────────
59
- # 3. RUN ANALYTICS PIPELINE
60
  # ──────────────────────────────────────────────────────────────
61
  if csv_path:
62
  st.markdown("---")
63
  st.info("Running analytics pipeline… ⏳")
64
 
65
- report = analytics_coordinator.run(input=csv_path)
 
66
 
67
  st.subheader("πŸ“ Analysis & Strategy Report")
68
  st.text(report)
69
 
70
- # Show charts generated by tool functions if present
71
  for plot_name, caption in [
72
  ("sales_plot.png", "Sales Trend"),
73
  ("forecast_plot.png", "Forecast Chart"),
 
5
  from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES
6
 
7
  # ──────────────────────────────────────────────────────────────
8
+ # PAGE CONFIG
9
  # ──────────────────────────────────────────────────────────────
10
  st.set_page_config(page_title="BizIntel AI Ultra", layout="wide")
11
  st.title("πŸ“Š BizIntel AI Ultra – Business Intelligence Agent")
12
 
13
+ # Writable directory inside HuggingΒ Face container
14
  TEMP_DIR = tempfile.gettempdir()
15
 
16
  # ──────────────────────────────────────────────────────────────
17
+ # 1. DATA SOURCE SELECTION (CSV or DB)
18
  # ──────────────────────────────────────────────────────────────
19
  input_source = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"])
20
  csv_path: str | None = None
21
 
22
  if input_source == "Upload CSV":
23
+ uploaded_csv = st.file_uploader("Upload CSV", type="csv")
24
+ if uploaded_csv:
25
+ csv_path = os.path.join(TEMP_DIR, uploaded_csv.name)
26
  with open(csv_path, "wb") as f:
27
+ f.write(uploaded_csv.read())
28
+ st.success("CSV saved to temporary storage βœ…")
29
 
30
  elif input_source == "Connect to SQL Database":
31
  engine = st.selectbox("Database engine", SUPPORTED_ENGINES)
 
39
  st.success(f"Fetched **{table_name}** as CSV βœ…")
40
 
41
  # ──────────────────────────────────────────────────────────────
42
+ # 2. OPTIONAL IMAGE UPLOAD & PREVIEW
43
  # ──────────────────────────────────────────────────────────────
44
  st.markdown("---")
45
  st.subheader("πŸ“· Optional: Upload an Image for Preview / Future Analysis")
 
53
  with open(img_path, "wb") as f:
54
  f.write(img_file.read())
55
  st.image(img_path, caption="Uploaded Image", use_column_width=True)
56
+ # πŸ‘‰Β To analyse with a vision agent later, call it here with `img_path`.
57
 
58
  # ──────────────────────────────────────────────────────────────
59
+ # 3. RUN ANALYTICS PIPELINE
60
  # ──────────────────────────────────────────────────────────────
61
  if csv_path:
62
  st.markdown("---")
63
  st.info("Running analytics pipeline… ⏳")
64
 
65
+ # Google ADK agents now use .invoke() (sync) instead of .run()
66
+ report = analytics_coordinator.invoke(input=csv_path)
67
 
68
  st.subheader("πŸ“ Analysis & Strategy Report")
69
  st.text(report)
70
 
71
+ # Display charts saved by tool functions (if any)
72
  for plot_name, caption in [
73
  ("sales_plot.png", "Sales Trend"),
74
  ("forecast_plot.png", "Forecast Chart"),