Spaces:
Runtime error
Runtime error
# Import necessary modules | |
import numpy as np | |
import gradio as gr | |
import joblib | |
import pandas as pd | |
import os | |
# Load the pre-trained model and preprocessor | |
def 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, preprocessor | |
Final_model, preprocessor = load_model() | |
# Define the prediction function | |
def make_prediction(input_data): | |
# Transform the input data using the preprocessor | |
transformer = preprocessor.transform(input_data) | |
predt = Final_model.predict(transformer) | |
# Return prediction | |
if 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 component | |
output = gr.Textbox(label='Prediction') | |
# Create the interface component with two columns | |
app = 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) | |