Spaces:
Sleeping
Sleeping
import pandas as pd | |
import streamlit as st | |
import pickle | |
from sklearn.preprocessing import MinMaxScaler | |
# Load the scaler and model | |
with open('model_and_scaler.pkl', 'rb') as file: | |
model_and_scaler = pickle.load(file) | |
# Extract the scaler and model | |
scaler = model_and_scaler['scaler'] | |
rf_model = model_and_scaler['model'] | |
# Define app title and description | |
st.image("https://pbs.twimg.com/media/DywhyJiXgAIUZej?format=jpg&name=medium") | |
st.title("Store Sales Prediction App") | |
st.caption("This app predicts sales patterns in different stores based on the inputs.") | |
# Sidebar with input field descriptions | |
st.sidebar.header("Description of The Required Input Fields") | |
st.sidebar.markdown("**Shop ID**: Unique identifier for a specific shop.") | |
st.sidebar.markdown("**Item ID**: Unique identifier for a product.") | |
st.sidebar.markdown("**Item Price**: Current price of an item.") | |
st.sidebar.markdown("**Item Category ID**: Unique identifier for an item category.") | |
st.sidebar.markdown("**Day**: Day the product was purchased.") | |
st.sidebar.markdown("**Month**: Month the product was purchased.") | |
st.sidebar.markdown("**Year**: Year the product was purchased.") | |
# Create the input fields | |
input_data = {} | |
col1, col2 = st.columns(2) | |
with col1: | |
input_data['shop_id'] = st.slider("Shop ID", 0, 54) | |
input_data['item_id'] = st.slider("Item ID", 100000, 1022169) | |
input_data['item_price'] = st.number_input("Item Price", 0, 153990) | |
input_data['item_category_id'] = st.slider("Item Category ID", 0, 166) | |
with col2: | |
input_data['day'] = st.slider("Day", 1, 31) | |
input_data['month'] = st.slider("Month", 1, 12, value=6) | |
input_data['year'] = st.number_input("Year", 2018, 2020, value=2020, step=1) | |
# Create a button to make a prediction | |
if st.button("Predict"): | |
# Feature Scaling | |
numerical_cols = ['day', 'month', 'year', 'shop_id', 'item_id', 'item_price', 'item_category_id'] | |
input_df = pd.DataFrame(input_data, index=[0])[numerical_cols] | |
# Make predictions using the trained model | |
predictions = rf_model.predict(input_df) | |
# Display the predicted sales value to the user | |
st.write("The predicted sales are:", predictions[0]) |