slickdata commited on
Commit
a58296a
·
1 Parent(s): 3a4e5c9

Update app.py

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