File size: 2,342 Bytes
56502a5
 
44cb5a1
56502a5
44cb5a1
 
 
 
56502a5
44cb5a1
 
 
 
56502a5
44cb5a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56502a5
44cb5a1
 
 
 
 
 
56502a5
 
44cb5a1
56502a5
 
44cb5a1
 
 
 
 
 
56502a5
 
523312c
56502a5
44cb5a1
 
 
 
 
 
56502a5
44cb5a1
 
 
 
 
 
 
 
 
 
52ad302
56502a5
44cb5a1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import joblib
import pandas as pd
import streamlit as st

buy_dict = {'low': 1,
            'med': 2,
            'high': 3,
            'vhigh': 4}

maint_dict = {'low': 1,
            'med': 2,
            'high': 3,
            'vhigh': 4}

lug_dict = {'small': 1,
            'med': 2,
            'big': 3}

safety_dict = {'low': 1,
               'med': 2,
               'high': 3}

class_dict = {'unacc': 0,
              'acc': 1,
              'good': 2,
              'vgood': 3}

model = joblib.load('model.joblib')
unique_values = joblib.load('unique_values.joblib')
    
unique_buy =  unique_values["buying"]
unique_maint =  unique_values["maintenance"]
unique_door =  unique_values["doors"]
unique_person =  unique_values["persons"]
unique_lugg =  unique_values["luggage_boot"]
unique_safety =  unique_values["safety"]

def main():
    st.title("Car Evaluation")

    with st.form("questionaire"):
        buy = st.selectbox('Buying Price', unique_buy)
        maint = st.selectbox('Maintenance cost', unique_maint)
        door = st.selectbox('Door', unique_door)
        person = st.selectbox('Persons capacity', unique_person)
        lugg = st.selectbox('Size of luggage boot', unique_lugg)
        safety = st.selectbox('Estimated safety of the car', unique_safety)

        # clicked==True only when the button is clicked
        clicked = st.form_submit_button("Predict evaluation")
        if clicked:
            result=model.predict(pd.DataFrame({"buying": [buy_dict[buy]],
                                               "maintenance": [maint_dict[maint]],
                                               "doors": [door],
                                               "persons": [person],
                                               "luggage_boot": [lug_dict[lugg]],
                                               "safety": [safety_dict[safety]]}))
            # Show prediction
            if result[0] == 0:
                result = 'Unacceptable'
            elif result[0] == 1:
                result = 'Acceptable'
            elif result[0] == 2:
                result = 'Good'
            elif result[0] == 3:
                result = 'Very Good'
            else:
                result = 'ERROR'
            st.success('Predicted evaluation: '+result)

if __name__ == '__main__':
    main() # Run main()