Shadatsh commited on
Commit
e563c54
·
verified ·
1 Parent(s): 529c49c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +67 -0
  2. forecastData.csv +366 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import openai
4
+ import os
5
+ from dotenv import load_dotenv
6
+ from datetime import datetime, timedelta
7
+
8
+ load_dotenv()
9
+
10
+ # Set OpenAI API key
11
+ openai.api_key = os.getenv("OPENAI_API_KEY")
12
+
13
+ # Load CSV file
14
+ df = pd.read_csv(r"C:\Users\sadac\OneDrive\Desktop\salesforecast-chatbot\forecastData.csv")
15
+ df['Date'] = pd.to_datetime(df['Date']) # Ensure Date is in datetime format
16
+
17
+ # Streamlit UI
18
+ st.set_page_config(page_title="Sales Forecast Chatbot")
19
+ st.title("Sales Forecast Chatbot")
20
+ st.markdown("Ask for sales forecast by day, week, or month.")
21
+
22
+ # User input for period
23
+ period = st.selectbox("Select Forecast Period", ["Day", "Week", "Month"])
24
+
25
+ start_date = None
26
+ end_date = None
27
+
28
+ # Handle date selection and period logic
29
+ if period == "Day":
30
+ selected_date = st.date_input("Select Date")
31
+ start_date = datetime.combine(selected_date, datetime.min.time())
32
+ end_date = start_date + timedelta(days=1) # Include full day
33
+
34
+ elif period == "Week":
35
+ selected_date = st.date_input("Select Start Date of Week")
36
+ start_date = datetime.combine(selected_date, datetime.min.time())
37
+ end_date = start_date + timedelta(days=7) # 7-day period
38
+
39
+ elif period == "Month":
40
+ selected_date = st.date_input("Select Start Date for Monthly Forecast")
41
+ start_date = datetime.combine(selected_date, datetime.min.time())
42
+ end_date = start_date + timedelta(days=30)
43
+
44
+ # When user clicks the button
45
+ if st.button("Get Forecast"):
46
+ filtered = df[(df['Date'] >= start_date) & (df['Date'] < end_date)]
47
+
48
+ if not filtered.empty:
49
+ total_sales = filtered['Forecasted_Sales'].sum()
50
+ formatted_total = f"{total_sales:,.2f}"
51
+ st.success(f"🧾 Total Forecasted Sales from {start_date.date()} to {end_date.date()}: {formatted_total}")
52
+
53
+ # Generate GPT suggestion
54
+ prompt = f"The total forecasted sales from {start_date.date()} to {end_date.date()} is {formatted_total}. Provide a brief suggestion for improving sales or maintaining performance."
55
+ with st.spinner("Generating GPT suggestion..."):
56
+ response = openai.ChatCompletion.create(
57
+ model="gpt-3.5-turbo", # or gpt-4 if you have access
58
+ messages=[
59
+ {"role": "user", "content": prompt}
60
+ ]
61
+ )
62
+ gpt_reply = response['choices'][0]['message']['content']
63
+ st.markdown("**GPT Suggestion:**")
64
+ st.write(gpt_reply)
65
+
66
+ else:
67
+ st.warning(" No forecast data found for selected period.")
forecastData.csv ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Date,Forecasted_Sales
2
+ 2025-03-01,4685661.387
3
+ 2025-03-02,2586351.492
4
+ 2025-03-03,4675843.927
5
+ 2025-03-04,5052969.364
6
+ 2025-03-05,4977911.143
7
+ 2025-03-06,4875497.257
8
+ 2025-03-07,3522924.054
9
+ 2025-03-08,4496472.553
10
+ 2025-03-09,2474748.294
11
+ 2025-03-10,4471271.522
12
+ 2025-03-11,5023028.628
13
+ 2025-03-12,5042117.902
14
+ 2025-03-13,4825123.487
15
+ 2025-03-14,3564184.507
16
+ 2025-03-15,4463466.871
17
+ 2025-03-16,2466828.851
18
+ 2025-03-17,4530176.331
19
+ 2025-03-18,4981621.956
20
+ 2025-03-19,5030621.096
21
+ 2025-03-20,4886472.334
22
+ 2025-03-21,3590695.43
23
+ 2025-03-22,4507196.067
24
+ 2025-03-23,2484495.597
25
+ 2025-03-24,4520779.214
26
+ 2025-03-25,5012889.54
27
+ 2025-03-26,5027726.102
28
+ 2025-03-27,4854277.921
29
+ 2025-03-28,3567430.115
30
+ 2025-03-29,4484790.629
31
+ 2025-03-30,2475577.98
32
+ 2025-03-31,4519072.906
33
+ 2025-04-01,5000178.57
34
+ 2025-04-02,5032902.259
35
+ 2025-04-03,4867033.75
36
+ 2025-04-04,3579706.59
37
+ 2025-04-05,4493499.416
38
+ 2025-04-06,2479333.512
39
+ 2025-04-07,4522270.714
40
+ 2025-04-08,5003991.995
41
+ 2025-04-09,5030191.809
42
+ 2025-04-10,4863942.434
43
+ 2025-04-11,3575410.29
44
+ 2025-04-12,4491405.739
45
+ 2025-04-13,2478320.335
46
+ 2025-04-14,4520424.156
47
+ 2025-04-15,5003511.617
48
+ 2025-04-16,5031152.698
49
+ 2025-04-17,4863911.417
50
+ 2025-04-18,3576262.303
51
+ 2025-04-19,4491361.031
52
+ 2025-04-20,2478360.695
53
+ 2025-04-21,4521116.871
54
+ 2025-04-22,5003188.971
55
+ 2025-04-23,5030932.101
56
+ 2025-04-24,4864421.841
57
+ 2025-04-25,3576379.747
58
+ 2025-04-26,4491722.817
59
+ 2025-04-27,2478490.949
60
+ 2025-04-28,4520947.42
61
+ 2025-04-29,5003479.376
62
+ 2025-04-30,5030919.662
63
+ 2025-05-01,4864081.933
64
+ 2025-05-02,3576160.09
65
+ 2025-05-03,4491486.4
66
+ 2025-05-04,2478396.516
67
+ 2025-05-05,4520947.837
68
+ 2025-05-06,5003337.343
69
+ 2025-05-07,5030964.381
70
+ 2025-05-08,4864227.021
71
+ 2025-05-09,3576288.742
72
+ 2025-05-10,4491586.346
73
+ 2025-05-11,2478438.984
74
+ 2025-05-12,4520975.604
75
+ 2025-05-13,5003385.499
76
+ 2025-05-14,5030936.647
77
+ 2025-05-15,4864185.413
78
+ 2025-05-16,3576238.465
79
+ 2025-05-17,4491558.044
80
+ 2025-05-18,2478426.02
81
+ 2025-05-19,4520956.972
82
+ 2025-05-20,5003376.452
83
+ 2025-05-21,5030947.991
84
+ 2025-05-22,4864189.645
85
+ 2025-05-23,3576251.194
86
+ 2025-05-24,4491560.707
87
+ 2025-05-25,2478427.78
88
+ 2025-05-26,4520964.937
89
+ 2025-05-27,5003374.647
90
+ 2025-05-28,5030944.905
91
+ 2025-05-29,4864193.602
92
+ 2025-05-30,3576250.864
93
+ 2025-05-31,4491563.542
94
+ 2025-06-01,2478428.713
95
+ 2025-06-02,4520962.632
96
+ 2025-06-03,5003377.334
97
+ 2025-06-04,5030945.118
98
+ 2025-06-05,4864190.251
99
+ 2025-06-06,3576249.002
100
+ 2025-06-07,4491561.202
101
+ 2025-06-08,2478427.798
102
+ 2025-06-09,4520962.876
103
+ 2025-06-10,5003375.825
104
+ 2025-06-11,5030945.479
105
+ 2025-06-12,4864191.853
106
+ 2025-06-13,3576250.306
107
+ 2025-06-14,4491562.309
108
+ 2025-06-15,2478428.26
109
+ 2025-06-16,4520963.089
110
+ 2025-06-17,5003376.399
111
+ 2025-06-18,5030945.202
112
+ 2025-06-19,4864191.326
113
+ 2025-06-20,3576249.735
114
+ 2025-06-21,4491561.948
115
+ 2025-06-22,2478428.099
116
+ 2025-06-23,4520962.906
117
+ 2025-06-24,5003376.26
118
+ 2025-06-25,5030945.329
119
+ 2025-06-26,4864191.418
120
+ 2025-06-27,3576249.905
121
+ 2025-06-28,4491562.009
122
+ 2025-06-29,2478428.131
123
+ 2025-06-30,4520962.994
124
+ 2025-07-01,5003376.259
125
+ 2025-07-02,5030945.289
126
+ 2025-07-03,4864191.442
127
+ 2025-07-04,3576249.884
128
+ 2025-07-05,4491562.027
129
+ 2025-07-06,2478428.136
130
+ 2025-07-07,4520962.965
131
+ 2025-07-08,5003376.282
132
+ 2025-07-09,5030945.295
133
+ 2025-07-10,4864191.411
134
+ 2025-07-11,3576249.87
135
+ 2025-07-12,4491562.005
136
+ 2025-07-13,2478428.128
137
+ 2025-07-14,4520962.97
138
+ 2025-07-15,5003376.267
139
+ 2025-07-16,5030945.298
140
+ 2025-07-17,4864191.428
141
+ 2025-07-18,3576249.883
142
+ 2025-07-19,4491562.017
143
+ 2025-07-20,2478428.133
144
+ 2025-07-21,4520962.972
145
+ 2025-07-22,5003376.274
146
+ 2025-07-23,5030945.295
147
+ 2025-07-24,4864191.421
148
+ 2025-07-25,3576249.877
149
+ 2025-07-26,4491562.013
150
+ 2025-07-27,2478428.131
151
+ 2025-07-28,4520962.97
152
+ 2025-07-29,5003376.272
153
+ 2025-07-30,5030945.296
154
+ 2025-07-31,4864191.423
155
+ 2025-08-01,3576249.879
156
+ 2025-08-02,4491562.014
157
+ 2025-08-03,2478428.131
158
+ 2025-08-04,4520962.971
159
+ 2025-08-05,5003376.272
160
+ 2025-08-06,5030945.296
161
+ 2025-08-07,4864191.423
162
+ 2025-08-08,3576249.878
163
+ 2025-08-09,4491562.014
164
+ 2025-08-10,2478428.131
165
+ 2025-08-11,4520962.97
166
+ 2025-08-12,5003376.272
167
+ 2025-08-13,5030945.296
168
+ 2025-08-14,4864191.423
169
+ 2025-08-15,3576249.878
170
+ 2025-08-16,4491562.014
171
+ 2025-08-17,2478428.131
172
+ 2025-08-18,4520962.97
173
+ 2025-08-19,5003376.272
174
+ 2025-08-20,5030945.296
175
+ 2025-08-21,4864191.423
176
+ 2025-08-22,3576249.878
177
+ 2025-08-23,4491562.014
178
+ 2025-08-24,2478428.131
179
+ 2025-08-25,4520962.97
180
+ 2025-08-26,5003376.272
181
+ 2025-08-27,5030945.296
182
+ 2025-08-28,4864191.423
183
+ 2025-08-29,3576249.878
184
+ 2025-08-30,4491562.014
185
+ 2025-08-31,2478428.131
186
+ 2025-09-01,4520962.97
187
+ 2025-09-02,5003376.272
188
+ 2025-09-03,5030945.296
189
+ 2025-09-04,4864191.423
190
+ 2025-09-05,3576249.878
191
+ 2025-09-06,4491562.014
192
+ 2025-09-07,2478428.131
193
+ 2025-09-08,4520962.97
194
+ 2025-09-09,5003376.272
195
+ 2025-09-10,5030945.296
196
+ 2025-09-11,4864191.423
197
+ 2025-09-12,3576249.878
198
+ 2025-09-13,4491562.014
199
+ 2025-09-14,2478428.131
200
+ 2025-09-15,4520962.97
201
+ 2025-09-16,5003376.272
202
+ 2025-09-17,5030945.296
203
+ 2025-09-18,4864191.423
204
+ 2025-09-19,3576249.878
205
+ 2025-09-20,4491562.014
206
+ 2025-09-21,2478428.131
207
+ 2025-09-22,4520962.97
208
+ 2025-09-23,5003376.272
209
+ 2025-09-24,5030945.296
210
+ 2025-09-25,4864191.423
211
+ 2025-09-26,3576249.878
212
+ 2025-09-27,4491562.014
213
+ 2025-09-28,2478428.131
214
+ 2025-09-29,4520962.97
215
+ 2025-09-30,5003376.272
216
+ 2025-10-01,5030945.296
217
+ 2025-10-02,4864191.423
218
+ 2025-10-03,3576249.878
219
+ 2025-10-04,4491562.014
220
+ 2025-10-05,2478428.131
221
+ 2025-10-06,4520962.97
222
+ 2025-10-07,5003376.272
223
+ 2025-10-08,5030945.296
224
+ 2025-10-09,4864191.423
225
+ 2025-10-10,3576249.878
226
+ 2025-10-11,4491562.014
227
+ 2025-10-12,2478428.131
228
+ 2025-10-13,4520962.97
229
+ 2025-10-14,5003376.272
230
+ 2025-10-15,5030945.296
231
+ 2025-10-16,4864191.423
232
+ 2025-10-17,3576249.878
233
+ 2025-10-18,4491562.014
234
+ 2025-10-19,2478428.131
235
+ 2025-10-20,4520962.97
236
+ 2025-10-21,5003376.272
237
+ 2025-10-22,5030945.296
238
+ 2025-10-23,4864191.423
239
+ 2025-10-24,3576249.878
240
+ 2025-10-25,4491562.014
241
+ 2025-10-26,2478428.131
242
+ 2025-10-27,4520962.97
243
+ 2025-10-28,5003376.272
244
+ 2025-10-29,5030945.296
245
+ 2025-10-30,4864191.423
246
+ 2025-10-31,3576249.878
247
+ 2025-11-01,4491562.014
248
+ 2025-11-02,2478428.131
249
+ 2025-11-03,4520962.97
250
+ 2025-11-04,5003376.272
251
+ 2025-11-05,5030945.296
252
+ 2025-11-06,4864191.423
253
+ 2025-11-07,3576249.878
254
+ 2025-11-08,4491562.014
255
+ 2025-11-09,2478428.131
256
+ 2025-11-10,4520962.97
257
+ 2025-11-11,5003376.272
258
+ 2025-11-12,5030945.296
259
+ 2025-11-13,4864191.423
260
+ 2025-11-14,3576249.878
261
+ 2025-11-15,4491562.014
262
+ 2025-11-16,2478428.131
263
+ 2025-11-17,4520962.97
264
+ 2025-11-18,5003376.272
265
+ 2025-11-19,5030945.296
266
+ 2025-11-20,4864191.423
267
+ 2025-11-21,3576249.878
268
+ 2025-11-22,4491562.014
269
+ 2025-11-23,2478428.131
270
+ 2025-11-24,4520962.97
271
+ 2025-11-25,5003376.272
272
+ 2025-11-26,5030945.296
273
+ 2025-11-27,4864191.423
274
+ 2025-11-28,3576249.878
275
+ 2025-11-29,4491562.014
276
+ 2025-11-30,2478428.131
277
+ 2025-12-01,4520962.97
278
+ 2025-12-02,5003376.272
279
+ 2025-12-03,5030945.296
280
+ 2025-12-04,4864191.423
281
+ 2025-12-05,3576249.878
282
+ 2025-12-06,4491562.014
283
+ 2025-12-07,2478428.131
284
+ 2025-12-08,4520962.97
285
+ 2025-12-09,5003376.272
286
+ 2025-12-10,5030945.296
287
+ 2025-12-11,4864191.423
288
+ 2025-12-12,3576249.878
289
+ 2025-12-13,4491562.014
290
+ 2025-12-14,2478428.131
291
+ 2025-12-15,4520962.97
292
+ 2025-12-16,5003376.272
293
+ 2025-12-17,5030945.296
294
+ 2025-12-18,4864191.423
295
+ 2025-12-19,3576249.878
296
+ 2025-12-20,4491562.014
297
+ 2025-12-21,2478428.131
298
+ 2025-12-22,4520962.97
299
+ 2025-12-23,5003376.272
300
+ 2025-12-24,5030945.296
301
+ 2025-12-25,4864191.423
302
+ 2025-12-26,3576249.878
303
+ 2025-12-27,4491562.014
304
+ 2025-12-28,2478428.131
305
+ 2025-12-29,4520962.97
306
+ 2025-12-30,5003376.272
307
+ 2025-12-31,5030945.296
308
+ 2026-01-01,4864191.423
309
+ 2026-01-02,3576249.878
310
+ 2026-01-03,4491562.014
311
+ 2026-01-04,2478428.131
312
+ 2026-01-05,4520962.97
313
+ 2026-01-06,5003376.272
314
+ 2026-01-07,5030945.296
315
+ 2026-01-08,4864191.423
316
+ 2026-01-09,3576249.878
317
+ 2026-01-10,4491562.014
318
+ 2026-01-11,2478428.131
319
+ 2026-01-12,4520962.97
320
+ 2026-01-13,5003376.272
321
+ 2026-01-14,5030945.296
322
+ 2026-01-15,4864191.423
323
+ 2026-01-16,3576249.878
324
+ 2026-01-17,4491562.014
325
+ 2026-01-18,2478428.131
326
+ 2026-01-19,4520962.97
327
+ 2026-01-20,5003376.272
328
+ 2026-01-21,5030945.296
329
+ 2026-01-22,4864191.423
330
+ 2026-01-23,3576249.878
331
+ 2026-01-24,4491562.014
332
+ 2026-01-25,2478428.131
333
+ 2026-01-26,4520962.97
334
+ 2026-01-27,5003376.272
335
+ 2026-01-28,5030945.296
336
+ 2026-01-29,4864191.423
337
+ 2026-01-30,3576249.878
338
+ 2026-01-31,4491562.014
339
+ 2026-02-01,2478428.131
340
+ 2026-02-02,4520962.97
341
+ 2026-02-03,5003376.272
342
+ 2026-02-04,5030945.296
343
+ 2026-02-05,4864191.423
344
+ 2026-02-06,3576249.878
345
+ 2026-02-07,4491562.014
346
+ 2026-02-08,2478428.131
347
+ 2026-02-09,4520962.97
348
+ 2026-02-10,5003376.272
349
+ 2026-02-11,5030945.296
350
+ 2026-02-12,4864191.423
351
+ 2026-02-13,3576249.878
352
+ 2026-02-14,4491562.014
353
+ 2026-02-15,2478428.131
354
+ 2026-02-16,4520962.97
355
+ 2026-02-17,5003376.272
356
+ 2026-02-18,5030945.296
357
+ 2026-02-19,4864191.423
358
+ 2026-02-20,3576249.878
359
+ 2026-02-21,4491562.014
360
+ 2026-02-22,2478428.131
361
+ 2026-02-23,4520962.97
362
+ 2026-02-24,5003376.272
363
+ 2026-02-25,5030945.296
364
+ 2026-02-26,4864191.423
365
+ 2026-02-27,3576249.878
366
+ 2026-02-28,4491562.014
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ openai==0.28
4
+ python-dotenv