sevvaliclal's picture
Update src/app.py
7b19fd5 verified
Raw
History Blame Contribute Delete
1.35 kB
import streamlit as st
import pandas as pd
import numpy as np
import joblib
# Load model and features
model = joblib.load("src/final_model.pkl")
features = joblib.load("src/model_features.pkl")
st.title("🔥 Calorie Burn Predictor")
sex = st.selectbox("Sex", ["male", "female"])
age = st.number_input("Age", 10, 100, 25)
height = st.number_input("Height (cm)", 100.0, 220.0, 170.0)
weight = st.number_input("Weight (kg)", 30.0, 200.0, 70.0)
duration = st.number_input("Duration (min)", 1.0, 300.0, 30.0)
heart_rate = st.number_input("Heart Rate", 50.0, 200.0, 100.0)
body_temp = st.number_input("Body Temp", 35.0, 42.0, 37.0)
# Feature engineering
bmi = weight / ((height/100)**2)
# Boş dataframe oluştur
input_dict = {col: 0 for col in features}
# Sayısal değerleri ekle
input_dict["Age"] = age
input_dict["Height"] = height
input_dict["Weight"] = weight
input_dict["Duration"] = duration
input_dict["Heart_Rate"] = heart_rate
input_dict["Body_Temp"] = body_temp
# BMI varsa ekle
if "BMI" in features:
input_dict["BMI"] = bmi
# Sex encoding
if "Sex_male" in features:
input_dict["Sex_male"] = 1 if sex == "male" else 0
# DataFrame oluştur
input_df = pd.DataFrame([input_dict])
if st.button("Predict Calories"):
prediction = model.predict(input_df)
st.success(f"🔥 Estimated Calories Burned: {prediction[0]:.2f}")