Download app.py from Meenakshi9182/ChurnGuardAI-PredictCustomerExitWithDeepLearning: direct link, hf CLI and curl.
- Browser
- Download file 2.88 kB
-
https://huggingface.co/spaces/Meenakshi9182/ChurnGuardAI-PredictCustomerExitWithDeepLearning/resolve/main/app.py
- Command line
-
hf download hf://spaces/Meenakshi9182/ChurnGuardAI-PredictCustomerExitWithDeepLearning/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Meenakshi9182/ChurnGuardAI-PredictCustomerExitWithDeepLearning/resolve/main/app.py
2.88 kB
| import pandas as pd | |
| from tensorflow.keras.models import load_model | |
| import pickle | |
| import streamlit as st | |
| with open('preprocessor.pkl', 'rb') as f: | |
| preprocessor = pickle.load(f) | |
| ann_model = load_model('ann_model.keras') | |
| df = pd.read_csv('customer_churn_1M.csv') | |
| st.title("ChurnGuard AI: Predict Customer Exit with Deep Learning") | |
| st.image('Customer_Churn_Prediction_-_AI__Analytics___Retention_Tips-1764682187258.webp') | |
| age = st.number_input("Age", min_value=18, max_value=100) | |
| gender = st.selectbox("Gender", df['gender'].unique()) | |
| annual_income = st.number_input("Annual Income", min_value=0.0) | |
| education = st.selectbox("Education", df['education'].unique()) | |
| marital_status = st.selectbox("Marital Status", df['marital_status'].unique()) | |
| dependents= st.number_input("Dependents", min_value=0, max_value=10) | |
| tenure = st.number_input("Tenure", min_value=0, max_value=50) | |
| contract = st.selectbox("Contract Type", df['contract'].unique()) | |
| payment_method = st.selectbox("Payment Method", df['payment_method'].unique()) | |
| credit_score = st.number_input("Credit Score", min_value=300, max_value=900) | |
| def model(): | |
| input_data = pd.DataFrame([{ | |
| "age": age, | |
| "gender": gender, | |
| "annual_income": annual_income, | |
| "education": education, | |
| "marital_status": marital_status, | |
| "dependents": dependents, | |
| "tenure": tenure, | |
| "contract": contract, | |
| "payment_method": payment_method, | |
| "credit_score": credit_score, | |
| # 👉 Add ALL missing columns with defaults | |
| "avg_monthly_gb": 0, | |
| "has_streaming_tv": "No", | |
| "customer_age_days": 0, | |
| "senior_citizen": 0, | |
| "late_payments": 0, | |
| "totalcharges": 0, | |
| "paperless_billing": "No", | |
| "has_tech_support": "No", | |
| "has_online_security": "No", | |
| "monthlycharges": 0, | |
| "has_device_protection": "No", | |
| "has_phone_service": "Yes", | |
| "customer_satisfaction": 3, | |
| "has_internet_service": "Yes", | |
| "has_streaming_movies": "No", | |
| "days_since_last_interaction": 0, | |
| "num_complaints": 0, | |
| "has_online_backup": "No", | |
| "num_service_calls": 0 | |
| }]) | |
| data=preprocessor.transform(input_data) | |
| pred = ann_model.predict(data) | |
| return pred[0][0] | |
| if st.button('predict'): | |
| result=model() | |
| if st.button('predict', key='predict_button'): | |
| result = model() | |
| if result > 0.5: | |
| st.error("High Churn Risk Detected!") | |
| st.markdown("This customer is **likely to leave**. Consider proactive retention strategies like personalized offers or engagement.") | |
| else: | |
| st.success(" Customer Retention Likely") | |
| st.markdown("This customer is **likely to stay**. Maintain engagement to ensure continued satisfaction.") |