sheltonmaharesh commited on
Commit
c741b95
·
verified ·
1 Parent(s): a9db6c4

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +15 -0
  2. app.py +48 -0
  3. customer_churn_pipeline.joblib +3 -0
  4. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # Create non-root user (required by Hugging Face)
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+ ENV PATH="/home/user/.local/bin:$PATH"
7
+
8
+ WORKDIR /app
9
+
10
+ COPY --chown=user requirements.txt .
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ COPY --chown=user . .
14
+
15
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import os
4
+ from joblib import load
5
+
6
+ # --- Model Loading ---
7
+ @st.cache_resource
8
+ def load_model():
9
+ model_path = "customer_churn_pipeline.joblib" # same folder
10
+ if not os.path.exists(model_path):
11
+ st.error(f"Model file not found: {model_path}")
12
+ st.stop()
13
+ try:
14
+ pipeline = load(model_path)
15
+ except Exception as e:
16
+ st.error(f"Failed to load model: {e}")
17
+ st.stop()
18
+ return pipeline
19
+
20
+ pipeline = load_model()
21
+
22
+ # --- Streamlit UI ---
23
+ st.title("Credit Card Customer Churn Prediction")
24
+ st.write("Adjust the input values below to predict whether a customer will churn:")
25
+
26
+ # Numeric inputs
27
+ customer_age = st.slider("Customer Age", 18, 100, 30)
28
+ credit_limit = st.slider("Credit Limit", 0, 100000, 5000, step=100)
29
+
30
+ # Categorical input
31
+ gender = st.selectbox("Gender", ["Female", "Male"])
32
+
33
+ # Build input dataframe
34
+ input_data = pd.DataFrame({
35
+ 'Customer_Age': [customer_age],
36
+ 'Credit_Limit': [credit_limit],
37
+ 'Gender': [gender]
38
+ })
39
+
40
+ # Predict button
41
+ if st.button("Predict Churn"):
42
+ prediction = pipeline.predict(input_data)[0]
43
+ probability = pipeline.predict_proba(input_data)[0][1]
44
+
45
+ if prediction == 1:
46
+ st.warning(f"⚠️ Customer is likely to churn! Probability: {probability:.2%}")
47
+ else:
48
+ st.success(f"✅ Customer is not likely to churn. Probability: {probability:.2%}")
customer_churn_pipeline.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f04518cc0cd086023ea8fab1d2b8663c50293cfa6db17a201e68cb79cd34220f
3
+ size 14835074
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ scikit-learn==1.6.1
5
+ matplotlib
6
+ seaborn
7
+ joblib==1.4.2