Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,8 @@ def predict(gender, SeniorCitizen, Partner, Dependents, Contract, tenure, Monthl
|
|
38 |
'MonthlyCharges': [MonthlyCharges] if MonthlyCharges else [0.0], # Replace None with default value
|
39 |
'TotalCharges': [TotalCharges] if TotalCharges else [0.0] # Replace None with default value
|
40 |
})
|
41 |
-
|
|
|
42 |
# Make predictions using the loaded logistic regression model
|
43 |
#predict probabilities
|
44 |
predictions = full_pipeline.predict_proba(input_data)
|
@@ -118,80 +119,4 @@ with gr.Blocks(css=".gradio-container {background-color: grey}",theme=gr.themes.
|
|
118 |
clear_btn.click(fn=clear, inputs=None, outputs=output)
|
119 |
|
120 |
|
121 |
-
demo.launch(inbrowser = True)
|
122 |
-
|
123 |
-
|
124 |
-
# Make predictions using the loaded logistic regression model
|
125 |
-
predictions = full_pipeline.predict(input_data)
|
126 |
-
|
127 |
-
#return predictions[0]
|
128 |
-
if predictions[0] == "Yes":
|
129 |
-
return "Churn"
|
130 |
-
else:
|
131 |
-
return "Not Churn"
|
132 |
-
|
133 |
-
# Setting Gradio App Interface
|
134 |
-
with gr.Blocks(css=".gradio-container {background-color: grey}") as demo:
|
135 |
-
gr.Markdown("# Teleco Customer Churn Prediction #\n*This App allows the user to predict whether a customer will churn or not by entering values in the given fields. Any field left blank takes the default value.*")
|
136 |
-
|
137 |
-
# Receiving ALL Input Data here
|
138 |
-
gr.Markdown("**Demographic Data**")
|
139 |
-
with gr.Row():
|
140 |
-
gender = gr.Dropdown(label="Gender", choices=["Male", "Female"])
|
141 |
-
SeniorCitizen = gr.Radio(label="Senior Citizen", choices=[1, 0])
|
142 |
-
Partner = gr.Radio(label="Partner", choices=["Yes", "No"])
|
143 |
-
Dependents = gr.Radio(label="Dependents", choices=["Yes", "No"])
|
144 |
-
|
145 |
-
gr.Markdown("**Service Length and Charges (USD)**")
|
146 |
-
with gr.Row():
|
147 |
-
Contract = gr.Dropdown(label="Contract", choices=["Month-to-month", "One year", "Two year"])
|
148 |
-
tenure = gr.Slider(label="Tenure (months)", minimum=1, step=1, interactive=True)
|
149 |
-
MonthlyCharges = gr.Slider(label="Monthly Charges", step=0.05)
|
150 |
-
TotalCharges = gr.Slider(label="Total Charges", step=0.05)
|
151 |
-
|
152 |
-
# Phone Service Usage part
|
153 |
-
gr.Markdown("**Phone Service Usage**")
|
154 |
-
with gr.Row():
|
155 |
-
PhoneService = gr.Radio(label="Phone Service", choices=["Yes", "No"])
|
156 |
-
MultipleLines = gr.Dropdown(label="Multiple Lines", choices=[
|
157 |
-
"Yes", "No", "No phone service"])
|
158 |
-
|
159 |
-
# Internet Service Usage part
|
160 |
-
gr.Markdown("**Internet Service Usage**")
|
161 |
-
with gr.Row():
|
162 |
-
InternetService = gr.Dropdown(label="Internet Service", choices=["DSL", "Fiber optic", "No"])
|
163 |
-
OnlineSecurity = gr.Dropdown(label="Online Security", choices=["Yes", "No", "No internet service"])
|
164 |
-
OnlineBackup = gr.Dropdown(label="Online Backup", choices=["Yes", "No", "No internet service"])
|
165 |
-
DeviceProtection = gr.Dropdown(label="Device Protection", choices=["Yes", "No", "No internet service"])
|
166 |
-
TechSupport = gr.Dropdown(label="Tech Support", choices=["Yes", "No", "No internet service"])
|
167 |
-
StreamingTV = gr.Dropdown(label="TV Streaming", choices=["Yes", "No", "No internet service"])
|
168 |
-
StreamingMovies = gr.Dropdown(label="Movie Streaming", choices=["Yes", "No", "No internet service"])
|
169 |
-
|
170 |
-
# Billing and Payment part
|
171 |
-
gr.Markdown("**Billing and Payment**")
|
172 |
-
with gr.Row():
|
173 |
-
PaperlessBilling = gr.Radio(
|
174 |
-
label="Paperless Billing", choices=["Yes", "No"])
|
175 |
-
PaymentMethod = gr.Dropdown(label="Payment Method", choices=["Electronic check", "Mailed check", "Bank transfer (automatic)", "Credit card (automatic)"])
|
176 |
-
|
177 |
-
# Output Prediction
|
178 |
-
output = gr.Text(label="Outcome")
|
179 |
-
submit_button = gr.Button("Predict")
|
180 |
-
|
181 |
-
submit_button.click(fn= predict,
|
182 |
-
outputs= output,
|
183 |
-
inputs=[gender, SeniorCitizen, Partner, Dependents, Contract, tenure, MonthlyCharges, TotalCharges, PaymentMethod, PhoneService, MultipleLines, InternetService, OnlineSecurity, OnlineBackup, DeviceProtection, TechSupport, StreamingTV, StreamingMovies, PaperlessBilling],
|
184 |
-
|
185 |
-
),
|
186 |
-
|
187 |
-
# Add the reset and flag buttons
|
188 |
-
|
189 |
-
def clear():
|
190 |
-
output.value = ""
|
191 |
-
return None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None
|
192 |
-
|
193 |
-
clear_btn = gr.Button("Reset", variant="primary")
|
194 |
-
clear_btn.click(fn=clear, inputs=None, outputs=output)
|
195 |
-
|
196 |
-
|
197 |
demo.launch(inbrowser = True)
|
|
|
38 |
'MonthlyCharges': [MonthlyCharges] if MonthlyCharges else [0.0], # Replace None with default value
|
39 |
'TotalCharges': [TotalCharges] if TotalCharges else [0.0] # Replace None with default value
|
40 |
})
|
41 |
+
|
42 |
+
|
43 |
# Make predictions using the loaded logistic regression model
|
44 |
#predict probabilities
|
45 |
predictions = full_pipeline.predict_proba(input_data)
|
|
|
119 |
clear_btn.click(fn=clear, inputs=None, outputs=output)
|
120 |
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
demo.launch(inbrowser = True)
|