Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,78 @@
|
|
1 |
-
import os
|
|
|
|
|
2 |
import google.generativeai as genai
|
|
|
3 |
from tools.csv_parser import parse_csv_tool
|
4 |
from tools.plot_generator import plot_sales_tool
|
5 |
from tools.forecaster import forecast_tool
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
9 |
genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
TEMP_DIR = tempfile.gettempdir()
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
st.text(summary)
|
47 |
|
48 |
-
|
49 |
-
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
|
50 |
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
st.
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import tempfile
|
3 |
+
import streamlit as st
|
4 |
import google.generativeai as genai
|
5 |
+
|
6 |
from tools.csv_parser import parse_csv_tool
|
7 |
from tools.plot_generator import plot_sales_tool
|
8 |
from tools.forecaster import forecast_tool
|
9 |
|
10 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
11 |
+
# 0. CONFIGURE GEMINI
|
12 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
13 |
genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
|
14 |
+
gemini = genai.GenerativeModel("gemini-pro")
|
15 |
|
16 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
17 |
+
# 1. STREAMLIT SETUP
|
18 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
19 |
+
st.set_page_config(page_title="BizIntel AI Ultra β Lite", layout="wide")
|
20 |
+
st.title("π BizIntel AI UltraΒ β Quick Analytics Pipeline")
|
21 |
|
22 |
TEMP_DIR = tempfile.gettempdir()
|
23 |
|
24 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
25 |
+
# 2. CSV UPLOAD
|
26 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
27 |
+
uploaded_csv = st.file_uploader("Upload a CSV file", type=["csv"])
|
28 |
+
if not uploaded_csv:
|
29 |
+
st.info("Upload a CSV to begin.")
|
30 |
+
st.stop()
|
31 |
+
|
32 |
+
csv_path = os.path.join(TEMP_DIR, uploaded_csv.name)
|
33 |
+
with open(csv_path, "wb") as f:
|
34 |
+
f.write(uploaded_csv.read())
|
35 |
+
st.success("CSV saved to temporary storage β
")
|
36 |
|
37 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
38 |
+
# 3. LOCAL TOOL PROCESSING
|
39 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
40 |
+
summary_text = parse_csv_tool(csv_path)
|
41 |
+
plot_msg = plot_sales_tool(csv_path) # creates sales_plot.png
|
42 |
+
forecast_text = forecast_tool(csv_path) # creates forecast_plot.png
|
43 |
|
44 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
45 |
+
# 4. GEMINI STRATEGY GENERATION
|
46 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
47 |
+
prompt = f"""
|
48 |
+
You are BizIntel Strategist AI.
|
49 |
|
50 |
+
CSV SUMMARY:
|
51 |
+
{summary_text}
|
52 |
|
53 |
+
FORECAST OUTPUT:
|
54 |
+
{forecast_text}
|
55 |
|
56 |
+
Using the data above, produce:
|
57 |
+
1. Key insights (bullet list)
|
58 |
+
2. Three actionable strategies to improve business performance.
|
59 |
|
60 |
+
Be concise and insightful.
|
61 |
+
"""
|
|
|
62 |
|
63 |
+
strategy = gemini.generate_content(prompt).text
|
|
|
64 |
|
65 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
66 |
+
# 5. DISPLAY RESULTS
|
67 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½βββββββ
|
68 |
+
st.subheader("π Data Summary")
|
69 |
+
st.text(summary_text)
|
70 |
|
71 |
+
if os.path.exists("sales_plot.png"):
|
72 |
+
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
|
73 |
+
|
74 |
+
if os.path.exists("forecast_plot.png"):
|
75 |
+
st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True)
|
76 |
+
|
77 |
+
st.subheader("π Strategy Recommendations")
|
78 |
+
st.markdown(strategy)
|