Update src/streamlit_app.py
Browse files- src/streamlit_app.py +92 -150
src/streamlit_app.py
CHANGED
|
@@ -1,177 +1,119 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
# --------------------------------------------------
|
| 6 |
-
st.set_page_config(
|
| 7 |
-
page_title="FitPlan AI",
|
| 8 |
-
page_icon="💪",
|
| 9 |
-
layout="centered"
|
| 10 |
-
)
|
| 11 |
|
| 12 |
-
# -
|
| 13 |
-
#
|
| 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 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 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.
|
| 83 |
-
st.
|
| 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 |
-
|
| 92 |
-
st.
|
| 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=
|
| 99 |
with col2:
|
| 100 |
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1)
|
| 101 |
|
| 102 |
-
st.
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
| 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 |
-
#
|
| 127 |
# --------------------------------------------------
|
| 128 |
if submit:
|
| 129 |
-
|
| 130 |
-
|
| 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 |
-
#
|
| 137 |
-
|
| 138 |
-
bmi = round(weight / (
|
| 139 |
|
| 140 |
-
# -------- BMI Classification --------
|
| 141 |
if bmi < 18.5:
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
elif
|
| 146 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# 1. Basic Configuration
|
| 4 |
+
st.set_page_config(page_title="FitPlan AI", page_icon="💪")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# 2. CSS with High-Priority Selectors
|
| 7 |
+
# This forces the background image and ensures font visibility
|
|
|
|
| 8 |
st.markdown("""
|
| 9 |
<style>
|
| 10 |
+
/* Full Page Background */
|
| 11 |
+
[data-testid="stAppViewContainer"] {
|
| 12 |
+
background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
|
| 13 |
+
url("https://images.unsplash.com/photo-1517836357463-d25dfeac3438?q=80&w=2070&auto=format&fit=crop");
|
| 14 |
+
background-size: cover;
|
| 15 |
+
background-position: center;
|
| 16 |
+
background-attachment: fixed;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
/* Transparent Header */
|
| 20 |
+
[data-testid="stHeader"] {
|
| 21 |
+
background: rgba(0,0,0,0);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/* Making the Form readable against the dark background */
|
| 25 |
+
div[data-testid="stForm"] {
|
| 26 |
+
background-color: rgba(255, 255, 255, 0.95) !important;
|
| 27 |
+
padding: 2rem !important;
|
| 28 |
+
border-radius: 15px !important;
|
| 29 |
+
border: 2px solid #3b82f6 !important;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
/* --- FONT COLORS (FORCED VISIBILITY) --- */
|
| 33 |
+
/* Main Title White (Outside Form) */
|
| 34 |
+
.title-text {
|
| 35 |
+
color: #FFFFFF !important;
|
| 36 |
+
text-shadow: 2px 2px 4px #000000;
|
| 37 |
+
font-size: 3rem;
|
| 38 |
+
font-weight: bold;
|
| 39 |
+
text-align: center;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
/* Form Labels (Dark Blue) */
|
| 43 |
+
label, p, .stMarkdown {
|
| 44 |
+
color: #1e293b !important;
|
| 45 |
+
font-weight: 600 !important;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
/* Section Headers inside form (Orange) */
|
| 49 |
+
.form-header {
|
| 50 |
+
color: #f97316 !important;
|
| 51 |
+
font-weight: 800;
|
| 52 |
+
margin-bottom: 0px;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/* Force metric values to be visible */
|
| 56 |
+
[data-testid="stMetricValue"] {
|
| 57 |
+
color: #2563eb !important;
|
| 58 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
</style>
|
| 60 |
""", unsafe_allow_html=True)
|
| 61 |
|
| 62 |
# --------------------------------------------------
|
| 63 |
+
# UI Elements
|
| 64 |
# --------------------------------------------------
|
| 65 |
+
st.markdown('<p class="title-text">💪 FitPlan AI</p>', unsafe_allow_html=True)
|
| 66 |
+
st.markdown("<p style='text-align:center; color:white;'>Your personalized gym companion.</p>", unsafe_allow_html=True)
|
|
|
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
with st.form("fitness_form"):
|
| 69 |
+
st.markdown('<p class="form-header">🧍♂️ 1. PERSONAL INFORMATION</p>', unsafe_allow_html=True)
|
| 70 |
+
|
| 71 |
+
name = st.text_input("Full Name *", placeholder="Enter your name")
|
|
|
|
|
|
|
| 72 |
|
| 73 |
col1, col2 = st.columns(2)
|
| 74 |
with col1:
|
| 75 |
+
height = st.number_input("Height (cm) *", min_value=0.0, step=1.0)
|
| 76 |
with col2:
|
| 77 |
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1)
|
| 78 |
|
| 79 |
+
st.markdown("---")
|
| 80 |
+
st.markdown('<p class="form-header">🏋️ 2. FITNESS DETAILS</p>', unsafe_allow_html=True)
|
| 81 |
+
|
| 82 |
+
goal = st.selectbox("Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
|
| 83 |
+
|
| 84 |
+
equipment = st.multiselect("Available Equipment",
|
| 85 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "Kettlebell", "No Equipment"],
|
| 86 |
+
default=["No Equipment"])
|
| 87 |
+
|
| 88 |
+
level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True)
|
| 89 |
|
| 90 |
+
submit = st.form_submit_button("GENERATE MY PLAN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
# --------------------------------------------------
|
| 93 |
+
# Calculations & Logic
|
| 94 |
# --------------------------------------------------
|
| 95 |
if submit:
|
| 96 |
+
if not name.strip() or height <= 0 or weight <= 0:
|
| 97 |
+
st.error("🚨 Please fill in all required fields accurately.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
else:
|
| 99 |
+
# BMI Logic
|
| 100 |
+
h_m = height / 100
|
| 101 |
+
bmi = round(weight / (h_m ** 2), 2)
|
| 102 |
|
|
|
|
| 103 |
if bmi < 18.5:
|
| 104 |
+
cat, color = "Underweight", "blue"
|
| 105 |
+
elif 18.5 <= bmi < 25:
|
| 106 |
+
cat, color = "Normal", "green"
|
| 107 |
+
elif 25 <= bmi < 30:
|
| 108 |
+
cat, color = "Overweight", "orange"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
else:
|
| 110 |
+
cat, color = "Obese", "red"
|
| 111 |
+
|
| 112 |
+
# Result Display
|
| 113 |
+
st.success(f"✅ Success! Data processed for {name}.")
|
| 114 |
+
|
| 115 |
+
res1, res2 = st.columns(2)
|
| 116 |
+
res1.metric("BMI Score", bmi)
|
| 117 |
+
res2.markdown(f"### Status: :{color}[{cat}]")
|
| 118 |
+
|
| 119 |
+
st.info(f"**Goal:** {goal} | **Level:** {level}")
|