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("

Sales Prediction App

", 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 = """ """ # 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)