Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
-
|
2 |
import streamlit as st
|
3 |
from agents.analytics_pipeline import analytics_coordinator
|
4 |
import os
|
5 |
from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES
|
6 |
|
7 |
st.set_page_config(page_title="BizIntel AI Ultra", layout="wide")
|
8 |
-
st.title("π BizIntel AI Ultra
|
9 |
|
|
|
|
|
|
|
10 |
input_source = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"])
|
11 |
file_path = None
|
12 |
|
@@ -16,25 +18,50 @@ if input_source == "Upload CSV":
|
|
16 |
file_path = os.path.join("data", uploaded_file.name)
|
17 |
with open(file_path, "wb") as f:
|
18 |
f.write(uploaded_file.read())
|
19 |
-
st.success("
|
20 |
|
21 |
elif input_source == "Connect to SQL Database":
|
22 |
-
engine = st.selectbox("
|
23 |
-
conn_str = st.text_input("
|
24 |
if conn_str:
|
25 |
tables = list_tables(conn_str)
|
26 |
if tables:
|
27 |
table_name = st.selectbox("Choose a table", tables)
|
28 |
if table_name:
|
29 |
file_path = fetch_data_from_db(conn_str, table_name)
|
30 |
-
st.success(f"Fetched
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
if file_path:
|
33 |
-
st.
|
|
|
34 |
result = analytics_coordinator.run(input=file_path)
|
35 |
-
|
|
|
36 |
st.text(result)
|
37 |
|
|
|
38 |
if os.path.exists("sales_plot.png"):
|
39 |
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
|
40 |
if os.path.exists("forecast_plot.png"):
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from agents.analytics_pipeline import analytics_coordinator
|
3 |
import os
|
4 |
from db_connector import fetch_data_from_db, list_tables, SUPPORTED_ENGINES
|
5 |
|
6 |
st.set_page_config(page_title="BizIntel AI Ultra", layout="wide")
|
7 |
+
st.title("π BizIntel AI UltraΒ β Business Intelligence Agent")
|
8 |
|
9 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
10 |
+
# βΆ DATA SOURCE SELECTION (CSVΒ orΒ Database)
|
11 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
12 |
input_source = st.radio("Select data source", ["Upload CSV", "Connect to SQL Database"])
|
13 |
file_path = None
|
14 |
|
|
|
18 |
file_path = os.path.join("data", uploaded_file.name)
|
19 |
with open(file_path, "wb") as f:
|
20 |
f.write(uploaded_file.read())
|
21 |
+
st.success("CSV file uploaded β
")
|
22 |
|
23 |
elif input_source == "Connect to SQL Database":
|
24 |
+
engine = st.selectbox("Database engine", SUPPORTED_ENGINES)
|
25 |
+
conn_str = st.text_input("SQLAlchemy connection string")
|
26 |
if conn_str:
|
27 |
tables = list_tables(conn_str)
|
28 |
if tables:
|
29 |
table_name = st.selectbox("Choose a table", tables)
|
30 |
if table_name:
|
31 |
file_path = fetch_data_from_db(conn_str, table_name)
|
32 |
+
st.success(f"Fetched **{table_name}** as CSV β
")
|
33 |
+
|
34 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
35 |
+
# β· OPTIONALΒ IMAGEΒ UPLOADΒ +Β PREVIEW
|
36 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
37 |
+
st.markdown("---")
|
38 |
+
st.subheader("π· Optional: Upload an Image for Preview / Future Analysis")
|
39 |
+
|
40 |
+
uploaded_image = st.file_uploader(
|
41 |
+
"Upload an image (PNG orΒ JPG)", type=["png", "jpg", "jpeg"], key="img"
|
42 |
+
)
|
43 |
|
44 |
+
if uploaded_image is not None:
|
45 |
+
image_path = os.path.join("data", uploaded_image.name)
|
46 |
+
with open(image_path, "wb") as f:
|
47 |
+
f.write(uploaded_image.read())
|
48 |
+
st.image(image_path, caption="Uploaded Image", use_column_width=True)
|
49 |
+
|
50 |
+
# πΒ If you later want to pass the image to an agent, you can add code here
|
51 |
+
# e.g.Β result = image_analysis_agent.run(input=image_path)
|
52 |
+
|
53 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
54 |
+
# βΈ RUNΒ BUSINESSΒ ANALYTICSΒ PIPELINE
|
55 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
56 |
if file_path:
|
57 |
+
st.markdown("---")
|
58 |
+
st.info("Running analytics pipelineβ¦ β³")
|
59 |
result = analytics_coordinator.run(input=file_path)
|
60 |
+
|
61 |
+
st.subheader("π Analysis & Strategy Report")
|
62 |
st.text(result)
|
63 |
|
64 |
+
# Display generated charts if they exist
|
65 |
if os.path.exists("sales_plot.png"):
|
66 |
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
|
67 |
if os.path.exists("forecast_plot.png"):
|