Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +56 -127
src/streamlit_app.py
CHANGED
|
@@ -1,130 +1,59 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
- Your fitness profile
|
| 18 |
-
- Your goals
|
| 19 |
-
- Available equipment
|
| 20 |
-
""")
|
| 21 |
-
|
| 22 |
-
if st.button("Generate My Plan"):
|
| 23 |
-
st.session_state.step = 2
|
| 24 |
-
|
| 25 |
-
# ---------------- STEP 2: FITNESS PROFILE ----------------
|
| 26 |
-
elif st.session_state.step == 2:
|
| 27 |
-
st.title("👤 Your Fitness Profile")
|
| 28 |
-
|
| 29 |
-
age = st.number_input("Age", min_value=10, max_value=80)
|
| 30 |
-
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
|
| 31 |
-
weight = st.number_input("Weight (kg)")
|
| 32 |
-
height = st.number_input("Height (cm)")
|
| 33 |
-
experience = st.selectbox(
|
| 34 |
-
"Fitness Level",
|
| 35 |
-
["Beginner", "Intermediate", "Advanced"]
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
if st.button("Next"):
|
| 39 |
-
st.session_state.profile = {
|
| 40 |
-
"age": age,
|
| 41 |
-
"gender": gender,
|
| 42 |
-
"weight": weight,
|
| 43 |
-
"height": height,
|
| 44 |
-
"experience": experience
|
| 45 |
-
}
|
| 46 |
-
st.session_state.step = 3
|
| 47 |
-
|
| 48 |
-
# ---------------- STEP 3: SELECT GOAL ----------------
|
| 49 |
-
elif st.session_state.step == 3:
|
| 50 |
-
st.title("🎯 Select Your Goal")
|
| 51 |
-
|
| 52 |
-
goal = st.radio(
|
| 53 |
-
"Choose your fitness goal:",
|
| 54 |
-
["Increase Flexibility 🧘",
|
| 55 |
-
"Build Muscle 💪",
|
| 56 |
-
"Weight Loss / Get Lean 🔥"]
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
if st.button("Next"):
|
| 60 |
-
st.session_state.goal = goal
|
| 61 |
-
st.session_state.step = 4
|
| 62 |
-
|
| 63 |
-
# ---------------- STEP 4: SELECT EQUIPMENT ----------------
|
| 64 |
-
elif st.session_state.step == 4:
|
| 65 |
-
st.title("🏋️ Select Available Equipment")
|
| 66 |
-
|
| 67 |
-
equipment = st.multiselect(
|
| 68 |
-
"Select equipment you have access to:",
|
| 69 |
-
[
|
| 70 |
-
"Dumbbells",
|
| 71 |
-
"Barbell",
|
| 72 |
-
"Resistance Bands",
|
| 73 |
-
"Treadmill",
|
| 74 |
-
"Stationary Bike",
|
| 75 |
-
"Bench Press",
|
| 76 |
-
"Pull-up Bar",
|
| 77 |
-
"Kettlebells",
|
| 78 |
-
"Leg Press Machine",
|
| 79 |
-
"Cable Machine",
|
| 80 |
-
"Smith Machine",
|
| 81 |
-
"No Equipment (Bodyweight Only)"
|
| 82 |
-
]
|
| 83 |
-
)
|
| 84 |
-
|
| 85 |
-
if st.button("Generate Plan"):
|
| 86 |
-
st.session_state.equipment = equipment
|
| 87 |
-
st.session_state.step = 5
|
| 88 |
-
|
| 89 |
-
# ---------------- STEP 5: DISPLAY PLAN ----------------
|
| 90 |
-
elif st.session_state.step == 5:
|
| 91 |
-
st.title("📄 Your Personalized Fitness Plan")
|
| 92 |
-
|
| 93 |
-
st.subheader("Profile Summary")
|
| 94 |
-
st.write(st.session_state.profile)
|
| 95 |
-
st.write("Goal:", st.session_state.goal)
|
| 96 |
-
st.write("Equipment:", st.session_state.equipment)
|
| 97 |
-
|
| 98 |
-
st.divider()
|
| 99 |
-
|
| 100 |
-
# Simple frontend demo output
|
| 101 |
-
if "Build Muscle" in st.session_state.goal:
|
| 102 |
-
st.success("💪 Suggested Plan: 4-Day Strength Split")
|
| 103 |
-
st.markdown("""
|
| 104 |
-
- Day 1: Chest + Triceps
|
| 105 |
-
- Day 2: Back + Biceps
|
| 106 |
-
- Day 3: Legs
|
| 107 |
-
- Day 4: Shoulders + Core
|
| 108 |
-
""")
|
| 109 |
-
|
| 110 |
-
elif "Flexibility" in st.session_state.goal:
|
| 111 |
-
st.success("🧘 Suggested Plan: 5-Day Mobility Routine")
|
| 112 |
-
st.markdown("""
|
| 113 |
-
- Dynamic Stretching
|
| 114 |
-
- Yoga Flow
|
| 115 |
-
- Hamstring & Hip Mobility
|
| 116 |
-
- Shoulder Mobility
|
| 117 |
-
- Core Stability
|
| 118 |
-
""")
|
| 119 |
-
|
| 120 |
else:
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
def calculate_bmi(weight, height_cm):
|
| 4 |
+
# Convert height from cm to meters
|
| 5 |
+
height_m = height_cm / 100
|
| 6 |
+
# BMI formula: weight (kg) / (height in meters)^2
|
| 7 |
+
bmi = weight / (height_m ** 2)
|
| 8 |
+
return round(bmi, 2)
|
| 9 |
+
|
| 10 |
+
def get_category(bmi):
|
| 11 |
+
if bmi < 18.5:
|
| 12 |
+
return "Underweight"
|
| 13 |
+
elif 18.5 <= bmi < 24.9:
|
| 14 |
+
return "Normal"
|
| 15 |
+
elif 25 <= bmi < 29.9:
|
| 16 |
+
return "Overweight"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
else:
|
| 18 |
+
return "Obese"
|
| 19 |
+
|
| 20 |
+
# App UI
|
| 21 |
+
st.set_page_config(page_title="FitPlan-AI", page_icon="💪")
|
| 22 |
+
st.title("💪 FitPlan-AI: Personalized Fitness Profile")
|
| 23 |
+
|
| 24 |
+
with st.form("fitness_form"):
|
| 25 |
+
st.header("Personal Information")
|
| 26 |
+
name = st.text_input("Full Name*", placeholder="Enter your name")
|
| 27 |
+
|
| 28 |
+
col1, col2 = st.columns(2)
|
| 29 |
+
with col1:
|
| 30 |
+
height = st.number_input("Height (cm)*", min_value=1.0, step=0.1)
|
| 31 |
+
with col2:
|
| 32 |
+
weight = st.number_input("Weight (kg)*", min_value=1.0, step=0.1)
|
| 33 |
+
|
| 34 |
+
st.header("Fitness Details")
|
| 35 |
+
goal = st.selectbox("Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 36 |
+
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"])
|
| 37 |
+
equipment = st.multiselect("Available Equipment", ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Kettlebell", "Pull-up Bar"])
|
| 38 |
+
|
| 39 |
+
submit = st.form_submit_button("Generate Profile")
|
| 40 |
+
|
| 41 |
+
if submit:
|
| 42 |
+
# Validation: Ensure name is not empty
|
| 43 |
+
if not name.strip():
|
| 44 |
+
st.error("Please enter your name.")
|
| 45 |
+
elif height <= 0 or weight <= 0:
|
| 46 |
+
st.error("Height and Weight must be positive values.")
|
| 47 |
+
else:
|
| 48 |
+
# BMI Logic
|
| 49 |
+
user_bmi = calculate_bmi(weight, height)
|
| 50 |
+
category = get_category(user_bmi)
|
| 51 |
+
|
| 52 |
+
# Display Results
|
| 53 |
+
st.success(f"Profile Created Successfully for {name}!")
|
| 54 |
+
st.metric(label="Your Calculated BMI", value=user_bmi)
|
| 55 |
+
st.info(f"Health Category: **{category}**")
|
| 56 |
+
|
| 57 |
+
# Summary
|
| 58 |
+
st.write(f"**Goal:** {goal} | **Level:** {level}")
|
| 59 |
+
st.write(f"**Equipment:** {', '.join(equipment) if equipment else 'None selected'}")
|