Spaces:
Running
Running
Circhastic
commited on
Commit
Β·
b54ea30
1
Parent(s):
aaacc29
First version release
Browse files
app.py
CHANGED
|
@@ -179,6 +179,16 @@ def sales_growth(dataframe, fittedValues):
|
|
| 179 |
|
| 180 |
return sales_growth
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
# TAPAS Model
|
| 183 |
|
| 184 |
@st.cache_resource
|
|
@@ -222,7 +232,7 @@ def get_converted_answer(table, query):
|
|
| 222 |
|
| 223 |
# Web Application
|
| 224 |
st.title("Forecasting Dashboard π")
|
| 225 |
-
st.subheader("Welcome User, start
|
| 226 |
|
| 227 |
# Session States
|
| 228 |
if 'uploaded' not in st.session_state:
|
|
@@ -233,26 +243,32 @@ if 'forecasted' not in st.session_state:
|
|
| 233 |
|
| 234 |
# Sidebar Menu
|
| 235 |
with st.sidebar:
|
| 236 |
-
|
| 237 |
-
st.
|
| 238 |
-
|
| 239 |
-
|
| 240 |
if uploaded_file is not None:
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
with open('sample.csv', 'rb') as f:
|
| 258 |
st.download_button("Download our sample CSV", f, file_name='sample.csv')
|
|
@@ -288,21 +304,11 @@ if (st.session_state.uploaded):
|
|
| 288 |
lower_series = pd.Series(confint[:, 0], index=index_of_fc)
|
| 289 |
upper_series = pd.Series(confint[:, 1], index=index_of_fc)
|
| 290 |
|
| 291 |
-
# TODO Plot Test and Training
|
| 292 |
-
col1, col2 = st.columns(2)
|
| 293 |
-
with col1:
|
| 294 |
-
col1.header("Sales Forecast")
|
| 295 |
-
chart_data = pd.DataFrame(np.random.randn(20, 3), columns=["Forecasted", "Predicted", "Actual Sale"])
|
| 296 |
-
col1.line_chart(chart_data)
|
| 297 |
-
# col1.line_chart(df['Sales'], x="Date", y="Actual Sales", color="#0000EE")
|
| 298 |
-
# plt.figure(figsize=(18,10))
|
| 299 |
# plt.plot(df['Sales'], color='b', label = 'Actual Sales')
|
| 300 |
# plt.plot(test_y, color='b')
|
| 301 |
# plt.plot(fitted_series, color='r', label = 'Predicted Sales')
|
| 302 |
# plt.title("SARIMAX - Forecast of Auto Business Retail Sales VS Actual Sales")
|
| 303 |
# plt.legend(loc='upper left', fontsize=8)
|
| 304 |
-
# plt.show()
|
| 305 |
-
# plt.savefig('Auto Retail Future Sales Forecast 80-20.png')
|
| 306 |
|
| 307 |
#Future predictions
|
| 308 |
frequency = '3D'
|
|
@@ -329,9 +335,15 @@ if (st.session_state.uploaded):
|
|
| 329 |
future_sales_growth = sales_growth(df, future_fitted_series)
|
| 330 |
future_sales_growth = future_sales_growth.iloc[n_periods:]
|
| 331 |
df = dates_df(future_sales_growth)
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
st.session_state.forecasted = True
|
| 336 |
|
| 337 |
with st.form("question_form"):
|
|
@@ -340,7 +352,10 @@ if (st.session_state.uploaded):
|
|
| 340 |
|
| 341 |
if query_button or question:
|
| 342 |
answer = get_converted_answer(df, question)
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
# Hide Streamlit default style
|
| 346 |
hide_st_style = """
|
|
|
|
| 179 |
|
| 180 |
return sales_growth
|
| 181 |
|
| 182 |
+
@st.cache_data
|
| 183 |
+
def merge_forecast_data(historical, test, future):
|
| 184 |
+
historical.rename(columns={historical.columns[0]: "Actual Sales"}, inplace=True)
|
| 185 |
+
test = test.to_frame()
|
| 186 |
+
test.rename(columns={test.columns[0]: "Predicted Sales"}, inplace=True)
|
| 187 |
+
future = future.to_frame()
|
| 188 |
+
future.rename(columns={future.columns[0]: "Future Forecasted Sales"}, inplace=True)
|
| 189 |
+
merged_dataframe = pd.merge(historical, test, future, on='Date', how='outer')
|
| 190 |
+
return merged_dataframe
|
| 191 |
+
|
| 192 |
# TAPAS Model
|
| 193 |
|
| 194 |
@st.cache_resource
|
|
|
|
| 232 |
|
| 233 |
# Web Application
|
| 234 |
st.title("Forecasting Dashboard π")
|
| 235 |
+
st.subheader("Welcome User, start forecasting by uploading your file in the sidebar!")
|
| 236 |
|
| 237 |
# Session States
|
| 238 |
if 'uploaded' not in st.session_state:
|
|
|
|
| 243 |
|
| 244 |
# Sidebar Menu
|
| 245 |
with st.sidebar:
|
| 246 |
+
# TODO Name for product
|
| 247 |
+
st.title("MaLaCast v1.0")
|
| 248 |
+
st.subheader("An intelligent sales forecasting system")
|
| 249 |
+
uploaded_file = st.file_uploader("Upload your store data here to proceed (must atleast contain Date and Sales)", type=["csv"])
|
| 250 |
if uploaded_file is not None:
|
| 251 |
+
date_found, sales_found = False
|
| 252 |
+
for column in uploaded_file.columns:
|
| 253 |
+
if 'Date' in column:
|
| 254 |
+
date_found = True
|
| 255 |
+
if 'Sales' in column:
|
| 256 |
+
sales_found = True
|
| 257 |
+
if(date_found and sales_found):
|
| 258 |
+
st.error('Please upload a csv containing both Date and Sales...')
|
| 259 |
+
st.stop()
|
| 260 |
+
|
| 261 |
+
st.success("File uploaded successfully!")
|
| 262 |
+
df = pd.read_csv(uploaded_file, parse_dates=True)
|
| 263 |
+
st.write("Your uploaded data:")
|
| 264 |
+
st.write(df)
|
| 265 |
+
|
| 266 |
+
df = drop(df)
|
| 267 |
+
df = date_format(df)
|
| 268 |
+
merge_sort(df)
|
| 269 |
+
series = group_to_three(df)
|
| 270 |
+
|
| 271 |
+
st.session_state.uploaded = True
|
| 272 |
|
| 273 |
with open('sample.csv', 'rb') as f:
|
| 274 |
st.download_button("Download our sample CSV", f, file_name='sample.csv')
|
|
|
|
| 304 |
lower_series = pd.Series(confint[:, 0], index=index_of_fc)
|
| 305 |
upper_series = pd.Series(confint[:, 1], index=index_of_fc)
|
| 306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
# plt.plot(df['Sales'], color='b', label = 'Actual Sales')
|
| 308 |
# plt.plot(test_y, color='b')
|
| 309 |
# plt.plot(fitted_series, color='r', label = 'Predicted Sales')
|
| 310 |
# plt.title("SARIMAX - Forecast of Auto Business Retail Sales VS Actual Sales")
|
| 311 |
# plt.legend(loc='upper left', fontsize=8)
|
|
|
|
|
|
|
| 312 |
|
| 313 |
#Future predictions
|
| 314 |
frequency = '3D'
|
|
|
|
| 335 |
future_sales_growth = sales_growth(df, future_fitted_series)
|
| 336 |
future_sales_growth = future_sales_growth.iloc[n_periods:]
|
| 337 |
df = dates_df(future_sales_growth)
|
| 338 |
+
|
| 339 |
+
col = st.columns(2)
|
| 340 |
+
with col[0]:
|
| 341 |
+
col[0].header("Sales Forecast")
|
| 342 |
+
merged_data = merge_forecast_data(df['Data'], fitted_series, future_fitted_series)
|
| 343 |
+
col[0].line_chart(merged_data)
|
| 344 |
+
with col[1]:
|
| 345 |
+
col[1].subheader("Forecasted sales in x days")
|
| 346 |
+
col[1].write(df)
|
| 347 |
st.session_state.forecasted = True
|
| 348 |
|
| 349 |
with st.form("question_form"):
|
|
|
|
| 352 |
|
| 353 |
if query_button or question:
|
| 354 |
answer = get_converted_answer(df, question)
|
| 355 |
+
if answer is not None:
|
| 356 |
+
st.subheader("The answer is:", answer)
|
| 357 |
+
else:
|
| 358 |
+
st.subheader("Answer is not found in table")
|
| 359 |
|
| 360 |
# Hide Streamlit default style
|
| 361 |
hide_st_style = """
|