File size: 3,246 Bytes
f5193be
f9280be
 
 
 
f46dec4
f9280be
 
0280c86
 
f9280be
 
f5193be
f9280be
f5193be
f9280be
 
 
 
 
 
 
 
 
 
f5193be
60d136c
f5193be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60d136c
f5193be
60d136c
 
f5193be
 
 
8d1c5f7
 
60d136c
0280c86
 
 
 
 
 
 
 
 
342f1ab
0280c86
 
 
 
 
 
 
 
 
 
 
 
f9280be
f46dec4
 
 
 
 
0280c86
f9280be
60d136c
 
 
 
 
f9280be
60d136c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#import modules
import numpy as np
import gradio as gr
import joblib
import pandas as pd
import itertools
import os

from gradio.components import Dropdown, Number, Textbox

def load_model():
    cwd = os.getcwd()

    destination = os.path.join(cwd, "saved cap")

    Final_model_file_path = os.path.join(destination, "Final_model.joblib")
    preprocessor_file_path = os.path.join(destination, "preprocessor.joblib")

    Final_model = joblib.load(Final_model_file_path)
    preprocessor = joblib.load(preprocessor_file_path)

    return Final_model, preprocessor

Final_model, preprocessor = load_model()

#define prediction function
def make_prediction(REGION, TENURE, MONTANT, FREQUENCE_RECH, REVENUE, ARPU_SEGMENT, FREQUENCE, DATA_VOLUME, ON_NET, ORANGE, TIGO, ZONE1, ZONE2, MRG, REGULARITY, FREQ_TOP_PACK):
    #make a dataframe from input data
    input_data = pd.DataFrame({'REGION':[REGION], 
                               'TENURE':[TENURE], 
                               'MONTANT':[MONTANT], 
                               'FREQUENCE_RECH':[FREQUENCE_RECH], 
                               'REVENUE':[REVENUE],
                               'ARPU_SEGMENT':[ARPU_SEGMENT], 
                               'FREQUENCE':[FREQUENCE], 
                               'DATA_VOLUME':[DATA_VOLUME], 
                               'ON_NET':[ON_NET],
                               'ORANGE':[ORANGE], 
                               'TIGO':[TIGO], 
                               'ZONE1':[ZONE1], 
                               'ZONE2':[ZONE2],
                               'MRG':[MRG],
                               'REGULARITY':[REGULARITY], 
                               'FREQ_TOP_PACK':[FREQ_TOP_PACK]})

    transformer = preprocessor.transform(input_data)

    predt = Final_model.predict(transformer)
    #return prediction
    if predt[0]==1:
        return "Customer will Churn" 
    return "Customer will not Churn"

# Create the input components for gradio
input_col1 = [Dropdown(choices=['DAKAR', 'THIES', 'SAINT-LOUIS', 'LOUGA', 'KAOLACK', 'DIOURBEL', 'TAMBACOUNDA', 'KAFFRINE', 'KOLDA']),
              Dropdown(choices=['K > 24 month', 'I 18-21 month', 'H 15-18 month', 'G 12-15 month', 'J 21-24 month', 'F 9-12 month', 'E 6-9 month', 'D 3-6 month']),
              Number(),
              Number(),
              Number(),
              Number(),
              Number(),
              Number(),
              Number()]

input_col2 = [Number(),
              Number(),
              Number(),
              Number(),
              Number(),
              Number(),
              Number(),
              Number(),
              Number(),
              Dropdown(choices=['NO']),
              Number(),
              Number()]

def flatten(list_of_lists):
    return itertools.chain.from_iterable(list_of_lists)

inputs = flatten([input_col1, input_col2])

output = Textbox(label='Prediction')

# Create the interface component
app = gr.Interface(fn=make_prediction, inputs=[input_col1, input_col2],
                   title="Customer Churn Predictor",
                   description="Enter the fields below and click the submit button to Make Your Prediction",
                   outputs=output)

app.launch(debug=True)