viwiyada commited on
Commit
7575c1a
1 Parent(s): 467a6cb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ import streamlit as st
4
+
5
+ EDU_DICT = {'Preschool': 1,
6
+ '1st-4th': 2,
7
+ '5th-6th': 3,
8
+ '7th-8th': 4,
9
+ '9th': 5,
10
+ '10th': 6,
11
+ '11th': 7,
12
+ '12th': 8,
13
+ 'HS-grad': 9,
14
+ 'Some-college': 10,
15
+ 'Assoc-voc': 11,
16
+ 'Assoc-acdm': 12,
17
+ 'Bachelors': 13,
18
+ 'Masters': 14,
19
+ 'Prof-school': 15,
20
+ 'Doctorate': 16
21
+ }
22
+
23
+ model = joblib.load('model.joblib')
24
+ unique_values = joblib.load('unique_values.joblib')
25
+
26
+ unique_class = unique_values["workclass"]
27
+ unique_education = unique_values["education"]
28
+ unique_marital_status = unique_values["marital.status"]
29
+ unique_relationship = unique_values["relationship"]
30
+ unique_occupation = unique_values["occupation"]
31
+ unique_sex = unique_values["sex"]
32
+ unique_race = unique_values["race"]
33
+ unique_country = unique_values["native.country"]
34
+
35
+ def main():
36
+ st.title("Adult Income")
37
+
38
+ with st.form("questionaire"):
39
+ age = st.slider("Age", min_value=10, max_value=100)
40
+ workclass = st.selectbox("Workclass", options = unique_class)
41
+ education = st.selectbox("Education", options = unique_education)
42
+ Marital_Status = st.selectbox("Marital Status", options = unique_marital_status)
43
+ occupation = st.selectbox("Occupation", options = unique_occupation)
44
+ relationship = st.selectbox("Relationship", options = unique_relationship)
45
+ race = st.selectbox("Race", options = unique_race)
46
+ sex = st.selectbox("Sex", options = unique_sex)
47
+ hours_per_week = st.slider("Hours per week", min_value=1, max_value=100)
48
+ native_country = st.selectbox("Native country", options = unique_country)
49
+
50
+ # clicked==True only when the button is clicked
51
+ clicked = st.form_submit_button("Predict income")
52
+ if clicked:
53
+ result=model.predict(pd.DataFrame({"age": [age],
54
+ "workclass": [workclass],
55
+ "education": [EDU_DICT[education]],
56
+ "marital.status": [Marital_Status],
57
+ "occupation": [occupation],
58
+ "relationship": [relationship],
59
+ "race": [race],
60
+ "sex": [sex],
61
+ "hours.per.week": [hours_per_week],
62
+ "native.country": [native_country]}))
63
+ # Show prediction
64
+ result = '>50K' if result[0] == 1 else '<=50K'
65
+ st.success("Your predicted income is "+result) #แสดงผล
66
+
67
+ # Run main()
68
+ if __name__ == "__main__":
69
+ main()