Spaces:
Running
Running
Commit
Β·
e40f126
1
Parent(s):
4bcb041
Fix app
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import numpy as np
|
|
| 6 |
import pmdarima as pm
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
from pmdarima import auto_arima
|
|
|
|
| 9 |
|
| 10 |
import torch
|
| 11 |
from transformers import pipeline, TapasTokenizer, TapasForQuestionAnswering
|
|
@@ -211,8 +212,7 @@ def get_converted_answer(table, query):
|
|
| 211 |
|
| 212 |
|
| 213 |
# Web Application
|
| 214 |
-
|
| 215 |
-
st.title("Sales Forecasting Dashboard π")
|
| 216 |
st.subheader("Welcome User, start using the application by uploading your file in the sidebar!")
|
| 217 |
|
| 218 |
# Session States
|
|
@@ -222,9 +222,6 @@ if 'uploaded' not in st.session_state:
|
|
| 222 |
if 'preprocessed_data' not in st.session_state:
|
| 223 |
st.session_state.preprocessed_data = None
|
| 224 |
|
| 225 |
-
if 'fitted_models' not in st.session_state:
|
| 226 |
-
st.session_state.fitted_models = {}
|
| 227 |
-
|
| 228 |
# Sidebar Menu
|
| 229 |
with st.sidebar:
|
| 230 |
uploaded_file = st.file_uploader("Upload your Store Data here (must atleast contain Date and Sale)", type=["csv"])
|
|
@@ -297,18 +294,53 @@ if (st.session_state.uploaded):
|
|
| 297 |
|
| 298 |
st.title("Forecasted Sales")
|
| 299 |
|
| 300 |
-
|
| 301 |
-
plt.
|
| 302 |
-
plt.plot(
|
| 303 |
-
plt.plot(
|
| 304 |
-
plt.
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
plt.
|
| 311 |
-
plt.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
# Forecast (actual)
|
| 314 |
n_periods = forecast_period
|
|
@@ -323,16 +355,45 @@ if (st.session_state.uploaded):
|
|
| 323 |
future_upper_series = pd.Series(confint[:, 1], index=future_index_of_fc)
|
| 324 |
|
| 325 |
# Plot
|
| 326 |
-
plt.figure(figsize=(12,8))
|
| 327 |
-
plt.plot(df['Sales'][-50:])
|
| 328 |
-
plt.plot(future_fitted_series, color='darkgreen')
|
| 329 |
-
plt.fill_between(future_lower_series.index,
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
plt.title("SARIMA - Final Forecast of Retail Sales")
|
| 335 |
-
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
auto_sales_growth = sales_growth(df, future_fitted_series)
|
| 338 |
df = auto_sales_growth
|
|
@@ -343,7 +404,10 @@ if (st.session_state.uploaded):
|
|
| 343 |
st.write("Forecasted sales in the next 3 months")
|
| 344 |
st.write(df)
|
| 345 |
|
| 346 |
-
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
| 348 |
answer = get_converted_answer(df, question)
|
| 349 |
st.write("The answer is:", answer)
|
|
|
|
| 6 |
import pmdarima as pm
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
from pmdarima import auto_arima
|
| 9 |
+
import plotly.graph_objects as go
|
| 10 |
|
| 11 |
import torch
|
| 12 |
from transformers import pipeline, TapasTokenizer, TapasForQuestionAnswering
|
|
|
|
| 212 |
|
| 213 |
|
| 214 |
# Web Application
|
| 215 |
+
st.title("π SalesCast Forecasting Dashboard")
|
|
|
|
| 216 |
st.subheader("Welcome User, start using the application by uploading your file in the sidebar!")
|
| 217 |
|
| 218 |
# Session States
|
|
|
|
| 222 |
if 'preprocessed_data' not in st.session_state:
|
| 223 |
st.session_state.preprocessed_data = None
|
| 224 |
|
|
|
|
|
|
|
|
|
|
| 225 |
# Sidebar Menu
|
| 226 |
with st.sidebar:
|
| 227 |
uploaded_file = st.file_uploader("Upload your Store Data here (must atleast contain Date and Sale)", type=["csv"])
|
|
|
|
| 294 |
|
| 295 |
st.title("Forecasted Sales")
|
| 296 |
|
| 297 |
+
# Plot
|
| 298 |
+
# plt.figure(figsize=(12,8))
|
| 299 |
+
# plt.plot(training_y[-80:])
|
| 300 |
+
# plt.plot(test_y, color = 'red', label = 'Actual Sales')
|
| 301 |
+
# plt.plot(fitted_series, color='darkgreen', label = 'Predicted Sales')
|
| 302 |
+
# plt.fill_between(lower_series.index,
|
| 303 |
+
# lower_series,
|
| 304 |
+
# upper_series,
|
| 305 |
+
# color='k', alpha=.15)
|
| 306 |
+
|
| 307 |
+
# plt.title("SARIMAX - Forecast of Retail Sales VS Actual Sales")
|
| 308 |
+
# plt.legend(loc='upper left', fontsize=8)
|
| 309 |
+
# plt.show()
|
| 310 |
+
|
| 311 |
+
trace_actual = go.Scatter(x=range(len(training_y) - 80, len(training_y)),
|
| 312 |
+
y=training_y[-80:],
|
| 313 |
+
mode='lines',
|
| 314 |
+
name='Training Data')
|
| 315 |
+
|
| 316 |
+
trace_actual_sales = go.Scatter(x=range(len(training_y), len(training_y) + len(test_y)),
|
| 317 |
+
y=test_y,
|
| 318 |
+
mode='lines',
|
| 319 |
+
name='Actual Sales',
|
| 320 |
+
line=dict(color='red'))
|
| 321 |
+
|
| 322 |
+
trace_predicted_sales = go.Scatter(x=range(len(training_y), len(training_y) + len(fitted_series)),
|
| 323 |
+
y=fitted_series,
|
| 324 |
+
mode='lines',
|
| 325 |
+
name='Predicted Sales',
|
| 326 |
+
line=dict(color='darkgreen'))
|
| 327 |
+
|
| 328 |
+
trace_fill_between = go.Scatter(x=list(range(len(training_y), len(training_y) + len(lower_series))) +
|
| 329 |
+
list(range(len(training_y) + len(lower_series), len(training_y) + len(upper_series))),
|
| 330 |
+
y=list(lower_series) + list(upper_series)[::-1],
|
| 331 |
+
fill='toself',
|
| 332 |
+
fillcolor='rgba(0,100,80,0.2)',
|
| 333 |
+
line=dict(color='rgba(255,255,255,0)'),
|
| 334 |
+
name='Prediction Interval')
|
| 335 |
+
|
| 336 |
+
# Combine traces and create layout
|
| 337 |
+
data = [trace_actual, trace_actual_sales, trace_predicted_sales, trace_fill_between]
|
| 338 |
+
layout = go.Layout(title="SARIMAX - Forecast of Retail Sales VS Actual Sales",
|
| 339 |
+
legend=dict(x=0, y=1.0),
|
| 340 |
+
xaxis=dict(title='X-axis Label'),
|
| 341 |
+
yaxis=dict(title='Y-axis Label'))
|
| 342 |
+
fig_test = go.Figure(data=data, layout=layout)
|
| 343 |
+
st.plotly_chart(fig_test)
|
| 344 |
|
| 345 |
# Forecast (actual)
|
| 346 |
n_periods = forecast_period
|
|
|
|
| 355 |
future_upper_series = pd.Series(confint[:, 1], index=future_index_of_fc)
|
| 356 |
|
| 357 |
# Plot
|
| 358 |
+
# plt.figure(figsize=(12,8))
|
| 359 |
+
# plt.plot(df['Sales'][-50:])
|
| 360 |
+
# plt.plot(future_fitted_series, color='darkgreen')
|
| 361 |
+
# plt.fill_between(future_lower_series.index,
|
| 362 |
+
# future_lower_series,
|
| 363 |
+
# future_upper_series,
|
| 364 |
+
# color='k', alpha=.15)
|
| 365 |
+
|
| 366 |
+
# plt.title("SARIMA - Final Forecast of Retail Sales")
|
| 367 |
+
# plt.show()
|
| 368 |
+
|
| 369 |
+
# Create traces for each line and fill_between
|
| 370 |
+
trace_sales = go.Scatter(x=df.index[-50:],
|
| 371 |
+
y=df['Sales'][-50:],
|
| 372 |
+
mode='lines',
|
| 373 |
+
name='Sales')
|
| 374 |
+
|
| 375 |
+
trace_predicted_sales = go.Scatter(x=df.index[-50:] + future_fitted_series.index,
|
| 376 |
+
y=future_fitted_series,
|
| 377 |
+
mode='lines',
|
| 378 |
+
name='Predicted Sales',
|
| 379 |
+
line=dict(color='darkgreen'))
|
| 380 |
+
|
| 381 |
+
trace_fill_between = go.Scatter(x=list(df.index[-50:] + future_lower_series.index) +
|
| 382 |
+
list(df.index[-50:] + future_upper_series.index[::-1]),
|
| 383 |
+
y=list(future_lower_series) + list(future_upper_series)[::-1],
|
| 384 |
+
fill='toself',
|
| 385 |
+
fillcolor='rgba(0,100,80,0.2)',
|
| 386 |
+
line=dict(color='rgba(255,255,255,0)'),
|
| 387 |
+
name='Prediction Interval')
|
| 388 |
+
|
| 389 |
+
# Combine traces and create layout
|
| 390 |
+
data = [trace_sales, trace_predicted_sales, trace_fill_between]
|
| 391 |
+
layout = go.Layout(title="SARIMA - Final Forecast of Retail Sales",
|
| 392 |
+
legend=dict(x=0, y=1.0),
|
| 393 |
+
xaxis=dict(title='X-axis Label'),
|
| 394 |
+
yaxis=dict(title='Y-axis Label'))
|
| 395 |
+
fig_final = go.Figure(data=data, layout=layout)
|
| 396 |
+
st.plotly_chart(fig_final)
|
| 397 |
|
| 398 |
auto_sales_growth = sales_growth(df, future_fitted_series)
|
| 399 |
df = auto_sales_growth
|
|
|
|
| 404 |
st.write("Forecasted sales in the next 3 months")
|
| 405 |
st.write(df)
|
| 406 |
|
| 407 |
+
with st.form("question_form"):
|
| 408 |
+
question = st.text_input('Ask a Question about the Forecasted Data', placeholder="What is the total sales in the month of December?")
|
| 409 |
+
query_button = st.form_submit_button(label='Generate Answer')
|
| 410 |
+
|
| 411 |
+
if query_button:
|
| 412 |
answer = get_converted_answer(df, question)
|
| 413 |
st.write("The answer is:", answer)
|