Update src/streamlit_app.py
Browse files- src/streamlit_app.py +113 -55
src/streamlit_app.py
CHANGED
|
@@ -1,89 +1,147 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
|
|
|
| 3 |
# Page Configuration
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
|
|
|
|
|
|
| 7 |
st.markdown("""
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 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("
|
| 25 |
|
| 26 |
-
# ---
|
|
|
|
|
|
|
| 27 |
with st.form("fitness_form"):
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
col1, col2 = st.columns(2)
|
| 32 |
with col1:
|
| 33 |
-
height = st.number_input(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
with col2:
|
| 35 |
-
weight = st.number_input(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
if not name.strip():
|
| 56 |
-
st.error("Please enter your name.")
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
-
#
|
| 61 |
height_m = height / 100 # Convert cm to meters
|
| 62 |
bmi = weight / (height_m ** 2)
|
| 63 |
-
|
| 64 |
|
| 65 |
-
#
|
| 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
|
| 73 |
category = "Overweight"
|
| 74 |
color = "orange"
|
| 75 |
else:
|
| 76 |
category = "Obese"
|
| 77 |
color = "red"
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
st.success(f"Profile
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# --------------------------------------------------
|
| 4 |
# Page Configuration
|
| 5 |
+
# --------------------------------------------------
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="FitPlan AI",
|
| 8 |
+
page_icon="💪",
|
| 9 |
+
layout="centered"
|
| 10 |
+
)
|
| 11 |
|
| 12 |
+
# --------------------------------------------------
|
| 13 |
+
# Custom Styling (HF Compatible)
|
| 14 |
+
# --------------------------------------------------
|
| 15 |
st.markdown("""
|
| 16 |
+
<style>
|
| 17 |
+
.stApp {
|
| 18 |
+
background: linear-gradient(135deg, #e3f2fd, #f8fbff);
|
| 19 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
.block-container {
|
| 22 |
+
background-color: white;
|
| 23 |
+
padding: 2rem;
|
| 24 |
+
border-radius: 15px;
|
| 25 |
+
max-width: 850px;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.stButton > button {
|
| 29 |
+
width: 100%;
|
| 30 |
+
height: 3em;
|
| 31 |
+
border-radius: 8px;
|
| 32 |
+
background-color: #FF4B4B;
|
| 33 |
+
color: white;
|
| 34 |
+
font-size: 16px;
|
| 35 |
+
border: none;
|
| 36 |
+
}
|
| 37 |
+
</style>
|
| 38 |
+
""", unsafe_allow_html=True)
|
| 39 |
+
|
| 40 |
+
# --------------------------------------------------
|
| 41 |
+
# Title Section
|
| 42 |
+
# --------------------------------------------------
|
| 43 |
st.title("💪 FitPlan AI")
|
| 44 |
st.subheader("Milestone 1: Fitness Profile & BMI Analysis")
|
| 45 |
+
st.write("Fill in your details to generate your BMI profile.")
|
| 46 |
|
| 47 |
+
# --------------------------------------------------
|
| 48 |
+
# Fitness Profile Form
|
| 49 |
+
# --------------------------------------------------
|
| 50 |
with st.form("fitness_form"):
|
| 51 |
+
|
| 52 |
+
st.header("1️⃣ Personal Information")
|
| 53 |
+
|
| 54 |
+
name = st.text_input("Full Name *")
|
| 55 |
+
|
| 56 |
col1, col2 = st.columns(2)
|
| 57 |
with col1:
|
| 58 |
+
height = st.number_input(
|
| 59 |
+
"Height (cm) *",
|
| 60 |
+
min_value=0.0,
|
| 61 |
+
step=0.1,
|
| 62 |
+
format="%.2f"
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
with col2:
|
| 66 |
+
weight = st.number_input(
|
| 67 |
+
"Weight (kg) *",
|
| 68 |
+
min_value=0.0,
|
| 69 |
+
step=0.1,
|
| 70 |
+
format="%.2f"
|
| 71 |
+
)
|
| 72 |
|
| 73 |
st.divider()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
st.header("2️⃣ Fitness Details")
|
| 76 |
+
|
| 77 |
+
goal = st.selectbox(
|
| 78 |
+
"Fitness Goal",
|
| 79 |
+
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
equipment = st.multiselect(
|
| 83 |
+
"Available Equipment",
|
| 84 |
+
["Dumbbells", "Resistance Band", "Yoga Mat",
|
| 85 |
+
"Kettlebell", "Pull-up Bar", "No Equipment"]
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
level = st.radio(
|
| 89 |
+
"Fitness Level",
|
| 90 |
+
["Beginner", "Intermediate", "Advanced"]
|
| 91 |
+
)
|
| 92 |
|
| 93 |
+
submit = st.form_submit_button("Generate Profile")
|
| 94 |
+
|
| 95 |
+
# --------------------------------------------------
|
| 96 |
+
# Processing Logic
|
| 97 |
+
# --------------------------------------------------
|
| 98 |
+
if submit:
|
| 99 |
+
|
| 100 |
+
# -------- Input Validation --------
|
| 101 |
if not name.strip():
|
| 102 |
+
st.error("⚠ Please enter your name.")
|
| 103 |
+
|
| 104 |
+
elif height <= 0:
|
| 105 |
+
st.error("⚠ Height must be greater than 0 cm.")
|
| 106 |
+
|
| 107 |
+
elif weight <= 0:
|
| 108 |
+
st.error("⚠ Weight must be greater than 0 kg.")
|
| 109 |
+
|
| 110 |
else:
|
| 111 |
+
# -------- BMI Calculation --------
|
| 112 |
height_m = height / 100 # Convert cm to meters
|
| 113 |
bmi = weight / (height_m ** 2)
|
| 114 |
+
bmi = round(bmi, 2)
|
| 115 |
|
| 116 |
+
# -------- BMI Classification --------
|
| 117 |
if bmi < 18.5:
|
| 118 |
category = "Underweight"
|
| 119 |
color = "blue"
|
| 120 |
elif 18.5 <= bmi < 24.9:
|
| 121 |
category = "Normal"
|
| 122 |
color = "green"
|
| 123 |
+
elif 25 <= bmi < 29.9:
|
| 124 |
category = "Overweight"
|
| 125 |
color = "orange"
|
| 126 |
else:
|
| 127 |
category = "Obese"
|
| 128 |
color = "red"
|
| 129 |
|
| 130 |
+
# -------- Display Results --------
|
| 131 |
+
st.success(f"✅ Profile successfully created for {name}!")
|
| 132 |
+
|
| 133 |
+
colA, colB = st.columns(2)
|
| 134 |
+
|
| 135 |
+
with colA:
|
| 136 |
+
st.metric("Your BMI", bmi)
|
| 137 |
+
|
| 138 |
+
with colB:
|
| 139 |
+
st.markdown(f"**BMI Category:** :{color}[{category}]")
|
| 140 |
+
|
| 141 |
+
st.info(f"🎯 Goal: {goal} | 📈 Level: {level}")
|
| 142 |
+
|
| 143 |
+
if equipment:
|
| 144 |
+
st.write("🏋 Available Equipment:", ", ".join(equipment))
|
| 145 |
+
else:
|
| 146 |
+
st.write("🏋 Available Equipment: None selected")
|
| 147 |
+
|