Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,72 @@
|
|
1 |
import joblib
|
2 |
import pandas as pd
|
|
|
3 |
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
'
|
7 |
-
'
|
8 |
-
'
|
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 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
unique_race = unique_values["race"]
|
33 |
-
unique_country = unique_values["native.country"]
|
34 |
|
35 |
def main():
|
36 |
-
st.title("
|
37 |
|
38 |
with st.form("questionaire"):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
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({"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"
|
59 |
-
"race": [race],
|
60 |
-
"sex": [sex],
|
61 |
-
"hours.per.week": [hours_per_week],
|
62 |
-
"native.country": [native_country]}))
|
63 |
# Show prediction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
|
|
|
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()
|