slickdata commited on
Commit
8d1c5f7
·
1 Parent(s): cf70616

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -71
app.py CHANGED
@@ -1,97 +1,69 @@
1
- #import modules
2
  import numpy as np
3
  import gradio as gr
4
  import joblib
5
  import pandas as pd
6
  import os
7
 
8
-
9
  def load_model():
10
  cwd = os.getcwd()
11
-
12
  destination = os.path.join(cwd, "saved cap")
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],
32
- 'MONTANT':[MONTANT],
33
- 'FREQUENCE_RECH':[FREQUENCE_RECH],
34
- 'REVENUE':[REVENUE],
35
- 'ARPU_SEGMENT':[ARPU_SEGMENT],
36
- 'FREQUENCE':[FREQUENCE],
37
- 'DATA_VOLUME':[DATA_VOLUME],
38
- 'ON_NET':[ON_NET],
39
- 'ORANGE':[ORANGE],
40
- 'TIGO':[TIGO],
41
- 'ZONE1':[ZONE1],
42
- 'ZONE2':[ZONE2],
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(debug = True)
 
1
+ # Import necessary modules
2
  import numpy as np
3
  import gradio as gr
4
  import joblib
5
  import pandas as pd
6
  import os
7
 
8
+ # Load the pre-trained model and preprocessor
9
  def load_model():
10
  cwd = os.getcwd()
 
11
  destination = os.path.join(cwd, "saved cap")
 
12
  Final_model_file_path = os.path.join(destination, "Final_model.joblib")
13
  preprocessor_file_path = os.path.join(destination, "preprocessor.joblib")
 
14
 
15
  Final_model = joblib.load(Final_model_file_path)
16
  preprocessor = joblib.load(preprocessor_file_path)
 
17
 
18
  return Final_model, preprocessor
19
 
20
  Final_model, preprocessor = load_model()
21
 
22
+ # Define the prediction function
23
+ def make_prediction(input_data):
24
+ # Transform the input data using the preprocessor
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  transformer = preprocessor.transform(input_data)
26
+ predt = Final_model.predict(transformer)
 
 
 
 
 
27
 
28
+ # Return prediction
29
+ if predt[0] == 1:
30
+ return "Customer will Churn"
31
+ return "Customer will not Churn"
32
+
33
+ # Create the input components for gradio (organize them into two columns)
34
+ input_column1 = [
35
+ gr.inputs.Dropdown(choices=['DAKAR', 'THIES', 'SAINT-LOUIS', 'LOUGA', 'KAOLACK', 'DIOURBEL', 'TAMBACOUNDA', 'KAFFRINE', 'KOLDA', 'FATICK', 'MATAM', 'ZIGUINCHOR', 'SEDHIOU', 'KEDOUGOU']),
36
+ 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']),
37
+ gr.inputs.Number(),
38
+ gr.inputs.Number(),
39
+ gr.inputs.Number(),
40
+ gr.inputs.Number(),
41
+ ]
42
 
43
+ input_column2 = [
44
+ gr.inputs.Number(),
45
+ gr.inputs.Number(),
46
+ gr.inputs.Number(),
47
+ gr.inputs.Number(),
48
+ gr.inputs.Number(),
49
+ gr.inputs.Number(),
50
+ gr.inputs.Number(),
51
+ gr.inputs.Number(),
52
+ gr.inputs.Dropdown(choices=['NO']),
53
+ gr.inputs.Number(),
54
+ gr.inputs.Number(),
55
+ ]
 
 
 
 
56
 
57
+ # Define the output component
58
  output = gr.Textbox(label='Prediction')
 
59
 
60
+ # Create the interface component with two columns
61
+ app = gr.Interface(
62
+ fn=make_prediction,
63
+ inputs=[input_column1, input_column2],
64
+ title="Customer Churn Predictor",
65
+ description="Enter the fields below and click the submit button to Make Your Prediction",
66
+ outputs=output
67
+ )
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ app.launch(debug=True)