sevvaliclal commited on
Commit
7b19fd5
·
verified ·
1 Parent(s): 8db1a9e

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +25 -19
src/app.py CHANGED
@@ -3,39 +3,45 @@ 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}")
 
3
  import numpy as np
4
  import joblib
5
 
6
+ # Load model and features
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
  sex = st.selectbox("Sex", ["male", "female"])
13
  age = st.number_input("Age", 10, 100, 25)
14
  height = st.number_input("Height (cm)", 100.0, 220.0, 170.0)
15
  weight = st.number_input("Weight (kg)", 30.0, 200.0, 70.0)
16
+ duration = st.number_input("Duration (min)", 1.0, 300.0, 30.0)
17
  heart_rate = st.number_input("Heart Rate", 50.0, 200.0, 100.0)
18
+ body_temp = st.number_input("Body Temp", 35.0, 42.0, 37.0)
19
 
20
  # Feature engineering
21
  bmi = weight / ((height/100)**2)
22
 
23
+ # Boş dataframe oluştur
24
+ input_dict = {col: 0 for col in features}
25
+
26
+ # Sayısal değerleri ekle
27
+ input_dict["Age"] = age
28
+ input_dict["Height"] = height
29
+ input_dict["Weight"] = weight
30
+ input_dict["Duration"] = duration
31
+ input_dict["Heart_Rate"] = heart_rate
32
+ input_dict["Body_Temp"] = body_temp
33
+
34
+ # BMI varsa ekle
35
+ if "BMI" in features:
36
+ input_dict["BMI"] = bmi
37
+
38
+ # Sex encoding
39
+ if "Sex_male" in features:
40
+ input_dict["Sex_male"] = 1 if sex == "male" else 0
41
+
42
+ # DataFrame oluştur
43
+ input_df = pd.DataFrame([input_dict])
44
 
45
  if st.button("Predict Calories"):
46
  prediction = model.predict(input_df)
47
+ st.success(f"🔥 Estimated Calories Burned: {prediction[0]:.2f}")