File size: 1,021 Bytes
bde18e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()