JamesBentley commited on
Commit
e5f24e8
1 Parent(s): 3128632

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -67
app.py CHANGED
@@ -200,9 +200,76 @@ def visualize_forecast(forecast_df, time_series_data, ground_truth_df=None, grou
200
  def main():
201
  st.title("Amazon Chronos Forecasting App")
202
 
203
- tab1, tab2, tab3 = st.tabs(["Run a Forecast", "Compare to Actual", "User Guide"])
204
 
205
  with tab1:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  uploaded_file = st.file_uploader("Upload CSV file with historical data", type=["csv"])
207
  if uploaded_file is not None:
208
  data = pd.read_csv(uploaded_file)
@@ -232,7 +299,7 @@ def main():
232
  st.session_state.initial_forecast_fig = initial_forecast_fig
233
  st.plotly_chart(initial_forecast_fig)
234
 
235
- with tab2:
236
  st.subheader("Compare Forecast to Actual Data")
237
 
238
  if 'forecast_df' not in st.session_state or 'time_series_data' not in st.session_state:
@@ -259,71 +326,6 @@ def main():
259
  visualize_forecast(st.session_state.forecast_df, st.session_state.time_series_data,
260
  ground_truth_df, ground_truth_date_format, ground_truth_date_col, ground_truth_metric_col)
261
 
262
- with tab3:
263
- st.subheader("User Guide")
264
- st.write("""
265
- This is a demo HuggingFace app which gives you everything you need to test Amazon Chronos T5 Small using a demo ecommerce sales dataset.
266
-
267
- As per the Hugging Face description:
268
-
269
- 'Chronos is a family of pretrained time series forecasting models based on language model architectures. Chronos models have been trained on a large corpus of publicly available time series data, as well as synthetic data generated using Gaussian processes.
270
- For more info see:
271
- - [Hugging Face Chronos T5 Small](https://huggingface.co/amazon/chronos-t5-small)
272
- - [GitHub: Chronos Forecasting](https://github.com/amazon-science/chronos-forecasting)
273
-
274
- Please Share, Cite and Connect with Me:
275
-
276
- If you liked or found this notebook at all helpful please share it, and simply cite me as the original source... feel free to connect with me on LinkedIn here:
277
- - [LinkedIn: James Bentley](https://www.linkedin.com/in/james-bentley-1b329214/)
278
-
279
- Youtube Video Walkthrough of a Google Colab Notebook I built previously - which I based this app on:
280
- - [Watch here](https://www.youtube.com/watch?v=jyrOmIiI2Bc&t=103s)
281
-
282
- Disclaimer: This is purely for educational purposes.
283
- """)
284
-
285
- # Display the image after the disclaimer
286
- st.image("https://huggingface.co/spaces/JamesBentley/Amazon_Chronos_Forecasting_App/resolve/main/chronos.gif", caption="Visualization of Chronos Forecasting")
287
-
288
- st.write("""
289
- **Upload Your CSV File From Your Computer:**
290
- It should contain two columns, the first column should contain your dates, and the second should contain the metric you would like to predict, as pictured below.
291
-
292
- You can download a copies of the csv files I use for this test here (be sure to save them as csv):
293
- - [Sales.csv](https://docs.google.com/spreadsheets/d/1_tyquxKwYRWFyp0r8tMvpWoAIqJmS8fEG0wsxFT58B0/edit?usp=sharing)
294
- - [Actual.csv](https://docs.google.com/spreadsheets/d/1yjebWmbmY-rAyB_TDXAye8i-yoiqKA2dW_SHmtL2ihM/edit?usp=sharing)
295
-
296
- **Confirm Your Column Names:**
297
- Now we just need to confirm which column contains your dates and which contains your metric that you want to forecast, this is just so we can properly handle it based on whatever you have named them.
298
-
299
- **Generate Forecast and CSV File:**
300
- To run your forecast you will need to confirm two settings,
301
-
302
- - The forecast length, so this is the number of timepoints you want to run the forecast for, so for example if you wanted to run a 31 day forecast for a month, then you would select 31, if you wanted to run only 7 days next week, then you would select seven, or if you wanted to run 12 months, with one forecast for each month, you would select 12. The current default is set at 12 (to work with the demo). If you plan to assess forecast accuracy against some test data, then you should make sure that this number matches the number of date ranges you want to test against where you have data.
303
-
304
- - The Interval Period, so this means how many days should be between each forecasted period, so if you wanted to run the forecast for consecutive days then you would select 1, if you wanted to run the forecast for each week, then you would select 7.
305
-
306
- **Check the Accuracy of Your Forecast Against Actual Data:**
307
-
308
- If you want to check the accuracy of the forecaster against some real data, which you didn't include in the original csv, then you can do that by uploading an actual.csv file (or whatever you choose to name it).
309
-
310
- This file should contain the actual data for the dates you ran the forecast for.
311
-
312
- This should be a two column file with a date range in the first column, and the metric in the second column, and by comparing this to the forecast you'll be able to see what kind of accuracy it outputs.
313
-
314
- Below is the file I use in my demo
315
-
316
- - [Actual.csv](https://docs.google.com/spreadsheets/d/1yjebWmbmY-rAyB_TDXAye8i-yoiqKA2dW_SHmtL2ihM/edit?usp=sharing)
317
-
318
-
319
- **Select the Actual.csv File and Confirm The Column Names:**
320
- Now you just need to confirm the column names that need to be used.
321
-
322
- **Generate Actual vs Forecast Trendline Chart and CSV:**
323
- Now that you have setup your actual file you can generate a trendline chart to show how the forecasts tracked vs your actual data for the forecasted date range.
324
-
325
- A csv file is also available to download which shows the combined original data, forecasts and actuals with % variances.
326
- """)
327
 
328
  if __name__ == "__main__":
329
  main()
 
200
  def main():
201
  st.title("Amazon Chronos Forecasting App")
202
 
203
+ tab1, tab2, tab3 = st.tabs(["User Guide", "Run a Forecast", "Compare to Actual"])
204
 
205
  with tab1:
206
+ st.subheader("User Guide")
207
+ st.write("""
208
+ This is a demo HuggingFace app which gives you everything you need to test Amazon Chronos T5 Small using a demo ecommerce sales dataset. Scroll down for full instructions on how to use this app.
209
+
210
+ **Please Share and Connect with Me:**
211
+
212
+ If you liked or found this app at all helpful please share it, and simply cite me as the original source... feel free to connect with me on LinkedIn here:
213
+ - [LinkedIn: James Bentley](https://www.linkedin.com/in/james-bentley-1b329214/)
214
+
215
+ Youtube Video Walkthrough of a Google Colab Notebook I built previously - which I based this app on:
216
+ - [Watch here](https://www.youtube.com/watch?v=jyrOmIiI2Bc&t=103s)
217
+
218
+ Disclaimer: This is purely for educational purposes.
219
+ """)
220
+
221
+ # Display the image after the disclaimer
222
+ st.image("https://huggingface.co/spaces/JamesBentley/Amazon_Chronos_Forecasting_App/resolve/main/chronos.gif", caption="Visualization of Chronos Forecasting")
223
+
224
+ st.write("""
225
+ As per the Hugging Face description:
226
+
227
+ 'Chronos is a family of pretrained time series forecasting models based on language model architectures. Chronos models have been trained on a large corpus of publicly available time series data, as well as synthetic data generated using Gaussian processes.
228
+ For more info see:
229
+ - [Hugging Face Chronos T5 Small](https://huggingface.co/amazon/chronos-t5-small)
230
+ - [GitHub: Chronos Forecasting](https://github.com/amazon-science/chronos-forecasting)
231
+
232
+ **Upload Your CSV File From Your Computer:**
233
+ It should contain two columns, the first column should contain your dates, and the second should contain the metric you would like to predict, as pictured below.
234
+
235
+ You can download a copies of the csv files I use for this test here (be sure to save them as csv):
236
+ - [Sales.csv](https://docs.google.com/spreadsheets/d/1_tyquxKwYRWFyp0r8tMvpWoAIqJmS8fEG0wsxFT58B0/edit?usp=sharing)
237
+ - [Actual.csv](https://docs.google.com/spreadsheets/d/1yjebWmbmY-rAyB_TDXAye8i-yoiqKA2dW_SHmtL2ihM/edit?usp=sharing)
238
+
239
+ **Confirm Your Column Names:**
240
+ Now we just need to confirm which column contains your dates and which contains your metric that you want to forecast, this is just so we can properly handle it based on whatever you have named them.
241
+
242
+ **Generate Forecast and CSV File:**
243
+ To run your forecast you will need to confirm two settings,
244
+
245
+ - The forecast length, so this is the number of timepoints you want to run the forecast for, so for example if you wanted to run a 31 day forecast for a month, then you would select 31, if you wanted to run only 7 days next week, then you would select seven, or if you wanted to run 12 months, with one forecast for each month, you would select 12. The current default is set at 12 (to work with the demo). If you plan to assess forecast accuracy against some test data, then you should make sure that this number matches the number of date ranges you want to test against where you have data.
246
+
247
+ - The Interval Period, so this means how many days should be between each forecasted period, so if you wanted to run the forecast for consecutive days then you would select 1, if you wanted to run the forecast for each week, then you would select 7.
248
+
249
+ **Check the Accuracy of Your Forecast Against Actual Data:**
250
+
251
+ If you want to check the accuracy of the forecaster against some real data, which you didn't include in the original csv, then you can do that by uploading an actual.csv file (or whatever you choose to name it).
252
+
253
+ This file should contain the actual data for the dates you ran the forecast for.
254
+
255
+ This should be a two column file with a date range in the first column, and the metric in the second column, and by comparing this to the forecast you'll be able to see what kind of accuracy it outputs.
256
+
257
+ Below is the file I use in my demo
258
+
259
+ - [Actual.csv](https://docs.google.com/spreadsheets/d/1yjebWmbmY-rAyB_TDXAye8i-yoiqKA2dW_SHmtL2ihM/edit?usp=sharing)
260
+
261
+
262
+ **Select the Actual.csv File and Confirm The Column Names:**
263
+ Now you just need to confirm the column names that need to be used.
264
+
265
+ **Generate Actual vs Forecast Trendline Chart and CSV:**
266
+ Now that you have setup your actual file you can generate a trendline chart to show how the forecasts tracked vs your actual data for the forecasted date range.
267
+
268
+ A csv file is also available to download which shows the combined original data, forecasts and actuals with % variances.
269
+ """)
270
+
271
+
272
+ with tab2:
273
  uploaded_file = st.file_uploader("Upload CSV file with historical data", type=["csv"])
274
  if uploaded_file is not None:
275
  data = pd.read_csv(uploaded_file)
 
299
  st.session_state.initial_forecast_fig = initial_forecast_fig
300
  st.plotly_chart(initial_forecast_fig)
301
 
302
+ with tab3:
303
  st.subheader("Compare Forecast to Actual Data")
304
 
305
  if 'forecast_df' not in st.session_state or 'time_series_data' not in st.session_state:
 
326
  visualize_forecast(st.session_state.forecast_df, st.session_state.time_series_data,
327
  ground_truth_df, ground_truth_date_format, ground_truth_date_col, ground_truth_metric_col)
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
 
330
  if __name__ == "__main__":
331
  main()