Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import os | |
| from joblib import load | |
| # --- Model Loading --- | |
| def load_model(): | |
| model_path = "customer_churn_pipeline.joblib" # same folder | |
| if not os.path.exists(model_path): | |
| st.error(f"Model file not found: {model_path}") | |
| st.stop() | |
| try: | |
| pipeline = load(model_path) | |
| except Exception as e: | |
| st.error(f"Failed to load model: {e}") | |
| st.stop() | |
| return pipeline | |
| pipeline = load_model() | |
| # --- Streamlit UI --- | |
| st.title("Credit Card Customer Churn Prediction") | |
| st.write("Adjust the input values below to predict whether a customer will churn:") | |
| # Numeric inputs | |
| customer_age = st.slider("Customer Age", 18, 100, 30) | |
| credit_limit = st.slider("Credit Limit", 0, 100000, 5000, step=100) | |
| # Categorical input | |
| gender = st.selectbox("Gender", ["Female", "Male"]) | |
| # Build input dataframe | |
| input_data = pd.DataFrame({ | |
| 'Customer_Age': [customer_age], | |
| 'Credit_Limit': [credit_limit], | |
| 'Gender': [gender] | |
| }) | |
| # Predict button | |
| if st.button("Predict Churn"): | |
| prediction = pipeline.predict(input_data)[0] | |
| probability = pipeline.predict_proba(input_data)[0][1] | |
| if prediction == 1: | |
| st.warning(f"⚠️ Customer is likely to churn! Probability: {probability:.2%}") | |
| else: | |
| st.success(f"✅ Customer is not likely to churn. Probability: {probability:.2%}") |