Spaces:
Sleeping
Sleeping
Download app.py from mgbam/BizIntel_AI: direct link, hf CLI and curl.
- Browser
- Download file 3.58 kB
-
https://huggingface.co/spaces/mgbam/BizIntel_AI/resolve/a2cba7a311811db5d8b0c6488f74628de03b7f56/app.py
- Command line
-
hf download hf://spaces/mgbam/BizIntel_AI@a2cba7a311811db5d8b0c6488f74628de03b7f56/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mgbam/BizIntel_AI/resolve/a2cba7a311811db5d8b0c6488f74628de03b7f56/app.py
3.58 kB
| 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Β β Business Intelligence Agent") | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # βΆ DATA SOURCE SELECTION (CSVΒ orΒ Database) | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| 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("CSV file uploaded β ") | |
| 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: | |
| file_path = fetch_data_from_db(conn_str, table_name) | |
| st.success(f"Fetched **{table_name}** as CSV β ") | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # β· OPTIONALΒ IMAGEΒ UPLOADΒ +Β PREVIEW | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| st.markdown("---") | |
| st.subheader("π· Optional: Upload an Image for Preview / Future Analysis") | |
| uploaded_image = st.file_uploader( | |
| "Upload an image (PNG orΒ JPG)", type=["png", "jpg", "jpeg"], key="img" | |
| ) | |
| if uploaded_image is not None: | |
| image_path = os.path.join("data", uploaded_image.name) | |
| with open(image_path, "wb") as f: | |
| f.write(uploaded_image.read()) | |
| st.image(image_path, caption="Uploaded Image", use_column_width=True) | |
| # πΒ If you later want to pass the image to an agent, you can add code here | |
| # e.g.Β result = image_analysis_agent.run(input=image_path) | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # βΈ RUNΒ BUSINESSΒ ANALYTICSΒ PIPELINE | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| if file_path: | |
| st.markdown("---") | |
| st.info("Running analytics pipelineβ¦ β³") | |
| result = analytics_coordinator.run(input=file_path) | |
| st.subheader("π Analysis & Strategy Report") | |
| st.text(result) | |
| # Display generated charts if they exist | |
| 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) | |