import pandas as pd import streamlit as st import numpy as np import pickle from sklearn.preprocessing import MinMaxScaler 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("**Total Sales**: The total daily sales.") 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) input_data['year'] = st.number_input("Year", 2018, 2019, 2020) # Create a button to make a prediction if st.button("Predict"): # Feature Scaling numerical_cols = ['shop_id', 'item_id', 'item_price', 'item_category_id', 'total_sales', 'day', 'month', 'year', 'day_of_week'] scaler = MinMaxScaler() input_df = pd.DataFrame(input_data, index=[0]) input_df_scaled = scaler.fit_transform(input_df[numerical_cols]) input_df_scaled = pd.DataFrame(input_df_scaled, columns=numerical_cols) # Load the scaler and model with open('model_and_scaler.pkl', 'rb') as file: model_and_scaler = pickle.load(file) # Extract the model rf_model = model_and_scaler['model'] # Make predictions using the trained model predictions = rf_model.predict(input_df_scaled) # Display the predicted sales value to the user st.write("The predicted sales are:", predictions[0])