File size: 2,583 Bytes
92b63f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st
import pandas as pd
from make_prediction import get_prediction
import pickle


def project_ui():
    st.image("assets/customer_churn_image.jpg",width=600)
    st.title("Customer Churn Prediction")
    
    
    age = st.number_input("**Age**", min_value=18, max_value=100, step=1)
    gender = st.selectbox("**Gender**", options=["Male", "Female"])
    gender_encoded = 1 if gender == "Male" else 0

    tenure = st.number_input("**Tenure (months)**", min_value=0, step=1)
    usage_frequency = st.number_input("**Usage Frequency**", min_value=0, step=1)
    support_calls = st.number_input("**Support Calls**", min_value=0, step=1)
    payment_delay = st.number_input("**Payment Delay**", min_value=0, step=1)

    subscription_type = st.selectbox("**Subscription Type**", options=["Standard", "Basic", "Premium"])
    subscription_type_encoded = {"Standard": 2, "Basic": 0, "Premium": 1}[subscription_type]

    contract_length = st.selectbox("**Contract Length**", options=["Annual", "Monthly", "Quarterly"])
    contract_length_encoded = {"Annual": 0, "Monthly": 1, "Quarterly": 2}[contract_length]

    total_spend = st.number_input("**Total Spend**", min_value=0.0, step=1.0)
    last_interaction = st.number_input("Last Interaction (days ago)", min_value=0, step=1)

    # Create DataFrame of input data for the prediction
    input_data = pd.DataFrame({
        "Age": [age],
        "Gender": [gender_encoded],
        "Tenure": [tenure],
        "Usage Frequency": [usage_frequency],
        "Support Calls": [support_calls],
        "Payment Delay": [payment_delay],
        "Subscription Type": [subscription_type_encoded],
        "Contract Length": [contract_length_encoded],
        "Total Spend": [total_spend],
        "Last Interaction": [last_interaction],
    })

    
    if st.button("Predict Churn"):
        prediction = get_prediction(input_data)
        
        
        if prediction is not None:
            churn_value = int(prediction['predictions'][0]) 
            churn_prediction = "Will Churn" if churn_value == 1 else "Won't Churn"
            st.success(f"Prediction: {churn_prediction}")
        else:
            st.write("Prediction request failed. We are using local model ")
            with open("backend/artifacts/XGBoost.pkl","rb") as file:
                model= pickle.load(file)
            result = model.predict(input_data)
            churn_prediction = "Will Churn" if result ==1 else "Won't Churn"
            st.success(f"Prediction : {churn_prediction}")


if __name__ == "__main__":
    project_ui()