Application file
Browse files- .gitignore +5 -0
- app.py +117 -0
- best_model.pkl +3 -0
- requirements.txt +5 -0
.gitignore
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
.ipynb_checkpoints/
|
3 |
+
venv/
|
4 |
+
|
5 |
+
|
app.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import joblib
|
4 |
+
|
5 |
+
# Load your churn prediction model
|
6 |
+
model = joblib.load('best_model.pkl')
|
7 |
+
|
8 |
+
# Create a Gradio interface
|
9 |
+
def predict_churn(SeniorCitizen, Partner, Dependents, tenure, InternetService,
|
10 |
+
OnlineSecurity, OnlineBackup, DeviceProtection, TechSupport,
|
11 |
+
StreamingTV, StreamingMovies, Contract, PaperlessBilling,
|
12 |
+
PaymentMethod, MonthlyCharges, TotalCharges):
|
13 |
+
|
14 |
+
# Create a dictionary with input features
|
15 |
+
input_data = {
|
16 |
+
'SeniorCitizen': SeniorCitizen,
|
17 |
+
'Partner': Partner,
|
18 |
+
'Dependents': Dependents,
|
19 |
+
'tenure': tenure,
|
20 |
+
'InternetService': InternetService,
|
21 |
+
'OnlineSecurity': OnlineSecurity,
|
22 |
+
'OnlineBackup': OnlineBackup,
|
23 |
+
'DeviceProtection': DeviceProtection,
|
24 |
+
'TechSupport': TechSupport,
|
25 |
+
'StreamingTV': StreamingTV,
|
26 |
+
'StreamingMovies': StreamingMovies,
|
27 |
+
'Contract': Contract,
|
28 |
+
'PaperlessBilling': PaperlessBilling,
|
29 |
+
'PaymentMethod': PaymentMethod,
|
30 |
+
'MonthlyCharges': MonthlyCharges,
|
31 |
+
'TotalCharges': TotalCharges
|
32 |
+
}
|
33 |
+
|
34 |
+
# Create a DataFrame from the input data
|
35 |
+
input_df = pd.DataFrame([input_data])
|
36 |
+
|
37 |
+
# Make predictions
|
38 |
+
prediction = model.predict(input_df)
|
39 |
+
|
40 |
+
|
41 |
+
# Determine the churn prediction
|
42 |
+
if prediction[0] == 0:
|
43 |
+
churn_result = '<span style="color: limegreen;font-size:20px;">Customer will not churn</span>'
|
44 |
+
else:
|
45 |
+
churn_result = '<span style="color: red;font-size:20px;">Customer will churn</span>'
|
46 |
+
|
47 |
+
return churn_result
|
48 |
+
|
49 |
+
# Define Gradio components
|
50 |
+
with gr.Blocks(theme=gr.themes.Base(primary_hue="stone",neutral_hue="stone")) as block:
|
51 |
+
gr.Markdown(
|
52 |
+
"""# 👋 Welcome to Team Cape Cod's Churn Prediction App
|
53 |
+
|
54 |
+
This App predicts whether a customer will churn or not""")
|
55 |
+
|
56 |
+
with gr.Row():
|
57 |
+
with gr.Column():
|
58 |
+
SeniorCitizen = gr.Radio(["Yes", "No"], label="Are you a Senior Citizen?")
|
59 |
+
Partner = gr.Radio(["Yes", "No"], label="Do you have a partner?")
|
60 |
+
Dependents = gr.Radio(["Yes", "No"], label="Do you have dependents?")
|
61 |
+
tenure = gr.Number(label="Tenure (months): How long have you been at the company")
|
62 |
+
InternetService = gr.Radio(["DSL", "Fiber optic", "No"], label="What Internet Service Do You Use?")
|
63 |
+
OnlineSecurity = gr.Radio(["Yes", "No", "No internet service"], label="Do You Have Online Security?")
|
64 |
+
|
65 |
+
with gr.Column():
|
66 |
+
OnlineBackup = gr.Radio(["Yes", "No", "No internet service"], label="Do You Have Any Online Backup Service?")
|
67 |
+
DeviceProtection = gr.Radio(["Yes", "No", "No internet service"], label="Do You Use Any Device Protection?")
|
68 |
+
TechSupport = gr.Radio(["Yes", "No", "No internet service"], label="Do You Use TechSupport?")
|
69 |
+
StreamingTV = gr.Radio(["Yes", "No", "No internet service"], label="Do You Stream TV?")
|
70 |
+
StreamingMovies = gr.Radio(["Yes", "No", "No internet service"], label="Do You Stream Movies?")
|
71 |
+
|
72 |
+
with gr.Column():
|
73 |
+
Contract = gr.Radio(["Month-to-month", "One year", "Two year"], label="What Is Your Contract Type?")
|
74 |
+
PaperlessBilling = gr.Radio(["Yes", "No"], label="Do You Use Paperless Billing?")
|
75 |
+
PaymentMethod = gr.Dropdown(["Electronic check", "Mailed check", "Bank transfer (automatic)", "Credit card (automatic)"], label="What Payment Method Do You Use?")
|
76 |
+
MonthlyCharges = gr.Number(label="What is your Monthly Charge?")
|
77 |
+
TotalCharges = gr.Number(label="What are your Total Charges?")
|
78 |
+
|
79 |
+
|
80 |
+
#create a variable that clear button will clear
|
81 |
+
input_components = [SeniorCitizen, Partner, Dependents, tenure,
|
82 |
+
InternetService, OnlineSecurity, OnlineBackup, DeviceProtection,
|
83 |
+
TechSupport, StreamingTV, StreamingMovies, Contract, PaperlessBilling,
|
84 |
+
PaymentMethod, MonthlyCharges, TotalCharges]
|
85 |
+
|
86 |
+
#Create a button user will click to clear inputs selected
|
87 |
+
gr.ClearButton(input_components)
|
88 |
+
|
89 |
+
#create markdown for ouput
|
90 |
+
text = gr.Markdown("## Churn Status")
|
91 |
+
|
92 |
+
# Define Gradio outputs
|
93 |
+
output = gr.HTML("Awaiting Prediction")
|
94 |
+
|
95 |
+
# Create a button
|
96 |
+
button = gr.Button("Predict")
|
97 |
+
|
98 |
+
# Create Gradio interface
|
99 |
+
button.click(fn=predict_churn,inputs=input_components, outputs=output)
|
100 |
+
|
101 |
+
#create an example dataframe
|
102 |
+
gr.Markdown("## Input Examples")
|
103 |
+
|
104 |
+
gr.Examples([['No', 'No', 'No', '12', 'Fiber optic', 'No', 'No', 'No', 'No', 'Yes', 'No', 'Month-to-month', 'Yes', 'Electronic check', '84.45', '1059.55'],
|
105 |
+
|
106 |
+
['No', 'No', 'No', '9', 'No', 'No internet service', 'No internet service', 'No internet service', 'No internet service', 'No internet service', 'No internet service', 'Month-to-month', 'No', 'Mailed check', '20.40', '181.80'],
|
107 |
+
|
108 |
+
['No', 'No', 'No', '27', 'DSL', 'Yes', 'No', 'Yes', 'Yes', 'Yes', 'Yes', 'One year', 'No', 'Electronic check', '81.70', '2212.55']],
|
109 |
+
|
110 |
+
inputs=input_components)
|
111 |
+
|
112 |
+
#start gradio app
|
113 |
+
block.launch(
|
114 |
+
auth=("azubiafrica", "teamcapecod"),
|
115 |
+
auth_message="Enter the username 'azubiafrica' and password 'teamcapecod' for this demo app"
|
116 |
+
)
|
117 |
+
|
best_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:09bdc833b302834fb10202f3baa4ea24b159082c3d3d08b7acf7e8217d878bf1
|
3 |
+
size 8707
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.45.2
|
2 |
+
joblib==1.2.0
|
3 |
+
numpy==1.24.3
|
4 |
+
pandas==2.0.2
|
5 |
+
scikit-learn==1.2.2
|