Spaces:
Sleeping
Sleeping
Upload 3 files
Browse filesDiscover how many calories you burn with ease! Our Calories Burn Predictor is a simple yet powerful app designed to help you track your fitness progress.
Key Features:
➤Easy Input: Provide details like age, gender, height, weight, exercise duration, heart rate, and body temperature.
➤Instant Results: Get accurate calorie burn predictions in just one click.
➤User-Friendly Design: Enjoy a sleek, dark-themed interface for a smooth experience.
➤Fitness Tracking Made Simple: Perfect for both fitness enthusiasts and casual users.
➤Built with Care: Developed by M. Nabeel to bring precision and simplicity to your fitness journey.
Start your journey toward better health today!
- app.py +105 -0
- final_pipe.pkl +3 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import pickle
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# Load the model at the start
|
| 6 |
+
#@st.cache_resource
|
| 7 |
+
def load_model(pkl_file):
|
| 8 |
+
"""Load the prediction model from a file."""
|
| 9 |
+
with open(pkl_file, 'rb') as model_file:
|
| 10 |
+
return pickle.load(model_file)
|
| 11 |
+
|
| 12 |
+
def main():
|
| 13 |
+
# Title and layout
|
| 14 |
+
st.markdown("<h1 style='text-align: center; margin-top: -30px;'>Calories Burn Predictor 🏋🏽</h1>", unsafe_allow_html=True)
|
| 15 |
+
|
| 16 |
+
# Input fields
|
| 17 |
+
st.subheader("Enter Your Details:")
|
| 18 |
+
|
| 19 |
+
gender = st.radio("Gender", options=["Male", "Female"])
|
| 20 |
+
age_input = st.text_input("Age (years):", placeholder="e.g., 25")
|
| 21 |
+
height_input = st.text_input("Height (cm):", placeholder="e.g., 170")
|
| 22 |
+
weight_input = st.text_input("Weight (kg):", placeholder="e.g., 70")
|
| 23 |
+
duration_input = st.text_input("Duration of Exercise (minutes):", placeholder="e.g., 30")
|
| 24 |
+
heart_rate_input = st.text_input("Heart Rate (bpm):", placeholder="e.g., 100")
|
| 25 |
+
body_temp_input = st.text_input("Body Temperature (°C):", placeholder="e.g., 36.5")
|
| 26 |
+
|
| 27 |
+
# Prediction button
|
| 28 |
+
if st.button("Predict"):
|
| 29 |
+
inputs_valid, validated_inputs = validate_inputs(
|
| 30 |
+
gender, age_input, height_input, weight_input, duration_input, heart_rate_input, body_temp_input
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
if inputs_valid:
|
| 34 |
+
predict_calories(validated_inputs)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def validate_inputs(gender, age_input, height_input, weight_input, duration_input, heart_rate_input, body_temp_input):
|
| 38 |
+
"""Validate user inputs and return a flag with validated inputs."""
|
| 39 |
+
errors = []
|
| 40 |
+
|
| 41 |
+
def validate_input(value, field_name, is_float=False, is_int=False):
|
| 42 |
+
if not value.strip():
|
| 43 |
+
errors.append(f"Please enter your {field_name}.")
|
| 44 |
+
return None
|
| 45 |
+
try:
|
| 46 |
+
if is_float:
|
| 47 |
+
return float(value)
|
| 48 |
+
elif is_int:
|
| 49 |
+
return int(float(value))
|
| 50 |
+
else:
|
| 51 |
+
return value
|
| 52 |
+
except ValueError:
|
| 53 |
+
errors.append(f"Please enter a valid numeric value for {field_name}.")
|
| 54 |
+
return None
|
| 55 |
+
|
| 56 |
+
# Validate each input
|
| 57 |
+
age = validate_input(age_input, "Age", is_int=True)
|
| 58 |
+
height = validate_input(height_input, "Height", is_float=True)
|
| 59 |
+
weight = validate_input(weight_input, "Weight", is_float=True)
|
| 60 |
+
duration = validate_input(duration_input, "Duration of Exercise", is_float=True)
|
| 61 |
+
heart_rate = validate_input(heart_rate_input, "Heart Rate", is_float=True)
|
| 62 |
+
body_temp = validate_input(body_temp_input, "Body Temperature", is_float=True)
|
| 63 |
+
|
| 64 |
+
if errors:
|
| 65 |
+
for error in errors:
|
| 66 |
+
st.error(error)
|
| 67 |
+
return False, None
|
| 68 |
+
|
| 69 |
+
return True, {
|
| 70 |
+
"Gender": gender,
|
| 71 |
+
"Age": age,
|
| 72 |
+
"Height": height,
|
| 73 |
+
"Weight": weight,
|
| 74 |
+
"Duration": duration,
|
| 75 |
+
"Heart_Rate": heart_rate,
|
| 76 |
+
"Body_Temp": body_temp
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
def predict_calories(inputs):
|
| 80 |
+
"""Perform the calorie prediction and display the result."""
|
| 81 |
+
try:
|
| 82 |
+
# Convert inputs to DataFrame
|
| 83 |
+
input_data = pd.DataFrame([
|
| 84 |
+
[
|
| 85 |
+
inputs["Gender"],
|
| 86 |
+
inputs["Age"],
|
| 87 |
+
inputs["Height"],
|
| 88 |
+
inputs["Weight"],
|
| 89 |
+
inputs["Duration"],
|
| 90 |
+
inputs["Heart_Rate"],
|
| 91 |
+
inputs["Body_Temp"]
|
| 92 |
+
]
|
| 93 |
+
], columns=['Gender', 'Age', 'Height', 'Weight', 'Duration', 'Heart_Rate', 'Body_Temp'])
|
| 94 |
+
|
| 95 |
+
# Predict and display the result
|
| 96 |
+
result = pipe.predict(input_data)[0]
|
| 97 |
+
st.success(f"Calories burned: {result:.2f} kcal")
|
| 98 |
+
except Exception as e:
|
| 99 |
+
st.error(f"An error occurred during prediction: {e}")
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
|
| 103 |
+
pipe = load_model("final_pipe.pkl")
|
| 104 |
+
main()
|
| 105 |
+
st.markdown("<br><br><h5 style='text-align: center;'>Developed by M.Nabeel</h5>", unsafe_allow_html=True)
|
final_pipe.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5d6a34c40c5225c77c8d64e675675f02511a81d6547c5f08b15cb9d33ca9f05
|
| 3 |
+
size 439060
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
numpy==1.26.4
|
| 3 |
+
streamlit==1.37.1
|
| 4 |
+
scikit-learn==1.5.1
|
| 5 |
+
xgboost==2.1.2
|