File size: 7,149 Bytes
b73e992
e2f291d
f1043a8
d576c9e
 
92f9049
 
d576c9e
 
92f9049
 
 
 
 
 
 
 
 
 
98eef61
92f9049
 
 
 
 
 
 
 
 
 
d576c9e
92f9049
98eef61
92f9049
 
 
 
 
 
 
 
d576c9e
 
 
98eef61
d576c9e
 
 
 
 
 
 
 
92f9049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98eef61
92f9049
 
 
 
 
 
 
 
 
 
 
a701cd8
92f9049
 
586b22c
92f9049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d576c9e
92f9049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d576c9e
92f9049
 
d576c9e
92f9049
 
 
 
 
 
 
 
 
 
 
d576c9e
92f9049
 
d576c9e
92f9049
 
 
 
 
 
 
 
 
 
 
d576c9e
92f9049
 
d576c9e
92f9049
 
 
 
 
 
 
 
 
 
 
a06a8d7
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import gradio as gr
import sklearn
import pickle
import pandas as pd

def example1():
    
    model = pickle.load(open('model.pkl', 'rb'))
    input_model = [[65,1.8,2,0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1]]
    pred=model.predict(input_model)
    churn = "False"
    if pred[0] == 1:
        churn = "He Will Churn"
    elif pred[0] == 0:
        churn = "He Will Not Churn"
    return churn

def example2():
    
    model = pickle.load(open('model.pkl', 'rb'))
    input_model = [[41,2,2,0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0]]
    pred=model.predict(input_model)
    churn = "False"
    if pred[0] == 1:
        churn = "He Will Churn"
    elif pred[0] == 0:
        churn = "He Will Not Churn"
    return churn


def example3():
    
    model = pickle.load(open('model.pkl', 'rb'))
    input_model = [[10,1.1,2,0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0]]
    pred=model.predict(input_model)
    churn = "False"
    if pred[0] == 1:
        churn = "He Will Churn"
    elif pred[0] == 0:
        churn = "He Will Not Churn"
    return churn

def example4():
    
    model = pickle.load(open('model.pkl', 'rb'))
    input_model = [[7,0.8,5,0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,0, 0, 1]]
    pred=model.predict(input_model)
    churn = "False"
    if pred[0] == 0:
        churn = "She Will Churn"
    elif pred[0] == 1:
        churn = "She Will Not Churn"
    return churn
    

def greet(Total_Transaction, Total_Ct_Chng_Q4_Q1, Total_Relationship_Count, Education=None, Annual_Income=None, Marital_Status=None, Card_Type=None):
    educ, edud, edug, eduh, edup, eduu, ai0, ai40, ai60, ai80, ai120, msd, msm, mss, ctb, ctg, cts = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    
    if Annual_Income == "0k-40k":
        ai0 = 1
    elif Annual_Income == "40k-60k":
        ai40 = 1
    elif Annual_Income == "60k-80k":
        ai60 = 1
    elif Annual_Income == "80k-120k":
        ai80 = 1
    elif Annual_Income == "120k+":
        ai120 = 1

    if Marital_Status == "Single":
        mss = 1
    elif Marital_Status == "Married":
        msm = 1
    elif Marital_Status == "Divorced":
        msd = 1

    if Card_Type == "Blue":
        ctb = 1
    elif Card_Type == "Gold":
        ctg = 1
    elif Card_Type == "Silver":
        cts = 1

    if Education == "College":
        educ = 1
    elif Education == "Doctorate":
        edud = 1
    elif Education == "Graduate":
        edug = 1
    elif Education == "High-School":
        eduh = 1
    elif Education == "Post-Graduate":
        edup = 1
    elif Education == "Uneducated":
        eduu = 1
        
    
    input_model = [[Total_Transaction,Total_Ct_Chng_Q4_Q1,Total_Relationship_Count,educ, edud, edug, eduh, edup, eduu, ai120, ai40, ai60, ai80, ai0, msd, msm, mss,ctb, ctg, cts]]
    model = pickle.load(open('model.pkl', 'rb'))
    pred=model.predict(input_model)
    churn = "False"
    if pred[0] == 1:
        churn = "True"
    elif pred[0] == 0:
        churn = "Flase"
    return churn
    
with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column(scale=1,min_width=600):
            gr.Image("logo.png").style(height='7')
            Total_Transaction = gr.Slider(0, 200,label="Total Transaction Count")
            Total_Ct_Chng_Q4_Q1 = gr.Slider(0, 30,label="Transaction Count Q4 vs Q1")
            Total_Relationship_Count = gr.Slider(0, 20,step=1,label="Total Relationship Count")
            
        with gr.Column(scale=2,min_width=600):
            with gr.Row():
                with gr.Column(scale=1,min_width=300):
                    Annual_Income = gr.Dropdown(["0k-40k","40k-60k","60k-80k","80k-120K","120k+"],label="Annual Income")
                with gr.Column(scale=2,min_width=300):
                    Education = gr.Dropdown(["College","Doctorate","Graduate","High-School","Post-Graduate","Uneducated","Unknown"],label="Education")
                    
            with gr.Row():
                with gr.Column(scale=3,min_width=300):
                    Marital_Status = gr.Dropdown(["Single","Married","Divorced","Unknown"],label="Marital Status")
                with gr.Column(scale=4,min_width=300):
                    Card_Type = gr.Dropdown(["Blue","Silver","Gold"],label="Crad Type")
            churn = gr.Textbox(value="", label="Churn")
            btn = gr.Button("PREDICT").style(size = "lg")
            btn.click(fn=greet, inputs=[Total_Transaction,Total_Ct_Chng_Q4_Q1,Total_Relationship_Count,Education,Annual_Income,Marital_Status,Card_Type], outputs=[churn])
            gr.Markdown("""# Few Examples Based on Real-World Simulations""")
            
    with gr.Row():
        with gr.Column(scale=1,min_width=300):
            gr.Image("avatars/1.png")
            churn1 = gr.Textbox(value="", label="Churn")
            btn1 = gr.Button("PREDICT").style()
            exp =1
            btn1.click(fn=example1, inputs=[], outputs=[churn1])
            gr.Markdown("""
            # Corporate Professional!
            Total Transaction Count - 45\n
            Transaction Count Q4 vs Q1 - 1.3\n
            Total Relationship Count - 2\n
            Annual Income - 40k-60k\n
            Education - Graduate\n
            Marital Status - Married\n
            Card Type - Silver\n
            """)
        with gr.Column(scale=2,min_width=300):
            gr.Image("avatars/4.png")
            churn2 = gr.Textbox(value="", label="Churn")
            bt2 = gr.Button("PREDICT").style()
            bt2.click(fn=example4, inputs=[], outputs=[churn2])
            gr.Markdown("""
            # Medical Professional!
            Total Transaction Count - 7\n
            Transaction Count Q4 vs Q1 - 0.8\n
            Total Relationship Count - 5\n
            Annual Income - 80k-120k\n
            Education - Doctorate\n
            Marital Status - Married\n
            Card Type - Gold\n
            """)
        with gr.Column(scale=3,min_width=300):
            gr.Image("avatars/2.png")
            churn3 = gr.Textbox(value="", label="Churn")
            btn3 = gr.Button("PREDICT").style()
            btn3.click(fn=example2, inputs=[], outputs=[churn3])
            gr.Markdown("""
            # Freelance Photographer!
            Total Transaction Count - 41\n
            Transaction Count Q4 vs Q1 - 2\n
            Total Relationship Count - 2\n
            Annual Income - 0k-40k\n
            Education - High-School\n
            Marital Status - Single\n
            Card Type - Blue\n
            """)
        with gr.Column(scale=4,min_width=300):
            gr.Image("avatars/3.png")
            churn4 = gr.Textbox(value="", label="Churn")
            btn4 = gr.Button("PREDICT").style()
            btn4.click(fn=example3, inputs=[], outputs=[churn4])
            gr.Markdown("""
            # Retired Veteran Pensioner!
            Total Transaction Count - 10\n
            Transaction Count Q4 vs Q1 - 1.1\n
            Total Relationship Count - 2\n
            Annual Income - 80k-120k\n
            Education - Post-Graduate\n
            Marital Status - Divorced\n
            Card Type - GOld\n
            """)

demo.launch()