Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869# Import necessary modulesimport numpy as npimport gradio as grimport joblibimport pandas as pdimport os# Load the pre-trained model and preprocessordef 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, preprocessorFinal_model, preprocessor = load_model()# Define the prediction functiondef make_prediction(input_data):# Transform the input data using the preprocessortransformer = preprocessor.transform(input_data)predt = Final_model.predict(transformer)# Return predictionif predt[0] == 1:return "Customer will Churn"return "Customer will not Churn"# Create the input components for gradio (organize them into two columns)input_column1 = [gr.inputs.Dropdown(choices=['DAKAR', 'THIES', 'SAINT-LOUIS', 'LOUGA', 'KAOLACK', 'DIOURBEL', 'TAMBACOUNDA', 'KAFFRINE', 'KOLDA', 'FATICK', 'MATAM', 'ZIGUINCHOR', 'SEDHIOU', 'KEDOUGOU']),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']),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),]input_column2 = [gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Number(),gr.inputs.Dropdown(choices=['NO']),gr.inputs.Number(),gr.inputs.Number(),]# Define the output componentoutput = gr.Textbox(label='Prediction')# Create the interface component with two columnsapp = gr.Interface(fn=make_prediction,inputs=[input_column1, input_column2],title="Customer Churn Predictor",description="Enter the fields below and click the submit button to Make Your Prediction",outputs=output)app.launch(debug=True)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697#import modulesimport numpy as npimport gradio as grimport joblibimport pandas as pdimport osdef 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, preprocessorFinal_model, preprocessor = load_model()#define prediction functiondef 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 datainput_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 predictionif predt[0]==1:return "Customer will Churn"return "Customer will not Churn"#create the input components for gradioREGION = gr.inputs.Dropdown(choices =['DAKAR', 'THIES', 'SAINT-LOUIS', 'LOUGA', 'KAOLACK', 'DIOURBEL', 'TAMBACOUNDA' 'KAFFRINE,KOLDA', 'FATICK', 'MATAM', 'ZIGUINCHOR', 'SEDHIOU', 'KEDOUGOU'])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'])MONTANT = gr.inputs.Number()FREQUENCE_RECH = gr.Number()REVENUE = gr.Number()ARPU_SEGMENT = gr.Number()FREQUENCE = gr.Number()DATA_VOLUME = gr.Number()ON_NET = gr.Number()ORANGE = gr.Number()TIGO = gr.Number()ZONE1 = gr.Number()ZONE2 = gr.Number()MRG = gr.inputs.Dropdown(choices =['NO'])REGULARITY = gr.Number()FREQ_TOP_PACK = gr.Number()output = gr.Textbox(label='Prediction')#create the interface componentapp = gr.Interface(fn =make_prediction,inputs =[REGION,TENURE,MONTANT,FREQUENCE_RECH,REVENUE,ARPU_SEGMENT,FREQUENCE,DATA_VOLUME,ON_NET,ORANGE,TIGO,ZONE1,ZONE2,MRG,REGULARITY,FREQ_TOP_PACK],title ="Customer Churn Predictor",description="Enter the feilds Below and click the submit button to Make Your Prediction",outputs = output)app.launch(debug = True)
app.py+71-43