|
|
import streamlit as st |
|
|
import joblib |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
xgb_model = joblib.load('xgb_model.joblib') |
|
|
label_encoder_X = joblib.load('label_encoder_X.joblib') |
|
|
label_encoder_y = joblib.load('label_encoder_y.joblib') |
|
|
|
|
|
|
|
|
def main(): |
|
|
st.title("Injury Type Prediction") |
|
|
|
|
|
|
|
|
age = st.number_input("Age", min_value=0, max_value=120, step=1) |
|
|
sex = st.number_input("Sex", min_value=1, max_value=3) |
|
|
present_city = st.text_input("Present City") |
|
|
|
|
|
|
|
|
|
|
|
if present_city not in label_encoder_X.classes_: |
|
|
st.warning("Unrecognized city. Please enter a valid city.") |
|
|
return |
|
|
|
|
|
|
|
|
present_city_encoded = label_encoder_X.transform([present_city])[0] |
|
|
|
|
|
|
|
|
input_data = np.array([[age, sex, present_city_encoded]]) |
|
|
|
|
|
|
|
|
if st.button("Predict"): |
|
|
|
|
|
prediction = xgb_model.predict(input_data) |
|
|
|
|
|
|
|
|
predicted_injury_type = label_encoder_y.inverse_transform(prediction) |
|
|
if(predicted_injury_type[0]==2): |
|
|
st.write("Predicted Injury Type: Fatal") |
|
|
elif(predicted_injury_type[0]==3): |
|
|
st.write("Predicted Injury Type: Minor") |
|
|
elif(predicted_injury_type[0]==1): |
|
|
st.write("Predicted Injury Type: Grievous") |
|
|
elif(predicted_injury_type==4): |
|
|
st.write("Predicted Injury Type: Not Applicable") |
|
|
else: |
|
|
st.write("Predicted Injury Type: Abused") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|