Tanapol commited on
Commit
44cb5a1
1 Parent(s): 56502a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -49
app.py CHANGED
@@ -1,65 +1,72 @@
1
  import joblib
2
  import pandas as pd
 
3
 
 
 
 
 
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 = #
24
- unique_values = #
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = # user's input
40
- workclass = # user's input
41
- education = # user's input
42
- Marital_Status = # user's input
43
- occupation = # user's input
44
- relationship = # user's input
45
- race = # user's input
46
- sex = # user's input
47
- hours_per_week = # user's input
48
- native_country = # user's input
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
 
65
- # Run main()
 
 
1
  import joblib
2
  import pandas as pd
3
+ import streamlit as st
4
 
5
+ buy_dict = {'low': 1,
6
+ 'med': 2,
7
+ 'high': 3,
8
+ 'vhigh': 4}
9
 
10
+ maint_dict = {'low': 1,
11
+ 'med': 2,
12
+ 'high': 3,
13
+ 'vhigh': 4}
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ lug_dict = {'small': 1,
16
+ 'med': 2,
17
+ 'big': 3}
18
+
19
+ safety_dict = {'low': 1,
20
+ 'med': 2,
21
+ 'high': 3}
22
+
23
+ class_dict = {'unacc': 0,
24
+ 'acc': 1,
25
+ 'good': 2,
26
+ 'vgood': 3}
27
+
28
+ model = joblib.load('model.joblib')
29
+ unique_values = joblib.load('unique_values.joblib')
30
 
31
+ unique_buy = unique_values["buying"]
32
+ unique_maint = unique_values["maintenance"]
33
+ unique_door = unique_values["doors"]
34
+ unique_person = unique_values["persons"]
35
+ unique_lugg = unique_values["luggage_boot"]
36
+ unique_safety = unique_values["safety"]
 
 
37
 
38
  def main():
39
+ st.title("Car Evaluation")
40
 
41
  with st.form("questionaire"):
42
+ buy = st.selectbox('Buying Price', unique_buy)
43
+ maint = st.selectbox('Maintenance cost', unique_maint)
44
+ door = st.selectbox('Door', unique_door)
45
+ person = st.selectbox('Persons capacity', unique_person)
46
+ lugg = st.selectbox('Size of luggage boot', unique_lugg)
47
+ safety = st.selectbox('Estimated safety of the car', unique_safety)
 
 
 
 
48
 
49
  # clicked==True only when the button is clicked
50
  clicked = st.form_submit_button("Predict income")
51
  if clicked:
52
+ result=model.predict(pd.DataFrame({"buying": [buy_dict[buy]],
53
+ "maintenance": [maint_dict[maint]],
54
+ "doors": [door],
55
+ "persons": [person],
56
+ "luggage_boot": [lug_dict[lugg]],
57
+ "safety": [safety_dict[safety]]}))
 
 
 
 
58
  # Show prediction
59
+ if result[0] == 0:
60
+ result = 'Unacceptable'
61
+ elif result[0] == 1:
62
+ result = 'Acceptable'
63
+ elif result[0] == 2:
64
+ result = 'Good'
65
+ elif result[0] == 3:
66
+ result = 'Very Good'
67
+ else:
68
+ result = 'ERROR'
69
+ st.success('Your predicted car evaluation is '+result)
70
 
71
+ if __name__ == '__main__':
72
+ main() # Run main()