ahmad092's picture
Upload 3 files
bde18e9 verified
Raw History Blame Contribute Delete
1.02 kB
import gradio as gr
import pandas as pd
import joblib
import numpy as np
# 1. Load the model
model = joblib.load('model.pkl')
# 2. Define the prediction function
def predict_churn(age, tenure, balance, salary):
# Prepare the input in the same format as your training data X
input_data = np.array([[age, tenure, balance, salary]])
# Get prediction
prediction = model.predict(input_data)
# Return human-readable result
return "Likely to EXIT" if prediction[0] == 1 else "Likely to STAY"
# 3. Create the Gradio Interface
demo = gr.Interface(
fn=predict_churn,
inputs=[
gr.Number(label="Age (Years)"),
gr.Slider(0, 10, step=1, label="Tenure (Years)"),
gr.Number(label="Account Balance"),
gr.Number(label="Estimated Annual Salary")
],
outputs="text",
title="Customer Churn Predictor",
description="This model uses a Decision Tree (Optimized) to predict customer retention."
)
# 4. Launch
if __name__ == "__main__":
demo.launch()