Lokiiparihar's picture
Update app.py
e64d081 verified
Raw
History Blame Contribute Delete
1.78 kB
import streamlit as st
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download
@st.cache_resource
def load_model():
model_path = hf_hub_download(
repo_id='Lokiiparihar/churn-model', # fix case
filename='best_churn_model.joblib'
)
return joblib.load(model_path)
model = load_model()
st.title("Customer Churn Prediction App")
st.write("The Customer Churn Prediction App is an internal tool for bank staff that predicts whether customers are at risk of churning based on their details.")
st.write("Kindly enter the customer details to check whether they are likely to churn.")
CreditScore = st.number_input("Credit Score", 300, 900, 650)
Geography = st.selectbox("Geography", ["France", "Germany", "Spain"])
Age = st.number_input("Age", 18, 100, 30)
Tenure = st.number_input("Tenure", value=12)
Balance = st.number_input("Balance", min_value=0.0, value=10000.0)
NumOfProducts = st.number_input("Num Of Products", min_value=1, value=1)
HasCrCard = st.selectbox("Has Credit Card?", ["Yes", "No"])
IsActiveMember = st.selectbox("Is Active Member?", ["Yes", "No"])
EstimatedSalary = st.number_input("Estimated Salary", min_value=0.0, value=50000.0)
input_data = pd.DataFrame([{
'CreditScore': CreditScore,
'Geography': Geography,
'Age': Age,
'Tenure': Tenure,
'Balance': Balance,
'NumOfProducts': NumOfProducts,
'HasCrCard': 1 if HasCrCard == "Yes" else 0,
'IsActiveMember': 1 if IsActiveMember == "Yes" else 0,
'EstimatedSalary': EstimatedSalary
}])
threshold = 0.45
if st.button('Predict'):
proba = model.predict_proba(input_data)[0][1]
prediction = 1 if proba >= threshold else 0
result = 'Churn' if prediction == 1 else 'Not Churn'
st.write(f"Prediction: {result}")