Update src/streamlit_app.py
Browse files- src/streamlit_app.py +74 -87
src/streamlit_app.py
CHANGED
|
@@ -1,102 +1,89 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
# Page
|
| 4 |
-
st.set_page_config(
|
| 5 |
-
page_title="Fitness Plan AI Generator",
|
| 6 |
-
page_icon="💪",
|
| 7 |
-
layout="centered"
|
| 8 |
-
)
|
| 9 |
|
| 10 |
-
# Custom
|
| 11 |
st.markdown("""
|
| 12 |
-
<style>
|
|
|
|
|
|
|
|
|
|
| 13 |
.stButton>button {
|
| 14 |
width: 100%;
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
background:
|
| 18 |
color: white;
|
| 19 |
-
border-radius: 10px;
|
| 20 |
}
|
| 21 |
-
</style>
|
| 22 |
-
""", unsafe_allow_html=True)
|
| 23 |
-
|
| 24 |
-
# Title
|
| 25 |
-
st.markdown("## 🧍 Your Fitness Profile")
|
| 26 |
-
|
| 27 |
-
# Fitness Goal
|
| 28 |
-
goal = st.selectbox(
|
| 29 |
-
"Fitness Goal",
|
| 30 |
-
["Build Muscle", "Lose Weight", "Improve Endurance", "General Fitness"]
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
# Equipment Selection
|
| 34 |
-
st.markdown("### Available Equipment")
|
| 35 |
-
col1, col2, col3 = st.columns(3)
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
bands = st.checkbox("Resistance Bands")
|
| 41 |
-
with col3:
|
| 42 |
-
no_equipment = st.checkbox("No Equipment")
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
st.
|
| 46 |
-
|
| 47 |
-
"",
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
st.
|
| 55 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
if dumbbells:
|
| 59 |
-
equipment.append("Dumbbells")
|
| 60 |
-
if bands:
|
| 61 |
-
equipment.append("Resistance Bands")
|
| 62 |
-
if no_equipment or not equipment:
|
| 63 |
-
equipment.append("Bodyweight")
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
st.write("""
|
| 73 |
-
- **Day 1:** Chest & Triceps
|
| 74 |
-
- **Day 2:** Back & Biceps
|
| 75 |
-
- **Day 3:** Legs
|
| 76 |
-
- **Day 4:** Shoulders & Core
|
| 77 |
-
- **Day 5:** Full Body
|
| 78 |
-
- **Day 6:** Active Recovery
|
| 79 |
-
- **Day 7:** Rest
|
| 80 |
-
""")
|
| 81 |
-
elif goal == "Lose Weight":
|
| 82 |
-
st.write("""
|
| 83 |
-
- **Day 1:** Full Body HIIT
|
| 84 |
-
- **Day 2:** Cardio + Core
|
| 85 |
-
- **Day 3:** Strength Training
|
| 86 |
-
- **Day 4:** HIIT
|
| 87 |
-
- **Day 5:** Cardio
|
| 88 |
-
- **Day 6:** Yoga / Stretching
|
| 89 |
-
- **Day 7:** Rest
|
| 90 |
-
""")
|
| 91 |
else:
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Page Configuration
|
| 4 |
+
st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Custom Styling
|
| 7 |
st.markdown("""
|
| 8 |
+
<style>
|
| 9 |
+
.main {
|
| 10 |
+
background-color: #f5f7f9;
|
| 11 |
+
}
|
| 12 |
.stButton>button {
|
| 13 |
width: 100%;
|
| 14 |
+
border-radius: 5px;
|
| 15 |
+
height: 3em;
|
| 16 |
+
background-color: #FF4B4B;
|
| 17 |
color: white;
|
|
|
|
| 18 |
}
|
| 19 |
+
</style>
|
| 20 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
st.title("💪 FitPlan AI")
|
| 23 |
+
st.subheader("Milestone 1: Fitness Profile & BMI Analysis")
|
| 24 |
+
st.write("Complete the form below to begin your personalized fitness journey.")
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# --- Form Section ---
|
| 27 |
+
with st.form("fitness_form"):
|
| 28 |
+
st.header("1. Personal Information")
|
| 29 |
+
name = st.text_input("Full Name*", placeholder="Enter your name")
|
| 30 |
+
|
| 31 |
+
col1, col2 = st.columns(2)
|
| 32 |
+
with col1:
|
| 33 |
+
height = st.number_input("Height (cm)*", min_value=0.0, step=0.1, help="e.g., 175")
|
| 34 |
+
with col2:
|
| 35 |
+
weight = st.number_input("Weight (kg)*", min_value=0.0, step=0.1, help="e.g., 70")
|
| 36 |
|
| 37 |
+
st.divider()
|
| 38 |
+
|
| 39 |
+
st.header("2. Fitness Details")
|
| 40 |
+
goal = st.selectbox("Fitness Goal",
|
| 41 |
+
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 42 |
+
|
| 43 |
+
level = st.select_slider("Fitness Level",
|
| 44 |
+
options=["Beginner", "Intermediate", "Advanced"])
|
| 45 |
+
|
| 46 |
+
equipment = st.multiselect("Available Equipment",
|
| 47 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "Kettlebell", "Pull-up Bar", "No Equipment"],
|
| 48 |
+
default=["No Equipment"])
|
| 49 |
|
| 50 |
+
submit_button = st.form_submit_button("Generate Profile")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
# --- Logic & Results ---
|
| 53 |
+
if submit_button:
|
| 54 |
+
# 5. Input Validation
|
| 55 |
+
if not name.strip():
|
| 56 |
+
st.error("Please enter your name.")
|
| 57 |
+
elif height <= 0 or weight <= 0:
|
| 58 |
+
st.error("Height and weight must be greater than zero.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
+
# 3. Functional Requirements
|
| 61 |
+
height_m = height / 100 # Convert cm to meters
|
| 62 |
+
bmi = weight / (height_m ** 2)
|
| 63 |
+
bmi_rounded = round(bmi, 2)
|
| 64 |
+
|
| 65 |
+
# Classify BMI
|
| 66 |
+
if bmi < 18.5:
|
| 67 |
+
category = "Underweight"
|
| 68 |
+
color = "blue"
|
| 69 |
+
elif 18.5 <= bmi < 24.9:
|
| 70 |
+
category = "Normal"
|
| 71 |
+
color = "green"
|
| 72 |
+
elif 25.0 <= bmi < 29.9:
|
| 73 |
+
category = "Overweight"
|
| 74 |
+
color = "orange"
|
| 75 |
+
else:
|
| 76 |
+
category = "Obese"
|
| 77 |
+
color = "red"
|
| 78 |
|
| 79 |
+
# 4. Display Results
|
| 80 |
+
st.success(f"Profile Created Successfully for **{name}**!")
|
| 81 |
+
|
| 82 |
+
res_col1, res_col2 = st.columns(2)
|
| 83 |
+
with res_col1:
|
| 84 |
+
st.metric("Your BMI", bmi_rounded)
|
| 85 |
+
with res_col2:
|
| 86 |
+
st.markdown(f"**Category:** :{color}[{category}]")
|
| 87 |
+
|
| 88 |
+
st.info(f"**Goal:** {goal} | **Level:** {level}")
|
| 89 |
+
st.write(f"**Equipment:** {', '.join(equipment)}")
|