Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +8 -14
- app.py +49 -0
- churn_prediction_model_v1_0.joblib +3 -0
- requirements.txt +6 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,14 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
-
|
| 11 |
-
COPY requirements.txt ./
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
|
|
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
-
|
| 20 |
-
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# Set the working directory inside the container to /app
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# Copy all files from the current directory on the host to the container's /app directory
|
| 8 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Install Python dependencies listed in requirements.txt
|
| 11 |
RUN pip3 install -r requirements.txt
|
| 12 |
|
| 13 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
def load_model():
|
| 8 |
+
return joblib.load("churn_prediction_model_v1_0.joblib")
|
| 9 |
+
|
| 10 |
+
model = load_model()
|
| 11 |
+
|
| 12 |
+
# Streamlit UI for Customer Churn Prediction
|
| 13 |
+
st.title("Customer Churn Prediction App")
|
| 14 |
+
st.write("This tool predicts customer churn risk based on their details. Enter the required information below.")
|
| 15 |
+
|
| 16 |
+
# Collect user input based on dataset columns
|
| 17 |
+
Partner = st.selectbox("Does the customer have a partner?", ["Yes", "No"])
|
| 18 |
+
Dependents = st.selectbox("Does the customer have dependents?", ["Yes", "No"])
|
| 19 |
+
PhoneService = st.selectbox("Does the customer have phone service?", ["Yes", "No"])
|
| 20 |
+
InternetService = st.selectbox("Type of Internet Service", ["DSL", "Fiber optic", "No"])
|
| 21 |
+
Contract = st.selectbox("Type of Contract", ["Month-to-month", "One year", "Two year"])
|
| 22 |
+
PaymentMethod = st.selectbox("Payment Method", ["Electronic check", "Mailed check", "Bank transfer", "Credit card"])
|
| 23 |
+
Tenure = st.number_input("Tenure (Months with the company)", min_value=0, value=12)
|
| 24 |
+
MonthlyCharges = st.number_input("Monthly Charges", min_value=0.0, value=50.0)
|
| 25 |
+
TotalCharges = st.number_input("Total Charges", min_value=0.0, value=600.0)
|
| 26 |
+
|
| 27 |
+
# Convert categorical inputs to match model training
|
| 28 |
+
input_data = pd.DataFrame([{
|
| 29 |
+
'Partner': 1 if Partner == "Yes" else 0,
|
| 30 |
+
'Dependents': 1 if Dependents == "Yes" else 0,
|
| 31 |
+
'PhoneService': 1 if PhoneService == "Yes" else 0,
|
| 32 |
+
'InternetService': InternetService,
|
| 33 |
+
'Contract': Contract,
|
| 34 |
+
'PaymentMethod': PaymentMethod,
|
| 35 |
+
'Tenure': Tenure,
|
| 36 |
+
'MonthlyCharges': MonthlyCharges,
|
| 37 |
+
'TotalCharges': TotalCharges
|
| 38 |
+
}])
|
| 39 |
+
|
| 40 |
+
# Set classification threshold
|
| 41 |
+
classification_threshold = 0.5
|
| 42 |
+
|
| 43 |
+
# Predict button
|
| 44 |
+
if st.button("Predict"):
|
| 45 |
+
prediction_proba = model.predict_proba(input_data)[0, 1]
|
| 46 |
+
prediction = (prediction_proba >= classification_threshold).astype(int)
|
| 47 |
+
result = "churn" if prediction == 1 else "not churn"
|
| 48 |
+
st.write(f"Prediction: The customer is likely to **{result}**.")
|
| 49 |
+
st.write(f"Churn Probability: {prediction_proba:.2f}")
|
churn_prediction_model_v1_0.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1890379bd8a492620e028476e5e1c8f63cffabc25741b518f80a8c2ef11c919b
|
| 3 |
+
size 340069
|
requirements.txt
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==2.0.2
|
| 3 |
+
scikit-learn==1.6.1
|
| 4 |
+
xgboost==2.1.4
|
| 5 |
+
joblib==1.4.2
|
| 6 |
+
streamlit==1.43.2
|