Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# app.py โ BizIntelย AIย Ultra (Geminiโฏ1.5ย Pro,
|
2 |
|
3 |
import os
|
4 |
import tempfile
|
@@ -8,7 +8,7 @@ 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 # accepts date_col
|
12 |
|
13 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
14 |
# 1. GEMINI CONFIG (1.5โPro, temperature 0.7)
|
@@ -36,7 +36,7 @@ TEMP_DIR = tempfile.gettempdir()
|
|
36 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
37 |
csv_file = st.file_uploader("Upload CSV (โคโฏ200โฏMB)", type=["csv"])
|
38 |
if csv_file is None:
|
39 |
-
st.info("โฌ๏ธ
|
40 |
st.stop()
|
41 |
|
42 |
csv_path = os.path.join(TEMP_DIR, csv_file.name)
|
@@ -44,10 +44,10 @@ with open(csv_path, "wb") as f:
|
|
44 |
f.write(csv_file.read())
|
45 |
st.success("CSV saved to temporary storage โ
")
|
46 |
|
47 |
-
# Preview first rows and
|
48 |
df_preview = pd.read_csv(csv_path, nrows=5)
|
49 |
st.dataframe(df_preview)
|
50 |
-
date_col = st.selectbox("
|
51 |
|
52 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
53 |
# 4. LOCAL TOOL EXECUTION
|
@@ -56,20 +56,20 @@ 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) #
|
60 |
|
61 |
with st.spinner("๐ฎ Forecasting future metricsโฆ"):
|
62 |
-
forecast_text = forecast_tool(csv_path, date_col=date_col) #
|
63 |
|
64 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
65 |
-
# 5. GEMINI 1.5โPRO STRATEGY (
|
66 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
67 |
prompt = (
|
68 |
f"You are **BizIntel Strategist AI**.\n\n"
|
69 |
f"## CSV Summary\n```\n{summary_text}\n```\n\n"
|
70 |
f"## Forecast Output\n```\n{forecast_text}\n```\n\n"
|
71 |
"### Task\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"
|
@@ -77,13 +77,11 @@ prompt = (
|
|
77 |
)
|
78 |
|
79 |
st.subheader("๐ Strategy Recommendations (Geminiย 1.5ย Pro)")
|
80 |
-
|
81 |
-
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
strategy_md += chunk.candidate.content.parts[0].text
|
86 |
-
placeholder.markdown(strategy_md)
|
87 |
|
88 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
89 |
# 6. DISPLAY SUMMARY & CHARTS
|
@@ -94,5 +92,6 @@ 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)
|
|
|
1 |
+
# app.py โ BizIntelย AIย Ultra (Geminiโฏ1.5ย Pro, dateโcolumn selector)
|
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 argument
|
12 |
|
13 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
14 |
# 1. GEMINI CONFIG (1.5โPro, temperature 0.7)
|
|
|
36 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
37 |
csv_file = st.file_uploader("Upload CSV (โคโฏ200โฏMB)", type=["csv"])
|
38 |
if csv_file is None:
|
39 |
+
st.info("โฌ๏ธย Upload a CSV to begin.")
|
40 |
st.stop()
|
41 |
|
42 |
csv_path = os.path.join(TEMP_DIR, csv_file.name)
|
|
|
44 |
f.write(csv_file.read())
|
45 |
st.success("CSV saved to temporary storage โ
")
|
46 |
|
47 |
+
# Preview first rows and choose date column
|
48 |
df_preview = pd.read_csv(csv_path, nrows=5)
|
49 |
st.dataframe(df_preview)
|
50 |
+
date_col = st.selectbox("Select the date/time column for forecasting", df_preview.columns)
|
51 |
|
52 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
53 |
# 4. LOCAL TOOL EXECUTION
|
|
|
56 |
summary_text = parse_csv_tool(csv_path)
|
57 |
|
58 |
with st.spinner("๐ Generating sales trend chartโฆ"):
|
59 |
+
_ = plot_sales_tool(csv_path) # saves sales_plot.png
|
60 |
|
61 |
with st.spinner("๐ฎ Forecasting future metricsโฆ"):
|
62 |
+
forecast_text = forecast_tool(csv_path, date_col=date_col) # uses chosen column
|
63 |
|
64 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
65 |
+
# 5. GEMINI 1.5โPRO STRATEGY (sync call)
|
66 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
67 |
prompt = (
|
68 |
f"You are **BizIntel Strategist AI**.\n\n"
|
69 |
f"## CSV Summary\n```\n{summary_text}\n```\n\n"
|
70 |
f"## Forecast Output\n```\n{forecast_text}\n```\n\n"
|
71 |
"### Task\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"
|
|
|
77 |
)
|
78 |
|
79 |
st.subheader("๐ Strategy Recommendations (Geminiย 1.5ย Pro)")
|
80 |
+
with st.spinner("Geminiย 1.5ย Pro is thinkingโฆ"):
|
81 |
+
response = gemini.generate_content(prompt)
|
82 |
|
83 |
+
strategy_md = response.text
|
84 |
+
st.markdown(strategy_md)
|
|
|
|
|
85 |
|
86 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
87 |
# 6. DISPLAY SUMMARY & CHARTS
|
|
|
92 |
|
93 |
if os.path.exists("sales_plot.png"):
|
94 |
st.image("sales_plot.png", caption="Sales Trend", use_column_width=True)
|
95 |
+
|
96 |
if os.path.exists("forecast_plot.png"):
|
97 |
st.image("forecast_plot.png", caption="Forecast Chart", use_column_width=True)
|