Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# app.py โ BizIntelย AIย Ultra (Gemini
|
2 |
|
3 |
import os
|
4 |
import tempfile
|
@@ -8,21 +8,23 @@ import google.generativeai as genai
|
|
8 |
|
9 |
from tools.csv_parser import parse_csv_tool
|
10 |
from tools.plot_generator import plot_sales_tool
|
11 |
-
from tools.forecaster import forecast_tool #
|
12 |
|
13 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
14 |
# 1. GEMINI CONFIG (1.5โPro, temperature 0.7)
|
15 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
16 |
genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
|
17 |
gemini = genai.GenerativeModel(
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
)
|
23 |
|
24 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
25 |
-
# 2. STREAMLIT PAGE
|
26 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
27 |
st.set_page_config(page_title="BizIntel AI Ultra โ Geminiย 1.5ย Pro", layout="wide")
|
28 |
st.title("๐ BizIntelย AIย Ultraย โ Advanced Analytics Pipeline")
|
@@ -42,29 +44,25 @@ with open(csv_path, "wb") as f:
|
|
42 |
f.write(csv_file.read())
|
43 |
st.success("CSV saved to temporary storage โ
")
|
44 |
|
45 |
-
# Preview first rows
|
46 |
df_preview = pd.read_csv(csv_path, nrows=5)
|
47 |
st.dataframe(df_preview)
|
48 |
-
|
49 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
50 |
-
# 4. DATE COLUMN SELECTION
|
51 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
52 |
date_col = st.selectbox("Choose the date/time column for forecasting", df_preview.columns)
|
53 |
|
54 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
55 |
-
#
|
56 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
57 |
with st.spinner("๐ Parsing CSVโฆ"):
|
58 |
summary_text = parse_csv_tool(csv_path)
|
59 |
|
60 |
with st.spinner("๐ Generating sales trend chartโฆ"):
|
61 |
-
_ = plot_sales_tool(csv_path) #
|
62 |
|
63 |
with st.spinner("๐ฎ Forecasting future metricsโฆ"):
|
64 |
forecast_text = forecast_tool(csv_path, date_col=date_col) # pass chosen column
|
65 |
|
66 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
67 |
-
#
|
68 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
69 |
prompt = (
|
70 |
f"You are **BizIntel Strategist AI**.\n\n"
|
@@ -74,8 +72,8 @@ prompt = (
|
|
74 |
"Return Markdown with:\n"
|
75 |
"1. **Five key insights** (bullet list)\n"
|
76 |
"2. **Three actionable strategies** (with expected impact)\n"
|
77 |
-
"3. **Risk factors or anomalies
|
78 |
-
"4. **Suggested additional visuals
|
79 |
)
|
80 |
|
81 |
st.subheader("๐ Strategy Recommendations (Geminiย 1.5ย Pro)")
|
@@ -88,17 +86,13 @@ for chunk in gemini.generate_content_stream(prompt):
|
|
88 |
placeholder.markdown(strategy_md)
|
89 |
|
90 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
91 |
-
#
|
92 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
93 |
st.markdown("---")
|
94 |
st.subheader("๐ CSV Summary")
|
95 |
st.text(summary_text)
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
st.image(sales_plot_path, caption="Sales Trend", use_column_width=True)
|
102 |
-
|
103 |
-
if os.path.exists(forecast_plot_path):
|
104 |
-
st.image(forecast_plot_path, caption="Forecast Chart", use_column_width=True)
|
|
|
1 |
+
# app.py โ BizIntelย AIย Ultra (Geminiโฏ1.5ย Pro, selectable date column)
|
2 |
|
3 |
import os
|
4 |
import tempfile
|
|
|
8 |
|
9 |
from tools.csv_parser import parse_csv_tool
|
10 |
from tools.plot_generator import plot_sales_tool
|
11 |
+
from tools.forecaster import forecast_tool # accepts date_col
|
12 |
|
13 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
14 |
# 1. GEMINI CONFIG (1.5โPro, temperature 0.7)
|
15 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
16 |
genai.configure(api_key=os.getenv("GEMINI_APIKEY"))
|
17 |
gemini = genai.GenerativeModel(
|
18 |
+
"gemini-1.5-pro-latest",
|
19 |
+
generation_config={
|
20 |
+
"temperature": 0.7,
|
21 |
+
"top_p": 0.9,
|
22 |
+
"response_mime_type": "text/markdown",
|
23 |
+
},
|
24 |
)
|
25 |
|
26 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
27 |
+
# 2. STREAMLIT PAGE SETUP
|
28 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
29 |
st.set_page_config(page_title="BizIntel AI Ultra โ Geminiย 1.5ย Pro", layout="wide")
|
30 |
st.title("๐ BizIntelย AIย Ultraย โ Advanced Analytics Pipeline")
|
|
|
44 |
f.write(csv_file.read())
|
45 |
st.success("CSV saved to temporary storage โ
")
|
46 |
|
47 |
+
# Preview first rows and let user pick date column
|
48 |
df_preview = pd.read_csv(csv_path, nrows=5)
|
49 |
st.dataframe(df_preview)
|
|
|
|
|
|
|
|
|
50 |
date_col = st.selectbox("Choose the date/time column for forecasting", df_preview.columns)
|
51 |
|
52 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
53 |
+
# 4. LOCAL TOOL EXECUTION
|
54 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
55 |
with st.spinner("๐ Parsing CSVโฆ"):
|
56 |
summary_text = parse_csv_tool(csv_path)
|
57 |
|
58 |
with st.spinner("๐ Generating sales trend chartโฆ"):
|
59 |
+
_ = plot_sales_tool(csv_path) # generates sales_plot.png
|
60 |
|
61 |
with st.spinner("๐ฎ Forecasting future metricsโฆ"):
|
62 |
forecast_text = forecast_tool(csv_path, date_col=date_col) # pass chosen column
|
63 |
|
64 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
65 |
+
# 5. GEMINI 1.5โPRO STRATEGY (streaming)
|
66 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
67 |
prompt = (
|
68 |
f"You are **BizIntel Strategist AI**.\n\n"
|
|
|
72 |
"Return Markdown with:\n"
|
73 |
"1. **Five key insights** (bullet list)\n"
|
74 |
"2. **Three actionable strategies** (with expected impact)\n"
|
75 |
+
"3. **Risk factors or anomalies**\n"
|
76 |
+
"4. **Suggested additional visuals**\n"
|
77 |
)
|
78 |
|
79 |
st.subheader("๐ Strategy Recommendations (Geminiย 1.5ย Pro)")
|
|
|
86 |
placeholder.markdown(strategy_md)
|
87 |
|
88 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
89 |
+
# 6. DISPLAY SUMMARY & CHARTS
|
90 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
91 |
st.markdown("---")
|
92 |
st.subheader("๐ CSV Summary")
|
93 |
st.text(summary_text)
|
94 |
|
95 |
+
if os.path.exists("sales_plot.png"):
|
96 |
+
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
|
97 |
+
if os.path.exists("forecast_plot.png"):
|
98 |
+
st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True)
|
|
|
|
|
|
|
|