File size: 4,444 Bytes
ce08d4c
 
926ab8b
 
 
 
 
 
 
 
ce08d4c
 
 
17f565c
8e8fa12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce08d4c
926ab8b
8e8fa12
ce08d4c
 
926ab8b
 
 
 
 
 
ce08d4c
926ab8b
 
 
ce08d4c
926ab8b
ce08d4c
926ab8b
 
 
 
8e8fa12
926ab8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce08d4c
926ab8b
 
 
 
8e8fa12
926ab8b
 
 
8e8fa12
 
926ab8b
 
 
8e8fa12
 
926ab8b
 
 
8e8fa12
 
926ab8b
 
8e8fa12
 
926ab8b
 
8e8fa12
926ab8b
 
 
 
 
 
8e8fa12
926ab8b
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
import pandas as pd
import streamlit as st
import numpy as np
from matplotlib import pyplot as plt
import pickle
import sklearn
import joblib
from PIL import Image
import base64
from transformers import pipeline
import datetime
from huggingface_hub import hf_hub_download

REPO_ID = "albiecofie/predict-customer-churn"

num_imputer = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename="numerical_imputer.joblib")
)

cat_imputer = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename="categorical_imputer.joblib")
)

encoder = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename="encoder.joblib")
)

scaler = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename="scaler.joblib")
)

dt_model = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename="Final_model.joblib")
)

# Add a title and subtitle
st.write("<center><h1>Sales Prediction App</h1></center>", unsafe_allow_html=True)

# Set up the layout
col1, col2, col3 = st.columns([1, 3, 3])


#st.image("https://www.example.com/logo.png", width=200)
# Add a subtitle or description
st.write("This app uses machine learning to predict sales based on certain input parameters. Simply enter the required information and click 'Predict' to get a sales prediction!")

st.subheader("Enter the details to predict sales")

# Add some text
#st.write("Enter some data for Prediction.")

 # Create the input fields
input_data = {}
col1,col2 = st.columns(2)
with col1:
    input_data['store_nbr'] = st.slider("store_nbr",0,54)
    input_data['products'] = st.selectbox("products", ['AUTOMOTIVE', 'CLEANING', 'BEAUTY', 'FOODS', 'STATIONERY',
       'CELEBRATION', 'GROCERY', 'HARDWARE', 'HOME', 'LADIESWEAR',
       'LAWN AND GARDEN', 'CLOTHING', 'LIQUOR,WINE,BEER', 'PET SUPPLIES'])
    input_data['onpromotion'] =st.number_input("onpromotion",step=1)
    input_data['state'] = st.selectbox("state", ['Pichincha', 'Cotopaxi', 'Chimborazo', 'Imbabura',
       'Santo Domingo de los Tsachilas', 'Bolivar', 'Pastaza',
       'Tungurahua', 'Guayas', 'Santa Elena', 'Los Rios', 'Azuay', 'Loja',
       'El Oro', 'Esmeraldas', 'Manabi'])
    input_data['store_type'] = st.selectbox("store_type",['D', 'C', 'B', 'E', 'A'])
    input_data['cluster'] = st.number_input("cluster",step=1)

with col2:
    input_data['dcoilwtico'] = st.number_input("dcoilwtico",step=1)
    input_data['year'] = st.number_input("year",step=1)
    input_data['month'] = st.slider("month",1,12)
    input_data['day'] = st.slider("day",1,31)
    input_data['dayofweek'] = st.number_input("dayofweek,0=Sun and 6=Sat",step=1)
    input_data['end_month'] = st.selectbox("end_month",['True','False'])


# Define CSS style for the download button
# Define the custom CSS
predict_button_css = """
    <style>
    .predict-button {
        background-color: #C4C4C4;
        color: gray;
        padding: 0.75rem 2rem;
        border-radius: 0.5rem;
        border: none;
        font-size: 1.1rem;
        font-weight: bold;
        text-align: center;
        margin-top: 2rem;
    }
    </style>
"""

# Display the custom CSS
st.markdown(predict_button_css, unsafe_allow_html=True)


  # Create a button to make a prediction

if st.button("Predict", key="predict_button", help="Click to make a prediction."):
    # Convert the input data to a pandas DataFrame
        input_df = pd.DataFrame([input_data])


# Selecting categorical and numerical columns separately
        cat_columns = [col for col in input_df.columns if input_df[col].dtype == 'object']
        num_columns = [col for col in input_df.columns if input_df[col].dtype != 'object']


# Apply the imputers
        input_df_imputed_cat = cat_imputer.transform(input_df[cat_columns])
        input_df_imputed_num = num_imputer.transform(input_df[num_columns])


 # Encode the categorical columns
        input_encoded_df = pd.DataFrame(encoder.transform(input_df_imputed_cat).toarray(),
                                   columns=encoder.get_feature_names(cat_columns))

# Scale the numerical columns
        input_df_scaled = scaler.transform(input_df_imputed_num)
        input_scaled_df = pd.DataFrame(input_df_scaled , columns = num_columns)

#joining the cat encoded and num scaled
        final_df = pd.concat([input_encoded_df, input_scaled_df], axis=1)

# Make a prediction
        prediction = dt_model.predict(final_df)[0]


# Display the prediction
        st.write(f"The predicted sales are: {prediction}.")
        st.table(input_df)