Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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,
|
| 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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|