Spaces:
Runtime error
Runtime error
Update src/app.py
Browse files- src/app.py +28 -9
src/app.py
CHANGED
|
@@ -1,22 +1,41 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
import joblib
|
| 4 |
|
|
|
|
| 5 |
model = joblib.load("src/final_model.pkl")
|
| 6 |
features = joblib.load("src/model_features.pkl")
|
| 7 |
|
| 8 |
-
st.title("
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
input_df = input_df.reindex(columns=features, fill_value=0)
|
| 19 |
|
| 20 |
-
if st.button("Predict"):
|
| 21 |
-
prediction = model.predict(input_df)
|
| 22 |
-
st.success(f"
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
import joblib
|
| 5 |
|
| 6 |
+
# Load model
|
| 7 |
model = joblib.load("src/final_model.pkl")
|
| 8 |
features = joblib.load("src/model_features.pkl")
|
| 9 |
|
| 10 |
+
st.title("🔥 Calorie Burn Predictor")
|
| 11 |
|
| 12 |
+
# Inputs
|
| 13 |
+
sex = st.selectbox("Sex", ["male", "female"])
|
| 14 |
+
age = st.number_input("Age", 10, 100, 25)
|
| 15 |
+
height = st.number_input("Height (cm)", 100.0, 220.0, 170.0)
|
| 16 |
+
weight = st.number_input("Weight (kg)", 30.0, 200.0, 70.0)
|
| 17 |
+
duration = st.number_input("Workout Duration (min)", 1.0, 300.0, 30.0)
|
| 18 |
+
heart_rate = st.number_input("Heart Rate", 50.0, 200.0, 100.0)
|
| 19 |
+
body_temp = st.number_input("Body Temperature", 35.0, 42.0, 37.0)
|
| 20 |
|
| 21 |
+
# Feature engineering
|
| 22 |
+
bmi = weight / ((height/100)**2)
|
| 23 |
|
| 24 |
+
# Create dataframe
|
| 25 |
+
input_df = pd.DataFrame([{
|
| 26 |
+
"Age": age,
|
| 27 |
+
"Height": height,
|
| 28 |
+
"Weight": weight,
|
| 29 |
+
"Duration": duration,
|
| 30 |
+
"Heart_Rate": heart_rate,
|
| 31 |
+
"Body_Temp": body_temp,
|
| 32 |
+
"BMI": bmi,
|
| 33 |
+
"Sex_male": 1 if sex == "male" else 0
|
| 34 |
+
}])
|
| 35 |
|
| 36 |
+
# Align features
|
| 37 |
input_df = input_df.reindex(columns=features, fill_value=0)
|
| 38 |
|
| 39 |
+
if st.button("Predict Calories"):
|
| 40 |
+
prediction = model.predict(input_df)
|
| 41 |
+
st.success(f"🔥 Estimated Calories Burned: {prediction[0]:.2f}")
|