File size: 4,860 Bytes
ce08d4c
 
 
 
 
 
f8c1703
ce08d4c
f8c1703
 
 
ce08d4c
 
f8c1703
ce08d4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8c1703
 
ce08d4c
f8c1703
8e0309f
f8c1703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pandas as pd
from transformers import pipeline
import streamlit as st
import datetime
from huggingface_hub import hf_hub_download
import joblib
import json

REPO_ID = "rajistics/churn-model1"
FILENAME = "churn.pkl"
JSON_FILE = "config.json"

model = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
)

if 'clicked' not in st.session_state:
    st.session_state.clicked = False

def click_button():
    st.session_state.clicked = True


st.title("CUSTOMER CHURN PREDICTION APP")

with st.form(key="customer-information"):
    st.markdown("This app predicts whether a customer will leave your company or not. Enter the details of the customer below to see the result")
    gender = st.radio('Select your gender', ('male', 'female'))
    SeniorCitizen = st.radio("Are you a Seniorcitizen; No=0 and Yes=1", ('0', '1'))
    Partner = st.radio('Do you have Partner', ('Yes', 'No'))
    Dependents = st.selectbox('Do you have any Dependents?', ('No', 'Yes'))
    tenure = st.number_input('Lenght of tenure (no. of months with Telco)', min_value=0, max_value=90, value=1, step=1)
    PhoneService = st.radio('Do you have PhoneService? ', ('No', 'Yes'))
    MultipleLines = st.radio('Do you have MultipleLines', ('No', 'Yes'))
    InternetService = st.radio('Do you have InternetService', ('DSL', 'Fiber optic', 'No'))
    OnlineSecurity = st.radio('Do you have OnlineSecurity?', ('No', 'Yes'))
    OnlineBackup = st.radio('Do you have OnlineBackup?', ('No', 'Yes'))
    DeviceProtection = st.radio('Do you have DeviceProtection?', ('No', 'Yes'))
    TechSupport = st.radio('Do you have TechSupport?', ('No', 'Yes'))
    StreamingTV = st.radio('Do you have StreamingTV?', ('No', 'Yes'))
    StreamingMovies = st.radio('Do you have StreamingMovies?', ('No', 'Yes'))
    Contract = st.selectbox('which Contract do you use?', ('Month-to-month', 'One year', 'Two year'))
    PaperlessBilling = st.radio('Do you prefer PaperlessBilling?', ('Yes', 'No'))
    PaymentMethod = st.selectbox('Which PaymentMethod do you prefer?', ('Electronic check', 'Mailed check', 'Bank transfer (automatic)',
                                        'Credit card (automatic)'))
    MonthlyCharges = st.number_input("Enter monthly charges (the range should between 0-120)")
    TotalCharges = st.number_input("Enter total charges (the range should between 0-10.000)")           
    st.form_submit_button('Predict', on_click=click_button)

    if st.session_state.clicked:
        with open(JSON_FILE) as f:
            config = json.load(f)
    # The message and nested widget will remain on the page
        list_input =[gender,SeniorCitizen,Partner,Dependents, tenure, PhoneService,MultipleLines,
                       InternetService,OnlineSecurity,OnlineBackup,DeviceProtection,TechSupport,StreamingTV,StreamingMovies,
                       Contract,PaperlessBilling,PaymentMethod,MonthlyCharges,TotalCharges]
        df = pd.DataFrame({
            'gender': [gender],
            'SeniorCitizen': [SeniorCitizen],
            'Partner': [Partner],
            'Dependents': [Dependents],
            'tenure': [tenure],
            'PhoneService': [PhoneService],
            'MultipleLines': [MultipleLines],
            'InternetService': [InternetService],
            'OnlineSecurity': [OnlineSecurity],
            'OnlineBackup': [OnlineBackup],
            'DeviceProtection': [DeviceProtection],
            'TechSupport': [TechSupport],
            'StreamingTV': [StreamingTV],
            'StreamingMovies': [StreamingMovies],
            'Contract': [Contract],
            'PaperlessBilling': [PaperlessBilling],
            'PaymentMethod': [PaymentMethod],
            'MonthlyCharges': [MonthlyCharges],
            'TotalCharges': [TotalCharges]
            })
        st.dataframe(
            df,
            column_config={
                'gender': "gender",
                'SeniorCitizen': "SeniorCitizen",
                'Partner': "Partner",
                'Dependents': "Dependents",
                'tenure': "tenure",
                'PhoneService': "PhoneService",
                'MultipleLines': "MultipleLines",
                'InternetService': "InternetService",
                'OnlineSecurity': "OnlineSecurity",
                'OnlineBackup': "OnlineBackup",
                'DeviceProtection': "DeviceProtection",
                'TechSupport': "TechSupport",
                'StreamingTV': "StreamingTV",
                'StreamingMovies': "StreamingMovies",
                'Contract': "Contract",
                'PaperlessBilling': "PaperlessBilling",
                'PaymentMethod': "PaymentMethod",
                'MonthlyCharges': "MonthlyCharges",
                'TotalCharges': "TotalCharges"
            },
            hide_index=True,
        )

        model.predict(df(config["sklearn"][list_input]))