Update src/streamlit_app.py
Browse files- src/streamlit_app.py +84 -122
src/streamlit_app.py
CHANGED
|
@@ -10,168 +10,130 @@ 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 |
-
h1, h2, h3 {
|
| 33 |
-
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
/*
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/*
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 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 |
-
#
|
| 81 |
# --------------------------------------------------
|
| 82 |
st.title("πͺ FitPlan AI")
|
| 83 |
-
st.
|
| 84 |
-
st.write("
|
| 85 |
|
| 86 |
# --------------------------------------------------
|
| 87 |
# Fitness Profile Form
|
| 88 |
# --------------------------------------------------
|
| 89 |
with st.form("fitness_form"):
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
st.
|
| 93 |
-
|
| 94 |
-
name = st.text_input("Full Name *")
|
| 95 |
|
| 96 |
col1, col2 = st.columns(2)
|
| 97 |
with col1:
|
| 98 |
-
|
|
|
|
| 99 |
with col2:
|
| 100 |
-
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1)
|
| 101 |
-
|
| 102 |
-
st.divider()
|
| 103 |
|
| 104 |
-
|
| 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 |
-
|
| 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 |
-
#
|
| 127 |
# --------------------------------------------------
|
| 128 |
if submit:
|
| 129 |
-
|
| 130 |
-
# -------- Validation --------
|
| 131 |
if not name.strip():
|
| 132 |
-
st.error("
|
| 133 |
-
elif height <=
|
| 134 |
-
st.error("
|
| 135 |
else:
|
| 136 |
-
#
|
| 137 |
height_m = height / 100
|
| 138 |
-
bmi =
|
|
|
|
| 139 |
|
| 140 |
-
#
|
| 141 |
if bmi < 18.5:
|
| 142 |
-
category = "Underweight"
|
| 143 |
-
|
| 144 |
-
progress =
|
| 145 |
-
elif
|
| 146 |
-
category = "
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
)
|
| 11 |
|
| 12 |
# --------------------------------------------------
|
| 13 |
+
# Custom CSS (Ensuring High Visibility)
|
| 14 |
# --------------------------------------------------
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
+
/* Force a clean, light background for the whole app */
|
| 18 |
+
.stApp {
|
| 19 |
+
background-color: #F0F2F6;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* Card-style container for the form */
|
| 23 |
+
div[data-testid="stForm"] {
|
| 24 |
+
background-color: #FFFFFF !important;
|
| 25 |
+
padding: 30px !important;
|
| 26 |
+
border-radius: 15px !important;
|
| 27 |
+
border: 1px solid #E0E0E0 !important;
|
| 28 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.05);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/* Force all text labels and headers to be Dark Blue/Black */
|
| 32 |
+
h1, h2, h3, p, label, .stMarkdown {
|
| 33 |
+
color: #1A1C25 !important;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* Style the Input boxes for clarity */
|
| 37 |
+
input {
|
| 38 |
+
color: #1A1C25 !important;
|
| 39 |
+
background-color: #F8F9FA !important;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* Button styling */
|
| 43 |
+
.stButton > button {
|
| 44 |
+
width: 100%;
|
| 45 |
+
background: linear-gradient(90deg, #2563eb, #1d4ed8);
|
| 46 |
+
color: white !important;
|
| 47 |
+
font-weight: bold;
|
| 48 |
+
border: none;
|
| 49 |
+
padding: 10px;
|
| 50 |
+
border-radius: 8px;
|
| 51 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</style>
|
| 53 |
""", unsafe_allow_html=True)
|
| 54 |
|
| 55 |
# --------------------------------------------------
|
| 56 |
+
# Header
|
| 57 |
# --------------------------------------------------
|
| 58 |
st.title("πͺ FitPlan AI")
|
| 59 |
+
st.markdown("### Milestone 1: Fitness Profile & BMI Analysis")
|
| 60 |
+
st.write("Complete your profile below to calculate your health metrics.")
|
| 61 |
|
| 62 |
# --------------------------------------------------
|
| 63 |
# Fitness Profile Form
|
| 64 |
# --------------------------------------------------
|
| 65 |
with st.form("fitness_form"):
|
| 66 |
+
st.markdown("#### π§ββοΈ 1. Personal Information")
|
| 67 |
+
|
| 68 |
+
name = st.text_input("Full Name *", placeholder="e.g. John Doe")
|
|
|
|
|
|
|
| 69 |
|
| 70 |
col1, col2 = st.columns(2)
|
| 71 |
with col1:
|
| 72 |
+
# Added min_value logic to prevent negatives
|
| 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, format="%.1f")
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
st.markdown("---")
|
|
|
|
| 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 (Select all that apply)",
|
| 88 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "Kettlebell", "Pull-up Bar", "No Equipment"],
|
| 89 |
+
default=["No Equipment"]
|
| 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 |
+
# Logic & Output
|
| 102 |
# --------------------------------------------------
|
| 103 |
if submit:
|
| 104 |
+
# Validation checks
|
|
|
|
| 105 |
if not name.strip():
|
| 106 |
+
st.error("π¨ Name is required.")
|
| 107 |
+
elif height <= 50 or weight <= 10: # Realistic safety checks
|
| 108 |
+
st.error("π¨ Please enter valid height and weight values.")
|
| 109 |
else:
|
| 110 |
+
# BMI Calculation
|
| 111 |
height_m = height / 100
|
| 112 |
+
bmi = weight / (height_m ** 2)
|
| 113 |
+
bmi_display = round(bmi, 2)
|
| 114 |
|
| 115 |
+
# Precise BMI Classification
|
| 116 |
if bmi < 18.5:
|
| 117 |
+
category, color, progress = "Underweight", "blue", 0.25
|
| 118 |
+
elif 18.5 <= bmi < 25.0:
|
| 119 |
+
category, color, progress = "Normal", "green", 0.50
|
| 120 |
+
elif 25.0 <= bmi < 30.0:
|
| 121 |
+
category, color, progress = "Overweight", "orange", 0.75
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
else:
|
| 123 |
+
category, color, progress = "Obese", "red", 1.0
|
| 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'}")
|