File size: 8,445 Bytes
982c0a1
 
 
 
 
 
 
4daf5d3
 
982c0a1
 
4daf5d3
 
 
 
 
 
 
 
 
 
 
 
982c0a1
 
4daf5d3
982c0a1
 
 
 
 
 
1f38130
982c0a1
4daf5d3
 
13f0124
 
 
 
 
 
 
 
 
 
4daf5d3
13f0124
 
4daf5d3
13f0124
982c0a1
 
 
18f4cf3
 
 
929051d
097b65d
982c0a1
929051d
982c0a1
 
 
 
 
b6fd487
6d9a0a2
b6fd487
6d9a0a2
 
 
b6fd487
 
 
982c0a1
 
4daf5d3
982c0a1
4daf5d3
 
 
 
982c0a1
50e9487
982c0a1
 
 
6d9a0a2
b6fd487
982c0a1
 
 
4daf5d3
982c0a1
 
 
4daf5d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c90862
a97efd2
 
 
 
982c0a1
 
 
 
 
3453916
4daf5d3
3453916
 
 
 
 
982c0a1
 
 
 
 
 
 
 
 
 
 
 
 
aa50c4b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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 joblib
import os
from date_features import getDateFeatures


# Get the current directory path
current_dir = os.path.dirname(os.path.abspath(__file__))

# Load the model from the pickle file
model_path = os.path.join(current_dir, 'model.pkl')
model = joblib.load(model_path)

# Load the scaler from the pickle file
encoder_path = os.path.join(current_dir, 'encoder.pkl')
encoder = joblib.load(encoder_path)


# Set Page Configurations
st.set_page_config(page_title="Sales Prediction App", page_icon="fas fa-chart-line", layout="wide", initial_sidebar_state="auto")

# Set up sidebar
st.sidebar.header('Navigation')
menu = ['Home', 'About']
choice = st.sidebar.selectbox("Select an option", menu)

# predict function
def predict(sales_data):
    if sales_data.empty:
        raise ValueError("No sales data provided.")

    else:
        # Perform the necessary data processing steps
        sales_data = getDateFeatures(sales_data).set_index('date')
        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']
        
        num = sales_data[numeric_columns]
        encoded_cat = encoder.transform(sales_data[categoric_columns])
        sales_data = pd.concat([num, encoded_cat], axis=1)
    
        # Make predictions using the pre-trained model
        predicted_sales = model.predict(sales_data)
    
        return predicted_sales

# Home section
if choice == 'Home':
    # Set Page Title
    st.title('SEER- A Sales Forecasting APP')
    
    # Loading GIF
    gif_url = "https://i.gifer.com/7BzK.gif"
    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.markdown('Enter the required information to forecast sales:')

    # defining input parameters
    Store_type = ["Supermarket", "Department Store", "Convenience Store", "Pharmacy", "Clothing Store", "Electronics Store", "Furniture Store", "Hardware Store", "Bookstore", "Jewelry Store", "Toy Store", "Pet Store", "Sporting Goods Store", "Shoe Store", "Dollar Store", "Liquor Store", "Beauty Supply Store", "Home Improvement Store", "Stationery Store", "Gift Shop", "Bakery", "Butcher Shop", "Fish Market", "Vegetable Market", "Farmers Market", "Coffee Shop", "Café", "Restaurant", "Fast Food Restaurant", "Pizza Place", "Burger Joint", "Ice Cream Shop", "Food Truck", "Bar", "Pub", "Nightclub", "Gas Station", "Car Dealership", "Auto Repair Shop", "Car Wash", "Bank", "ATM", "Post Office", "Laundry", "Hair Salon", "Nail Salon", "Spa", "Gym", "Yoga Studio", "Movie Theater", "Bowling Alley", "Arcade", "Museum", "Art Gallery"]
    Store_id = ['Store_' + str(i) for i in range(0, 5)]
    cities = ["Lagos", "Abuja", "Kano", "Ibadan", "Kaduna", "Port Harcourt", "Benin City", "Maiduguri", "Zaria", "Aba", "Jos", "Ilorin", "Oyo", "Enugu", "Abeokuta", "Onitsha", "Warri", "Sokoto", "Calabar", "Katsina", "Akure", "Bauchi"]
    clusters = ["Fashion", "Electronics", "Supermarket", "Home Improvement", "Department Store","Pharmacy", "Furniture", "Sports Goods", "Jewelry", "Cosmetics", "Automotive","Bookstore", "Toy Store", "Pet Store", "Convenience Store", "Hardware Store","Outdoor Recreation"]
    categories = ["Apparel", "Beauty", "Books", "Electronics", "Furniture", "Grocery", "Health", "Home", "Jewelry", "Kitchen", "Music", "Office", "Outdoors", "Pets", "Shoes", "Sports", "Toys", "Automotive", "Baby", "Computers", "Garden", "Movies", "Tools", "Watches", "Appliances", "Cameras", "Fitness", "Industrial", "Luggage", "Software", "Video Games", "Cell Phones", "Home Improvement"]
    
    # Input form
    col1, col2 = st.columns(2)

    with col1:
        start_date = st.date_input("Start Date")
        # Convert the date to datetime format
        start_date = pd.to_datetime(start_date)
        end_date = st.date_input("End Date")
        # Convert the date to datetime format
        end_date = pd.to_datetime(end_date)
        onpromotion = st.number_input("How many products are on promotion?", min_value=0, step=1)
        selected_category = st.selectbox("Product_Category", categories)


    with col2:
        selected_store = st.selectbox("Store_type", Store_type)
        selected_store1 = st.selectbox("Store_id", Store_id)
        selected_city = st.selectbox("City", cities)
        selected_cluster = st.selectbox("Cluster", clusters)

    predicted_data = pd.DataFrame(columns=['Start Date', 'End Date', 'Store', 'Category', 'On Promotion', 'City', 'Cluster', 'Predicted Sales'])


    if st.button('Predict'):
        if start_date > end_date:
            st.error("Start date should be earlier than the end date.")
        else:
            with st.spinner('Predicting sales...'):
                sales_data = pd.DataFrame({
                    'date': pd.date_range(start=start_date, end=end_date),
                    'store_id': [selected_store] * len(pd.date_range(start=start_date, end=end_date)),
                    'category_id': [selected_category] * len(pd.date_range(start=start_date, end=end_date)),
                    'onpromotion': [onpromotion] * len(pd.date_range(start=start_date, end=end_date)),
                    'city': [selected_city] * len(pd.date_range(start=start_date, end=end_date)),
                    'store_type': [selected_store1] * len(pd.date_range(start=start_date, end=end_date)),
                    'cluster': [selected_cluster] * len(pd.date_range(start=start_date, end=end_date))
                })
                try:
                    sales = predict(sales_data)
                    formatted_sales = round(sales[0], 2)
                    predicted_data = predicted_data.append({
                         'Start Date': start_date,
                         'End Date': end_date,
                         'Store': selected_store,
                         'Category': selected_category,
                         'On Promotion': onpromotion,
                         'City': selected_city,
                         'Cluster': selected_cluster,
                         'Predicted Sales': formatted_sales}, ignore_index=True)

                    st.success(f"Total sales for the period is: #{formatted_sales}")
                except ValueError as e:
                    st.error(str(e))
                    
    if st.button('Clear Data'):
        predicted_data = pd.DataFrame(columns=['Start Date', 'End Date', 'Store', 'Category', 'On Promotion', 'City', 'Cluster', 'Predicted Sales'])
        st.success("Data cleared successfully.")



# About section
elif choice == 'About':
    # Load the banner image
    banner_image_url = "https://guardian.ng/wp-content/uploads/2017/03/Sales-targets.jpg"
 
    # Display the banner image
    st.image(
        banner_image_url, 
        use_column_width=True, 
        width=400)
    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)