Spaces:
Runtime error
Runtime error
Michaeldavidstein
commited on
Commit
•
2bc3aa9
1
Parent(s):
3dd1e62
Upload 3 files
Browse files- app.py +77 -0
- model.joblib +3 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import joblib
|
4 |
+
|
5 |
+
|
6 |
+
age_input = gr.Number(label="Age")
|
7 |
+
duration_input = gr.Number(label='Duration(Sec)')
|
8 |
+
cc_contact_freq_input = gr.Number(label='CC Contact Freq')
|
9 |
+
days_since_pc_input = gr.Number(label='Days Since PC')
|
10 |
+
pc_contact_freq_input = gr.Number(label='Pc Contact Freq')
|
11 |
+
job_input = gr.Dropdown(['admin.', 'blue-collar', 'technician', 'services', 'management',
|
12 |
+
'retired', 'entrepreneur', 'self-employed', 'housemaid', 'unemployed',
|
13 |
+
'student', 'unknown'],label="Job")
|
14 |
+
marital_input = gr.Dropdown(['married', 'single', 'divorced', 'unknown'],label='Marital Status')
|
15 |
+
education_input = gr.Dropdown(['experience', 'university degree', 'high school', 'professional.course',
|
16 |
+
'Others', 'illiterate'],label='Education')
|
17 |
+
defaulter_input = gr.Dropdown(['no', 'unknown', 'yes'],label='Defaulter')
|
18 |
+
home_loan_input = gr.Dropdown(['yes', 'no', 'unknown'],label='Home Loan')
|
19 |
+
personal_loan_input = gr.Dropdown(['yes', 'no', 'unknown'],label='Personal Loan')
|
20 |
+
communication_type_input = gr.Dropdown(['cellular', 'telephone'],label='Communication Type')
|
21 |
+
last_contacted_input = gr.Dropdown(['may', 'jul', 'aug', 'jun', 'nov', 'apr', 'oct', 'mar', 'sep', 'dec'],label='Last Contacted')
|
22 |
+
day_of_week_input = gr.Dropdown(['thu', 'mon', 'wed', 'tue', 'fri'],label='Day of Week')
|
23 |
+
pc_outcome_input = gr.Dropdown(['nonexistent', 'failure', 'success'], label='PC Outcome')
|
24 |
+
|
25 |
+
o = gr.Textbox()
|
26 |
+
|
27 |
+
# load the model
|
28 |
+
model = joblib.load('model.joblib')
|
29 |
+
i2l = ['Not subscribed', 'Subscribed']
|
30 |
+
def fn(age, duration, cc_contact_freq, days_since_pc, pc_contact_freq, job, marital_status, education,
|
31 |
+
defaulter, home_loan, personal_loan, communication_type, last_contacted,
|
32 |
+
day_of_week, pc_outcome):
|
33 |
+
sample = {
|
34 |
+
'Age': age,
|
35 |
+
'Duration(Sec)': duration,
|
36 |
+
'CC Contact Freq': cc_contact_freq,
|
37 |
+
'Days Since PC': days_since_pc,
|
38 |
+
'PC Contact Freq': pc_contact_freq,
|
39 |
+
'Job': job,
|
40 |
+
'Marital Status': marital_status,
|
41 |
+
'Education': education,
|
42 |
+
'Defaulter': defaulter,
|
43 |
+
'Home Loan': home_loan,
|
44 |
+
'Personal Loan': personal_loan,
|
45 |
+
'Communication Type': communication_type,
|
46 |
+
'Last Contacted': last_contacted,
|
47 |
+
'Day of Week': day_of_week,
|
48 |
+
'PC Outcome': pc_outcome,
|
49 |
+
}
|
50 |
+
print(f'sample: {sample}')
|
51 |
+
data_point = pd.DataFrame([sample])
|
52 |
+
print(f'{data_point}')
|
53 |
+
result = model.predict(data_point)
|
54 |
+
result = result[0]
|
55 |
+
print(result)
|
56 |
+
return i2l[result]
|
57 |
+
|
58 |
+
|
59 |
+
interface = gr.Interface(fn,
|
60 |
+
inputs = [age_input,
|
61 |
+
duration_input,
|
62 |
+
cc_contact_freq_input,
|
63 |
+
days_since_pc_input,
|
64 |
+
pc_contact_freq_input,
|
65 |
+
job_input,
|
66 |
+
marital_input,
|
67 |
+
education_input,
|
68 |
+
defaulter_input,
|
69 |
+
home_loan_input,
|
70 |
+
personal_loan_input,
|
71 |
+
communication_type_input,
|
72 |
+
last_contacted_input,
|
73 |
+
day_of_week_input,
|
74 |
+
pc_outcome_input],
|
75 |
+
outputs = o)
|
76 |
+
|
77 |
+
interface.launch(share=True)
|
model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c3c382c7233f0463a9c2698c7190fa6a89f2704433ae79735d9a6a1acfb5529
|
3 |
+
size 8439
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
joblib
|
2 |
+
scikit-learn==1.2.2
|