|
import streamlit as st |
|
import pandas as pd |
|
import numpy as np |
|
from PIL import Image |
|
import requests |
|
from bokeh.plotting import figure |
|
from bokeh.models import HoverTool |
|
import torch |
|
import joblib |
|
import os |
|
from date_features import getDateFeatures |
|
|
|
|
|
assets_dir = "assets/ML components" |
|
model_path = os.path.join(assets_dir, 'model.pkl') |
|
encoder_path = os.path.join(assets_dir, 'encoder.pkl') |
|
|
|
|
|
model = torch.hub.load(assets_dir, 'model') |
|
encoder = torch.hub.load(assets_dir, 'encoder') |
|
|
|
|
|
st.set_page_config(page_title="ETA Prediction App", page_icon="fas fa-chart-line", layout="wide", initial_sidebar_state="auto") |
|
|
|
|
|
gif_url = "https://raw.githubusercontent.com/Gilbert-B/Forecasting-Sales/main/app/salesgif.gif" |
|
|
|
|
|
st.sidebar.header('Navigation') |
|
menu = ['Home', 'About'] |
|
choice = st.sidebar.selectbox("Select an option", menu) |
|
|
|
def predict(sales_data): |
|
sales_data = getDateFeatures(sales_data).set_index('date') |
|
|
|
|
|
|
|
prediction_inputs = [] |
|
|
|
|
|
|
|
numeric_columns = ['onpromotion', 'year', 'month', 'dayofmonth', 'dayofweek', 'dayofyear', 'weekofyear', 'quarter', 'year_weekofyear', 'sin(dayofyear)', 'cos(dayofyear)'] |
|
categoric_columns = ['store_id','category_id','city','store_type','cluster','holiday_type','is_holiday','is_month_start','is_month_end','is_quarter_start','is_quarter_end','is_year_start','is_year_end','is_weekend', 'season'] |
|
print(categoric_columns) |
|
|
|
|
|
num = sales_data[numeric_columns] |
|
encoded_cat = encoder.transform(sales_data[categoric_columns]) |
|
sales_data = pd.concat([num, encoded_cat], axis=1) |
|
|
|
|
|
predicted_sales = model.predict(sales_data) |
|
|
|
return predicted_sales |
|
|
|
|
|
if choice == 'Home': |
|
st.image(gif_url, use_column_width=True) |
|
st.markdown("<h1 style='text-align: center;'>Welcome</h1>", unsafe_allow_html=True) |
|
st.markdown("<p style='text-align: center;'>This is a Sales Forecasting App.</p>", unsafe_allow_html=True) |
|
|
|
|
|
st.title('SEER- A Sales Forecasting APP') |
|
st.markdown('Enter the required information to forecast sales:') |
|
|
|
|
|
|
|
col1, col2 = st.columns(2) |
|
|
|
Stores = ['Store_' + str(i) for i in range(1, 55)] |
|
Stores1 = ['Store_' + str(i) for i in range(0, 5)] |
|
cities = ['city_' + str(i) for i in range(22)] |
|
clusters = ['cluster_' + str(i) for i in range(17)] |
|
categories = ['Category_' + str(i) for i in range(33)] |
|
|
|
with col1: |
|
date = st.date_input("Date") |
|
|
|
date = pd.to_datetime(date) |
|
onpromotion = st.number_input("How many products are on promotion?", min_value=0, step=1) |
|
selected_category = st.selectbox("Category", categories) |
|
|
|
|
|
with col2: |
|
selected_store = st.selectbox("Store_type", Stores) |
|
selected_store1 = st.selectbox("Store_id", Stores1) |
|
selected_city = st.selectbox("City", cities) |
|
selected_cluster = st.selectbox("Cluster", clusters) |
|
|
|
|
|
sales_data = pd.DataFrame({ |
|
'date': [date], |
|
'store_id': [selected_store], |
|
'category_id': [selected_category], |
|
'onpromotion': [onpromotion], |
|
'city' :[selected_city], |
|
'store_type': [selected_store1], |
|
'cluster':[selected_cluster] |
|
}) |
|
print(sales_data) |
|
print(sales_data.info()) |
|
|
|
|
|
if st.button('Predict'): |
|
sales = predict(sales_data) |
|
formatted_sales = round(sales[0], 2) |
|
st.write(f"Total sales for this week is: #{formatted_sales}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif choice == 'About': |
|
|
|
banner_image_url = "https://raw.githubusercontent.com/Gilbert-B/Forecasting-Sales/0d7b869515bysBoi5XxNGa3hayALLn9BK1VQqD69Dc/app/seer.png" |
|
banner_image = Image.open(requests.get(banner_image_url, stream=True).raw) |
|
|
|
|
|
st.image(banner_image, use_column_width=True) |
|
st.markdown(''' |
|
<p style='font-size: 20px; font-style: italic;font-style: bold;'> |
|
SEER is a powerful tool designed to assist businesses in making accurate |
|
and data-driven sales predictions. By leveraging advanced algorithms and |
|
machine learning techniques, our app provides businesses with valuable insights |
|
into future sales trends. With just a few input parameters, such as distance and |
|
average speed, our app generates reliable sales forecasts, enabling businesses |
|
to optimize their inventory management, production planning, and resource allocation. |
|
The user-friendly interface and intuitive design make it easy for users to navigate |
|
and obtain actionable predictions. With our Sales Forecasting App, |
|
businesses can make informed decisions, mitigate risks, |
|
and maximize their revenue potential in an ever-changing market landscape. |
|
</p> |
|
''', unsafe_allow_html=True) |
|
st.markdown("<p style='text-align: center;'>This Sales Forecasting App is developed using Streamlit and Python.</p>", unsafe_allow_html=True) |
|
st.markdown("<p style='text-align: center;'>It demonstrates how machine learning can be used to predict sales for the next 8 weeks based on historical data.</p>", unsafe_allow_html=True) |
|
|