import streamlit as st import pandas as pd import numpy as np import pickle import sklearn @st.cache_resource() def load_rfr(): model = pickle.load(open('rfr.sav', 'rb')) return model def load_xgb(): model = pickle.load(open('xbg.sav', 'rb')) return model def load_lr(): model = pickle.load(open('lr.sav', 'rb')) return model st.title("Burnt Calories Prediction") st.write(""" # Select a machine learning model """ ) #define the duration for the model age = st.number_input('Input your age!', max_value=80, min_value=18, step=1) duration = st.number_input('Input the amount of exercise time in minutes!', max_value=30.0, min_value=1.0, step=1.0) height = st.number_input('Input your height!', max_value=230.0, min_value=120.0, step=1.0) weight = st.number_input('Input your weight!', max_value=140.0, min_value=35.0, step=1.0) heart_rate = st.number_input('Input your heart rate!', max_value=130.0, min_value=60.0, step=20.0) body_temp = st.number_input('Input your body temperature!', max_value=45.0, min_value=35.0, step=1.0) def model_prediction(age, height, weight, duration, heart_rate, body_temp, gender, model_input): with st.spinner('Model is being loaded..'): if model_input == "Random Forest Regressor": model = load_rfr() elif model_input == "Linear Regressor": model = load_lr() else: model = load_xgb() inputs = pd.DataFrame([{'Gender': gender, 'Age': age, 'Height': height, 'Weight': weight, 'Duration': duration, 'Heart_Rate': heart_rate, 'Body_Temp': body_temp}]) predictions = model.predict(inputs) st.write("""# Prediction : """ , predictions) with st.sidebar: st.markdown("

Settings Tab

", unsafe_allow_html=True) st.write("Input Settings:") #define the gender for the model gender_input = st.radio("Gender", ["Male", "Female"], index=None) if gender_input == "Male": gender = 0 else: gender = 1 model_input = st.radio("Model", ["Random Forest Regressor", "Linear Regressor", "XG Boost"], index=None) with st.container(): if st.button("Calculate"): model_prediction(age, height, weight, duration, heart_rate, body_temp, gender, model_input)