slickdata commited on
Commit
60d136c
·
1 Parent(s): 580fef6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -32
app.py CHANGED
@@ -5,7 +5,6 @@ import joblib
5
  import pandas as pd
6
  import os
7
 
8
-
9
  def load_model():
10
  cwd = os.getcwd()
11
 
@@ -13,19 +12,16 @@ def load_model():
13
 
14
  Final_model_file_path = os.path.join(destination, "Final_model.joblib")
15
  preprocessor_file_path = os.path.join(destination, "preprocessor.joblib")
16
-
17
 
18
  Final_model = joblib.load(Final_model_file_path)
19
  preprocessor = joblib.load(preprocessor_file_path)
20
-
21
 
22
  return Final_model, preprocessor
23
 
24
  Final_model, preprocessor = load_model()
25
 
26
-
27
  #define prediction function
28
- 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):
29
  #make a dataframe from input data
30
  input_data = pd.DataFrame({'REGION':[REGION],
31
  'TENURE':[TENURE],
@@ -43,41 +39,50 @@ def make_prediction(REGION, TENURE, MONTANT, FREQUENCE_RECH, REVENUE, ARPU_SEGME
43
  'MRG':[MRG],
44
  'REGULARITY':[REGULARITY],
45
  'FREQ_TOP_PACK':[FREQ_TOP_PACK]})
46
-
47
  transformer = preprocessor.transform(input_data)
48
-
49
- predt = Final_model.predict(transformer)
50
  #return prediction
51
  if predt[0]==1:
52
  return "Customer will Churn"
53
  return "Customer will not Churn"
54
-
55
 
56
- #create the input components for gradio
57
- input_col1 = [ gr.inputs.Dropdown(choices =['DAKAR', 'THIES', 'SAINT-LOUIS', 'LOUGA', 'KAOLACK', 'DIOURBEL', 'TAMBACOUNDA' 'KAFFRINE,KOLDA', 'FATICK', 'MATAM', 'ZIGUINCHOR', 'SEDHIOU', 'KEDOUGOU']),
58
- gr.inputs.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']),
59
- gr.inputs.Number(),
60
- gr.Number(),
61
- gr.Number(),
62
- gr.Number(),
63
- gr.Number(),
64
- gr.Number()]
 
 
 
 
 
 
65
 
66
- input_col2 = [ gr.Number(),
67
- gr.Number(),
68
- gr.Number(),
69
- gr.Number(),
70
- gr.Number(),
71
- gr.inputs.Dropdown(choices =['NO']),
72
- gr.Number(),
73
- gr.Number()]
 
 
 
 
74
 
75
  output = gr.Textbox(label='Prediction')
76
- #create the interface component
77
 
78
- app = gr.Interface(fn =make_prediction,inputs=[input_col1, input_col2],
79
- title ="Customer Churn Predictor",
80
- description="Enter the fields below and click the submit button to Make Your Prediction",
81
- outputs = output)
 
82
 
83
- app.launch(debug = True)
 
5
  import pandas as pd
6
  import os
7
 
 
8
  def load_model():
9
  cwd = os.getcwd()
10
 
 
12
 
13
  Final_model_file_path = os.path.join(destination, "Final_model.joblib")
14
  preprocessor_file_path = os.path.join(destination, "preprocessor.joblib")
 
15
 
16
  Final_model = joblib.load(Final_model_file_path)
17
  preprocessor = joblib.load(preprocessor_file_path)
 
18
 
19
  return Final_model, preprocessor
20
 
21
  Final_model, preprocessor = load_model()
22
 
 
23
  #define prediction function
24
+ 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):
25
  #make a dataframe from input data
26
  input_data = pd.DataFrame({'REGION':[REGION],
27
  'TENURE':[TENURE],
 
39
  'MRG':[MRG],
40
  'REGULARITY':[REGULARITY],
41
  'FREQ_TOP_PACK':[FREQ_TOP_PACK]})
42
+
43
  transformer = preprocessor.transform(input_data)
44
+
45
+ predt = Final_model.predict(transformer)
46
  #return prediction
47
  if predt[0]==1:
48
  return "Customer will Churn"
49
  return "Customer will not Churn"
 
50
 
51
+ # Create the input components for gradio
52
+ input_col1 = gr.Column(
53
+ [
54
+ gr.Dropdown("REGION", choices=['DAKAR', 'THIES', 'SAINT-LOUIS', 'LOUGA', 'KAOLACK', 'DIOURBEL', 'TAMBACOUNDA', 'KAFFRINE', 'KOLDA']),
55
+ gr.Dropdown("TENURE", 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']),
56
+ gr.Number("MONTANT"),
57
+ gr.Number("FREQUENCE_RECH"),
58
+ gr.Number("REVENUE"),
59
+ gr.Number("ARPU_SEGMENT"),
60
+ gr.Number("FREQUENCE"),
61
+ gr.Number("DATA_VOLUME"),
62
+ gr.Number("ON_NET")
63
+ ],
64
+ label="Column 1"
65
+ )
66
 
67
+ input_col2 = gr.Column(
68
+ [
69
+ gr.Number("ORANGE"),
70
+ gr.Number("TIGO"),
71
+ gr.Number("ZONE1"),
72
+ gr.Number("ZONE2"),
73
+ gr.Dropdown("MRG", choices=['NO']),
74
+ gr.Number("REGULARITY"),
75
+ gr.Number("FREQ_TOP_PACK")
76
+ ],
77
+ label="Column 2"
78
+ )
79
 
80
  output = gr.Textbox(label='Prediction')
 
81
 
82
+ # Create the interface component
83
+ app = gr.Interface(fn=make_prediction, inputs=[input_col1, input_col2],
84
+ title="Customer Churn Predictor",
85
+ description="Enter the fields below and click the submit button to Make Your Prediction",
86
+ outputs=output)
87
 
88
+ app.launch(debug=True)