File size: 1,642 Bytes
67e3963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import streamlit as st
from agents.analytics_pipeline import analytics_coordinator
import os
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 - Ultimate Business Intelligence")

input_source = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"])
file_path = None

if input_source == "Upload CSV":
    uploaded_file = st.file_uploader("Upload CSV", type="csv")
    if uploaded_file:
        file_path = os.path.join("data", uploaded_file.name)
        with open(file_path, "wb") as f:
            f.write(uploaded_file.read())
        st.success("File uploaded.")

elif input_source == "Connect to SQL Database":
    engine = st.selectbox("Select database engine", SUPPORTED_ENGINES)
    conn_str = st.text_input("Connection string (SQLAlchemy format)")
    if conn_str:
        tables = list_tables(conn_str)
        if tables:
            table_name = st.selectbox("Choose a table", tables)
            if table_name:
                file_path = fetch_data_from_db(conn_str, table_name)
                st.success(f"Fetched table '{table_name}' as CSV.")

if file_path:
    st.info("Running analytics pipeline...")
    result = analytics_coordinator.run(input=file_path)
    st.subheader("Analysis & Strategy Report")
    st.text(result)

    if os.path.exists("sales_plot.png"):
        st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
    if os.path.exists("forecast_plot.png"):
        st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True)