Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from joblib import load
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
dv , model = load("train_model.joblib")
|
7 |
+
|
8 |
+
|
9 |
+
# creating a predict function to be passed into gradio UI
|
10 |
+
def predict(age, job, marital, education, default, housing,
|
11 |
+
loan, contact, month,day_of_week,campaign,pdays,
|
12 |
+
previous,poutcome,cons_price_idx,cons_conf_idx,emp_var_rate):
|
13 |
+
|
14 |
+
customer = {
|
15 |
+
'age': age,
|
16 |
+
'job': job,
|
17 |
+
'marital': marital,
|
18 |
+
'education': education,
|
19 |
+
'default': default,
|
20 |
+
'housing': housing,
|
21 |
+
'loan': loan,
|
22 |
+
'contact': contact,
|
23 |
+
'month': month,
|
24 |
+
'day_of_week': day_of_week,
|
25 |
+
'campaign': campaign,
|
26 |
+
'pdays': pdays,
|
27 |
+
'previous': previous,
|
28 |
+
'poutcome': poutcome,
|
29 |
+
'cons_price_idx': cons_price_idx,
|
30 |
+
'cons_conf_idx': cons_conf_idx,
|
31 |
+
'emp_var_rate': emp_var_rate
|
32 |
+
}
|
33 |
+
|
34 |
+
print(customer)
|
35 |
+
df_transformed = dv.transform([customer])
|
36 |
+
prediction = model.predict_proba(df_transformed)[:,1]
|
37 |
+
|
38 |
+
# Desposited = prediction >= 0.50
|
39 |
+
|
40 |
+
# result = {
|
41 |
+
# "deposit_probability": float(prediction),
|
42 |
+
# "Deposited": bool(Deposited)
|
43 |
+
# }
|
44 |
+
print(f' The probabilty of depositing in the bank is : {str(prediction)}')
|
45 |
+
|
46 |
+
return str(prediction)
|
47 |
+
|
48 |
+
age = gr.inputs.Slider(minimum=1,default = 35, maximum=100, label = 'age') #default=data['age'].mean()
|
49 |
+
job = gr.inputs.Dropdown(choices=["housemaid", "services","admin.","blue-collar","technician",
|
50 |
+
"retired","management","unemployed","self-employed","unknown",
|
51 |
+
"entrepreneur","student"],label = 'job')
|
52 |
+
marital = gr.inputs.Dropdown(choices=["married", "single","divorced","unknown"],label = 'marital')
|
53 |
+
education = gr.inputs.Dropdown(choices=["basic.4y", "high.school","basic.6y","basic.9y","professional.course",
|
54 |
+
"unknown","university.degree","illiterate"],label = 'education')
|
55 |
+
default = gr.inputs.Dropdown(choices=["yes", "no","unknown"],label = 'default')
|
56 |
+
housing = gr.inputs.Dropdown(choices=["yes", "no","unknown"],label = 'housing')
|
57 |
+
loan = gr.inputs.Dropdown(choices=["yes", "no","unknown"],label = 'loan')
|
58 |
+
contact = gr.inputs.Dropdown(choices=["telephone", "cellular"],label = 'contact')
|
59 |
+
month = gr.inputs.Dropdown(choices=['may', 'jun', 'jul', 'aug', 'oct', 'nov', 'dec',
|
60 |
+
'mar', 'apr','sep'],label = 'month')
|
61 |
+
day_of_week = gr.inputs.Dropdown(choices=['mon', 'tue', 'wed', 'thu', 'fri'],label = 'day_of_week')
|
62 |
+
campaign = gr.inputs.Slider(minimum=1,default = 2, maximum=56, label = 'campaign')
|
63 |
+
pdays = gr.inputs.Slider(minimum=0,default = 0, maximum=27, label = 'pdays')
|
64 |
+
previous = gr.inputs.Slider(minimum=0,default = 0, maximum=7, label = 'previous')
|
65 |
+
poutcome = gr.inputs.Dropdown(choices=["nonexistent", "failure","success"],label = 'poutcome')
|
66 |
+
cons_price_idx = gr.inputs.Slider(minimum=92,default = 94, maximum=95, label = 'cons_price_idx')
|
67 |
+
cons_conf_idx = gr.inputs.Slider(minimum=-51,default = -42, maximum=-27, label = 'cons_conf_idx')
|
68 |
+
emp_var_rate = gr.inputs.Slider(minimum=4964,default = 5191, maximum=5228, label = 'emp_var_rate')
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
iface = gr.Interface(predict,[age, job, marital, education, default, housing,
|
75 |
+
loan, contact, month,day_of_week,campaign,pdays,
|
76 |
+
previous,poutcome,cons_price_idx,cons_conf_idx,emp_var_rate],
|
77 |
+
outputs = "number",
|
78 |
+
interpretation="default"
|
79 |
+
)
|
80 |
+
iface.launch(share=True)
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
|