Update src/streamlit_app.py
Browse files- src/streamlit_app.py +122 -84
src/streamlit_app.py
CHANGED
|
@@ -10,130 +10,168 @@ st.set_page_config(
|
|
| 10 |
)
|
| 11 |
|
| 12 |
# --------------------------------------------------
|
| 13 |
-
# Custom CSS (
|
| 14 |
# --------------------------------------------------
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</style>
|
| 53 |
""", unsafe_allow_html=True)
|
| 54 |
|
| 55 |
# --------------------------------------------------
|
| 56 |
-
#
|
| 57 |
# --------------------------------------------------
|
| 58 |
st.title("πͺ FitPlan AI")
|
| 59 |
-
st.
|
| 60 |
-
st.write("
|
| 61 |
|
| 62 |
# --------------------------------------------------
|
| 63 |
# Fitness Profile Form
|
| 64 |
# --------------------------------------------------
|
| 65 |
with st.form("fitness_form"):
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
|
| 70 |
col1, col2 = st.columns(2)
|
| 71 |
with col1:
|
| 72 |
-
|
| 73 |
-
height = st.number_input("Height (cm) *", min_value=0.0, step=1.0, format="%.1f")
|
| 74 |
with col2:
|
| 75 |
-
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
|
|
|
| 78 |
|
| 79 |
-
st.markdown("#### ποΈ 2. Fitness Details")
|
| 80 |
-
|
| 81 |
goal = st.selectbox(
|
| 82 |
"Fitness Goal",
|
| 83 |
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
|
| 84 |
)
|
| 85 |
|
| 86 |
equipment = st.multiselect(
|
| 87 |
-
"Available Equipment
|
| 88 |
-
["Dumbbells", "Resistance Band", "Yoga Mat",
|
| 89 |
-
|
| 90 |
)
|
| 91 |
|
| 92 |
level = st.radio(
|
| 93 |
"Fitness Level",
|
| 94 |
-
["Beginner", "Intermediate", "Advanced"]
|
| 95 |
-
horizontal=True
|
| 96 |
)
|
| 97 |
|
| 98 |
submit = st.form_submit_button("Generate Profile")
|
| 99 |
|
| 100 |
# --------------------------------------------------
|
| 101 |
-
#
|
| 102 |
# --------------------------------------------------
|
| 103 |
if submit:
|
| 104 |
-
|
|
|
|
| 105 |
if not name.strip():
|
| 106 |
-
st.error("
|
| 107 |
-
elif height <=
|
| 108 |
-
st.error("
|
| 109 |
else:
|
| 110 |
-
# BMI Calculation
|
| 111 |
height_m = height / 100
|
| 112 |
-
bmi = weight / (height_m ** 2)
|
| 113 |
-
bmi_display = round(bmi, 2)
|
| 114 |
|
| 115 |
-
#
|
| 116 |
if bmi < 18.5:
|
| 117 |
-
category
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
elif
|
| 121 |
-
category
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
else:
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
# Results Display
|
| 126 |
-
st.success(f"β
Profile generated for {name}")
|
| 127 |
-
|
| 128 |
-
m_col1, m_col2 = st.columns(2)
|
| 129 |
-
with m_col1:
|
| 130 |
-
st.metric("Your BMI", f"{bmi_display}")
|
| 131 |
-
with m_col2:
|
| 132 |
-
# Using bold colored markdown for high visibility
|
| 133 |
-
st.markdown(f"**Status:** :{color}[{category}]")
|
| 134 |
-
|
| 135 |
-
st.markdown("### π BMI Visual Indicator")
|
| 136 |
-
st.progress(progress)
|
| 137 |
-
|
| 138 |
-
# Summary Box
|
| 139 |
-
st.info(f"**Profile Summary:**\n\n* **Goal:** {goal}\n* **Experience:** {level}\n* **Equipment:** {', '.join(equipment) if equipment else 'None'}")
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
# --------------------------------------------------
|
| 13 |
+
# Custom CSS (HF Compatible + Visible UI)
|
| 14 |
# --------------------------------------------------
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
+
|
| 18 |
+
/* Page background */
|
| 19 |
+
.stApp {
|
| 20 |
+
background-color: #f4f7fb;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
/* Main container */
|
| 24 |
+
.block-container {
|
| 25 |
+
background-color: #ffffff;
|
| 26 |
+
padding: 2.5rem;
|
| 27 |
+
border-radius: 18px;
|
| 28 |
+
max-width: 900px;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/* Headings */
|
| 32 |
+
h1, h2, h3 {
|
| 33 |
+
color: #0f172a !important;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* Labels */
|
| 37 |
+
label {
|
| 38 |
+
color: #1e293b !important;
|
| 39 |
+
font-weight: 600;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* Inputs */
|
| 43 |
+
input, textarea {
|
| 44 |
+
background-color: #ffffff !important;
|
| 45 |
+
color: #0f172a !important;
|
| 46 |
+
border-radius: 10px !important;
|
| 47 |
+
border: 1px solid #cbd5e1 !important;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/* Selectbox & Multiselect */
|
| 51 |
+
div[data-baseweb="select"] {
|
| 52 |
+
background-color: #ffffff !important;
|
| 53 |
+
border-radius: 10px;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* Form card */
|
| 57 |
+
div[data-testid="stForm"] {
|
| 58 |
+
background-color: #f8fafc;
|
| 59 |
+
padding: 2rem;
|
| 60 |
+
border-radius: 14px;
|
| 61 |
+
box-shadow: 0 10px 25px rgba(0,0,0,0.08);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/* Main button */
|
| 65 |
+
.stButton > button {
|
| 66 |
+
width: 100%;
|
| 67 |
+
height: 3.2em;
|
| 68 |
+
border-radius: 10px;
|
| 69 |
+
background: linear-gradient(90deg, #2563eb, #1d4ed8);
|
| 70 |
+
color: white !important;
|
| 71 |
+
font-size: 17px;
|
| 72 |
+
font-weight: 600;
|
| 73 |
+
border: none;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
</style>
|
| 77 |
""", unsafe_allow_html=True)
|
| 78 |
|
| 79 |
# --------------------------------------------------
|
| 80 |
+
# Title Section
|
| 81 |
# --------------------------------------------------
|
| 82 |
st.title("πͺ FitPlan AI")
|
| 83 |
+
st.subheader("Milestone 1: Fitness Profile & BMI Analysis")
|
| 84 |
+
st.write("Enter your details to calculate BMI and generate your fitness profile.")
|
| 85 |
|
| 86 |
# --------------------------------------------------
|
| 87 |
# Fitness Profile Form
|
| 88 |
# --------------------------------------------------
|
| 89 |
with st.form("fitness_form"):
|
| 90 |
+
|
| 91 |
+
# -------- Section 1 --------
|
| 92 |
+
st.header("π§ββοΈ 1. Personal Information")
|
| 93 |
+
|
| 94 |
+
name = st.text_input("Full Name *")
|
| 95 |
|
| 96 |
col1, col2 = st.columns(2)
|
| 97 |
with col1:
|
| 98 |
+
height = st.number_input("Height (cm) *", min_value=0.0, step=0.1)
|
|
|
|
| 99 |
with col2:
|
| 100 |
+
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1)
|
| 101 |
+
|
| 102 |
+
st.divider()
|
| 103 |
|
| 104 |
+
# -------- Section 2 --------
|
| 105 |
+
st.header("ποΈ 2. Fitness Details")
|
| 106 |
|
|
|
|
|
|
|
| 107 |
goal = st.selectbox(
|
| 108 |
"Fitness Goal",
|
| 109 |
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
|
| 110 |
)
|
| 111 |
|
| 112 |
equipment = st.multiselect(
|
| 113 |
+
"Available Equipment",
|
| 114 |
+
["Dumbbells", "Resistance Band", "Yoga Mat",
|
| 115 |
+
"Kettlebell", "Pull-up Bar", "No Equipment"]
|
| 116 |
)
|
| 117 |
|
| 118 |
level = st.radio(
|
| 119 |
"Fitness Level",
|
| 120 |
+
["Beginner", "Intermediate", "Advanced"]
|
|
|
|
| 121 |
)
|
| 122 |
|
| 123 |
submit = st.form_submit_button("Generate Profile")
|
| 124 |
|
| 125 |
# --------------------------------------------------
|
| 126 |
+
# Processing & Output
|
| 127 |
# --------------------------------------------------
|
| 128 |
if submit:
|
| 129 |
+
|
| 130 |
+
# -------- Validation --------
|
| 131 |
if not name.strip():
|
| 132 |
+
st.error("β Please enter your name.")
|
| 133 |
+
elif height <= 0 or weight <= 0:
|
| 134 |
+
st.error("β Height and weight must be greater than zero.")
|
| 135 |
else:
|
| 136 |
+
# -------- BMI Calculation --------
|
| 137 |
height_m = height / 100
|
| 138 |
+
bmi = round(weight / (height_m ** 2), 2)
|
|
|
|
| 139 |
|
| 140 |
+
# -------- BMI Classification --------
|
| 141 |
if bmi < 18.5:
|
| 142 |
+
category = "Underweight"
|
| 143 |
+
color = "blue"
|
| 144 |
+
progress = bmi / 18.5
|
| 145 |
+
elif 18.5 <= bmi < 24.9:
|
| 146 |
+
category = "Normal"
|
| 147 |
+
color = "green"
|
| 148 |
+
progress = bmi / 24.9
|
| 149 |
+
elif 25 <= bmi < 29.9:
|
| 150 |
+
category = "Overweight"
|
| 151 |
+
color = "orange"
|
| 152 |
+
progress = bmi / 29.9
|
| 153 |
+
else:
|
| 154 |
+
category = "Obese"
|
| 155 |
+
color = "red"
|
| 156 |
+
progress = 1.0
|
| 157 |
+
|
| 158 |
+
# -------- Results Section --------
|
| 159 |
+
st.success(f"β
Profile created successfully for **{name}**")
|
| 160 |
+
|
| 161 |
+
colA, colB = st.columns(2)
|
| 162 |
+
with colA:
|
| 163 |
+
st.metric("Your BMI", bmi)
|
| 164 |
+
with colB:
|
| 165 |
+
st.markdown(f"**BMI Category:** :{color}[{category}]")
|
| 166 |
+
|
| 167 |
+
# -------- BMI Progress Bar --------
|
| 168 |
+
st.markdown("### π BMI Progress Indicator")
|
| 169 |
+
st.progress(min(progress, 1.0))
|
| 170 |
+
|
| 171 |
+
# -------- Summary --------
|
| 172 |
+
st.info(f"π― Goal: {goal} | π Level: {level}")
|
| 173 |
+
|
| 174 |
+
if equipment:
|
| 175 |
+
st.write("π§° Equipment:", ", ".join(equipment))
|
| 176 |
else:
|
| 177 |
+
st.write("π§° Equipment: No equipment selected")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|