Spaces:
Sleeping
Sleeping
File size: 3,526 Bytes
f8130a1 47d2fbb f8130a1 47d2fbb f8130a1 e3fa61e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import gradio as gr
import pickle
import pandas as pd
import numpy as np
import joblib
from gradio.components import *
#define prediction function
def make_prediction(gender, Partner, Dependents, tenure, MultipleLines,
InternetService, OnlineSecurity, OnlineBackup, DeviceProtection,
TechSupport, Contract, PaperlessBilling, PaymentMethod,
MonthlyCharges, TotalCharges):
#make a dataframe from input data
input_data = pd.DataFrame({'gender':[gender], 'Partner':[Partner], 'Dependents':[Dependents], 'tenure':[tenure], 'MultipleLines':[MultipleLines],
'InternetService':[InternetService], 'OnlineSecurity':[OnlineSecurity], 'OnlineBackup':[OnlineBackup], 'DeviceProtection':[DeviceProtection],
'TechSupport':[TechSupport], 'Contract':[Contract], 'PaperlessBilling':[PaperlessBilling], 'PaymentMethod':[PaymentMethod],
'MonthlyCharges':[MonthlyCharges], 'TotalCharges':[TotalCharges]})
#load already saved pipeline and make predictions
with open("best_model.joblib", "rb") as f:
model = joblib.load(f)
predt = model.predict(input_data)
#return prediction
if predt == 'Yes':
return 'Customer Will Churn'
return 'Customer Will Not Churn'
#create the input components for gradio
gender_input = gr.Dropdown(choices =['Female', 'Male'])
Partner_input = gr.Dropdown(choices =['Yes', 'No'])
Dependents_input = gr.Dropdown(choices =['Yes', 'No'])
tenure_input = gr.Number(label='Lenght of tenure (no. of months with Telco)')
MultipleLines_input = gr.Dropdown(choices =['No phone service', 'No', 'Yes'])
InternetService_input = gr.Dropdown(choices =['DSL', 'Fiber optic', 'No'])
OnlineSecurity_input = gr.Dropdown(choices =['No', 'Yes', 'No internet service'])
OnlineBackup_input = gr.Dropdown(choices =['Yes', 'No', 'No internet service'])
DeviceProtection_input = gr.Dropdown(choices =['No', 'Yes', 'No internet service'])
TechSupport_input = gr.Dropdown(choices =['No', 'Yes', 'No internet service'])
Contract_input = gr.Dropdown(choices =['Month-to-month', 'One year', 'Two year'])
PaperlessBilling_input = gr.Dropdown(choices =['Yes', 'No'])
PaymentMethod_input = gr.Dropdown(choices =['Electronic check', 'Mailed check', 'Bank transfer (automatic)','Credit card (automatic)'])
MonthlyCharges_input = gr.Number(label="Enter monthly charges")
TotalCharges_input = gr.Number(label="Enter total charges")
output = gr.Textbox(label='Prediction')
app = gr.Interface(fn =make_prediction, inputs =[gender_input,
Partner_input,
Dependents_input,
tenure_input,
MultipleLines_input,
InternetService_input,
OnlineSecurity_input,
OnlineBackup_input,
DeviceProtection_input,
TechSupport_input,
Contract_input,
PaperlessBilling_input,
PaymentMethod_input,
MonthlyCharges_input,
TotalCharges_input], outputs = output)
app.launch(debug = True) |