CoolFace
Apppublic

PaviRaju/Predictive-Engine-Failure-Analysis

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
app.py50 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3from huggingface_hub import hf_hub_download4import joblib5 6# Download the model from the Model Hub7model_path = hf_hub_download(repo_id="PaviRaju/churn-model", filename="best_churn_model.joblib")8 9# Load the model10model = joblib.load(model_path)11 12# Streamlit UI for Customer Churn Prediction13st.title("Customer Churn Prediction App")14st.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.")15st.write("Kindly enter the customer details to check whether they are likely to churn.")16 17# Collect user input18CreditScore = st.number_input("Credit Score (customer's credit score)", min_value=300, max_value=900, value=650)19Geography = st.selectbox("Geography (country where the customer resides)", ["France", "Germany", "Spain"])20Age = st.number_input("Age (customer's age in years)", min_value=18, max_value=100, value=30)21Tenure = st.number_input("Tenure (number of years the customer has been with the bank)", value=12)22Balance = st.number_input("Account Balance (customer’s account balance)", min_value=0.0, value=10000.0)23NumOfProducts = st.number_input("Number of Products (number of products the customer has with the bank)", min_value=1, value=1)24HasCrCard = st.selectbox("Has Credit Card?", ["Yes", "No"])25IsActiveMember = st.selectbox("Is Active Member?", ["Yes", "No"])26EstimatedSalary = st.number_input("Estimated Salary (customer’s estimated salary)", min_value=0.0, value=50000.0)27 28# Convert categorical inputs to match model training29input_data = pd.DataFrame([{30    'CreditScore': CreditScore,31    'Geography': Geography,32    'Age': Age,33    'Tenure': Tenure,34    'Balance': Balance,35    'NumOfProducts': NumOfProducts,36    'HasCrCard': 1 if HasCrCard == "Yes" else 0,37    'IsActiveMember': 1 if IsActiveMember == "Yes" else 0,38    'EstimatedSalary': EstimatedSalary39}])40 41# Set the classification threshold42classification_threshold = 0.4543 44# Predict button45if st.button("Predict"):46    prediction_proba = model.predict_proba(input_data)[0, 1]47    prediction = (prediction_proba >= classification_threshold).astype(int)48    result = "churn" if prediction == 1 else "not churn"49    st.write(f"Based on the information provided, the customer is likely to {result}.")50