Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +107 -0
- dt_model.pkl +3 -0
- requirements.txt +8 -0
- stock.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
import numpy as np
|
4 |
+
from matplotlib import pyplot as plt
|
5 |
+
import pickle
|
6 |
+
import sklearn
|
7 |
+
from PIL import Image
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
# Load the saved components
|
12 |
+
with open("dt_model.pkl", "rb") as f:
|
13 |
+
components = pickle.load(f)
|
14 |
+
|
15 |
+
# Extract the individual components
|
16 |
+
num_imputer = components["num_imputer"]
|
17 |
+
cat_imputer = components["cat_imputer"]
|
18 |
+
encoder = components["encoder"]
|
19 |
+
scaler = components["scaler"]
|
20 |
+
dt_model = components["models"]
|
21 |
+
|
22 |
+
# Create the app
|
23 |
+
|
24 |
+
st.set_page_config(
|
25 |
+
layout="wide"
|
26 |
+
)
|
27 |
+
|
28 |
+
|
29 |
+
# Add an image or logo to the app
|
30 |
+
image = Image.open('grocery_store.jpg')
|
31 |
+
|
32 |
+
# Open the image file
|
33 |
+
st.image(image)
|
34 |
+
|
35 |
+
|
36 |
+
#add app title
|
37 |
+
st.title(":moneybag: SALES PREDICTION MACHINE LEARNING APP :moneybag:")
|
38 |
+
|
39 |
+
|
40 |
+
# Add some text
|
41 |
+
st.write("Enter some data for Prediction.")
|
42 |
+
|
43 |
+
# Create the input fields
|
44 |
+
input_data = {}
|
45 |
+
col1,col2,col3 = st.columns(3)
|
46 |
+
with col1:
|
47 |
+
input_data['store_nbr'] = st.slider("store_nbr",0,54)
|
48 |
+
input_data['products'] = st.selectbox("products", ['AUTOMOTIVE', 'CLEANING', 'BEAUTY', 'FOODS', 'STATIONERY',
|
49 |
+
'CELEBRATION', 'GROCERY', 'HARDWARE', 'HOME', 'LADIESWEAR',
|
50 |
+
'LAWN AND GARDEN', 'CLOTHING', 'LIQUOR,WINE,BEER', 'PET SUPPLIES'])
|
51 |
+
input_data['onpromotion'] =st.number_input("onpromotion",step=1)
|
52 |
+
input_data['state'] = st.selectbox("state", ['Pichincha', 'Cotopaxi', 'Chimborazo', 'Imbabura',
|
53 |
+
'Santo Domingo de los Tsachilas', 'Bolivar', 'Pastaza',
|
54 |
+
'Tungurahua', 'Guayas', 'Santa Elena', 'Los Rios', 'Azuay', 'Loja',
|
55 |
+
'El Oro', 'Esmeraldas', 'Manabi'])
|
56 |
+
with col2:
|
57 |
+
input_data['store_type'] = st.selectbox("store_type",['D', 'C', 'B', 'E', 'A'])
|
58 |
+
input_data['cluster'] = st.number_input("cluster",step=1)
|
59 |
+
input_data['dcoilwtico'] = st.number_input("dcoilwtico",step=1)
|
60 |
+
input_data['year'] = st.number_input("year",step=1)
|
61 |
+
with col3:
|
62 |
+
input_data['month'] = st.slider("month",1,12)
|
63 |
+
input_data['day'] = st.slider("day",1,31)
|
64 |
+
input_data['dayofweek'] = st.number_input("dayofweek,0=Sun and 6=Sat",step=1)
|
65 |
+
input_data['end_month'] = st.selectbox("end_month",['True','False'])
|
66 |
+
|
67 |
+
|
68 |
+
# Create a button to make a prediction
|
69 |
+
|
70 |
+
if st.button("Predict"):
|
71 |
+
# Convert the input data to a pandas DataFrame
|
72 |
+
input_df = pd.DataFrame([input_data])
|
73 |
+
|
74 |
+
|
75 |
+
# Selecting categorical and numerical columns separately
|
76 |
+
cat_columns = [col for col in input_df.columns if input_df[col].dtype == 'object']
|
77 |
+
num_columns = [col for col in input_df.columns if input_df[col].dtype != 'object']
|
78 |
+
|
79 |
+
|
80 |
+
# Apply the imputers
|
81 |
+
input_df_imputed_cat = cat_imputer.transform(input_df[cat_columns])
|
82 |
+
input_df_imputed_num = num_imputer.transform(input_df[num_columns])
|
83 |
+
|
84 |
+
|
85 |
+
# Encode the categorical columns
|
86 |
+
input_encoded_df = pd.DataFrame(encoder.transform(input_df_imputed_cat).toarray(),
|
87 |
+
columns=encoder.get_feature_names(cat_columns))
|
88 |
+
|
89 |
+
# Scale the numerical columns
|
90 |
+
input_df_scaled = scaler.transform(input_df_imputed_num)
|
91 |
+
input_scaled_df = pd.DataFrame(input_df_scaled , columns = num_columns)
|
92 |
+
|
93 |
+
#joining the cat encoded and num scaled
|
94 |
+
final_df = pd.concat([input_encoded_df, input_scaled_df], axis=1)
|
95 |
+
|
96 |
+
# Make a prediction
|
97 |
+
prediction =dt_model.predict(final_df)[0]
|
98 |
+
|
99 |
+
|
100 |
+
# Display the prediction
|
101 |
+
st.write(f"The predicted sales are: {prediction}.")
|
102 |
+
input_df.to_csv("data.csv", index=False)
|
103 |
+
st.table(input_df)
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
|
dt_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4c48c2b830b10599782588fb9850ab1fffc099a4af0bf970e341cfa6710b1f81
|
3 |
+
size 130142917
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit ==1.24.1
|
2 |
+
pandas ==2.0.3
|
3 |
+
numpy ==1.25.1
|
4 |
+
matplotlib ==3.7.2
|
5 |
+
scikit-learn ==1.2.2
|
6 |
+
pickleshare==0.7.5
|
7 |
+
cycler == 0.11.0
|
8 |
+
decorator == 5.1.1
|
stock.jpg
ADDED