Spaces:
Sleeping
Sleeping
File size: 5,124 Bytes
318e286 2c362d2 309eec4 2c362d2 309eec4 10c7dea 309eec4 10c7dea 318e286 10c7dea 309eec4 523228c 309eec4 10c7dea 2c362d2 b3a1f0c 318e286 b3a1f0c 2c362d2 67e3963 309eec4 b3a1f0c 309eec4 2c362d2 67e3963 72a73ff 309eec4 2c362d2 309eec4 523228c d826a13 309eec4 2c362d2 309eec4 2c362d2 309eec4 10c7dea d826a13 2c362d2 d826a13 10c7dea 309eec4 b3a1f0c 309eec4 523228c 2c362d2 10c7dea 523228c 318e286 10c7dea 523228c d826a13 67e3963 309eec4 d826a13 309eec4 523228c d826a13 523228c b3a1f0c 523228c d826a13 523228c d826a13 523228c b3a1f0c 523228c b3a1f0c d826a13 b3a1f0c |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# app.py โ BizIntelย AIย Ultra (Geminiโฏ1.5ย Pro, selectable date column)
import os
import tempfile
import pandas as pd
import streamlit as st
import google.generativeai as genai
from tools.csv_parser import parse_csv_tool
from tools.plot_generator import plot_sales_tool
from tools.forecaster import forecast_tool # must accept date_col
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 1. GEMINI CONFIG (1.5โPro, temperature 0.7)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
gemini = genai.GenerativeModel(
"gemini-1.5-pro-latest",
generation_config={
"temperature": 0.7,
"top_p": 0.9,
# Allowed types: text/plain, application/json, etc.
"response_mime_type": "text/plain",
},
)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 2. STREAMLIT PAGE SETUP
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.set_page_config(page_title="BizIntel AI Ultra โ Geminiย 1.5ย Pro", layout="wide")
st.title("๐ BizIntelย AIย Ultraย โ Advanced Analytics Pipeline")
TEMP_DIR = tempfile.gettempdir()
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 3. CSV UPLOAD
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
csv_file = st.file_uploader("Upload CSV (โคโฏ200โฏMB)", type=["csv"])
if csv_file is None:
st.info("โฌ๏ธย Upload a CSV to begin.")
st.stop()
csv_path = os.path.join(TEMP_DIR, csv_file.name)
with open(csv_path, "wb") as f:
f.write(csv_file.read())
st.success("CSV saved to temporary storage โ
")
# Preview first rows and choose date column
df_preview = pd.read_csv(csv_path, nrows=5)
st.dataframe(df_preview)
date_col = st.selectbox("Select the date/time column for forecasting", df_preview.columns)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 4. LOCAL TOOL EXECUTION
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with st.spinner("๐ Parsing CSVโฆ"):
summary_text = parse_csv_tool(csv_path)
with st.spinner("๐ Generating sales trend chartโฆ"):
_ = plot_sales_tool(csv_path) # generates sales_plot.png
with st.spinner("๐ฎ Forecasting future metricsโฆ"):
forecast_text = forecast_tool(csv_path, date_col=date_col) # uses chosen column
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 5. GEMINI 1.5โPRO STRATEGY (sync call)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
prompt = (
f"You are **BizIntel Strategist AI**.\n\n"
f"## CSV Summary\n```\n{summary_text}\n```\n\n"
f"## Forecast Output\n```\n{forecast_text}\n```\n\n"
"### Task\n"
"Return **Markdown** with:\n"
"1. **Five key insights** (bullet list)\n"
"2. **Three actionable strategies** (with expected impact)\n"
"3. **Risk factors or anomalies**\n"
"4. **Suggested additional visuals**\n"
)
st.subheader("๐ Strategy Recommendations (Geminiย 1.5ย Pro)")
with st.spinner("Geminiย 1.5ย Pro is thinkingโฆ"):
response = gemini.generate_content(prompt)
strategy_md = response.text
st.markdown(strategy_md)
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# 6. DISPLAY SUMMARY & CHARTS
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
st.markdown("---")
st.subheader("๐ CSV Summary")
st.text(summary_text)
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)
|