Spaces:
Runtime error
Runtime error
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('Your predicted evaluation is '+result) | |
if __name__ == '__main__': | |
main() # Run main() |