Update src/streamlit_app.py
Browse files- src/streamlit_app.py +226 -95
src/streamlit_app.py
CHANGED
|
@@ -1,106 +1,237 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# ---------- Custom Professional Colorful CSS ----------
|
| 6 |
st.markdown("""
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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 |
</style>
|
| 51 |
""", unsafe_allow_html=True)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
st.
|
| 57 |
-
st.markdown("
|
| 58 |
-
|
| 59 |
-
st.
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
with col1:
|
| 65 |
-
|
| 66 |
-
"๐ฏ Select Your Fitness Goal",
|
| 67 |
-
["Build Muscle", "Lose Weight", "Improve Endurance"]
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
level = st.radio(
|
| 71 |
-
"๐ Fitness Level",
|
| 72 |
-
["Beginner", "Intermediate", "Advanced"],
|
| 73 |
-
horizontal=True
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
with col2:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
st.
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
st.
|
| 90 |
-
|
| 91 |
-
st.
|
| 92 |
-
|
| 93 |
-
st.
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
else:
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
|
| 4 |
+
# Custom CSS for professional, innovative look
|
|
|
|
|
|
|
| 5 |
st.markdown("""
|
| 6 |
<style>
|
| 7 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
|
| 8 |
+
|
| 9 |
+
.main {
|
| 10 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 11 |
+
padding: 2rem;
|
| 12 |
+
font-family: 'Poppins', sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.stApp {
|
| 16 |
+
background-color: transparent;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
h1 {
|
| 20 |
+
color: white !important;
|
| 21 |
+
font-weight: 700;
|
| 22 |
+
text-align: center;
|
| 23 |
+
text-shadow: 0 4px 8px rgba(0,0,0,0.3);
|
| 24 |
+
margin-bottom: 2rem;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.fitness-card {
|
| 28 |
+
background: rgba(255, 255, 255, 0.95);
|
| 29 |
+
padding: 2rem;
|
| 30 |
+
border-radius: 20px;
|
| 31 |
+
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
| 32 |
+
backdrop-filter: blur(10px);
|
| 33 |
+
border: 1px solid rgba(255,255,255,0.2);
|
| 34 |
+
margin-bottom: 1.5rem;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.stTextInput > div > div > input {
|
| 38 |
+
border-radius: 12px;
|
| 39 |
+
border: 2px solid #e1e5e9;
|
| 40 |
+
padding: 12px 16px;
|
| 41 |
+
font-size: 16px;
|
| 42 |
+
transition: all 0.3s ease;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.stTextInput > div > div > input:focus {
|
| 46 |
+
border-color: #667eea;
|
| 47 |
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.stSelectbox > div > div > select {
|
| 51 |
+
border-radius: 12px;
|
| 52 |
+
border: 2px solid #e1e5e9;
|
| 53 |
+
padding: 12px 16px;
|
| 54 |
+
font-size: 16px;
|
| 55 |
+
transition: all 0.3s ease;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.stSelectbox > div > div > select:focus {
|
| 59 |
+
border-color: #667eea;
|
| 60 |
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.stMultiSelect > div > div {
|
| 64 |
+
border-radius: 12px;
|
| 65 |
+
border: 2px solid #e1e5e9;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.stButton > button {
|
| 69 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 70 |
+
color: white;
|
| 71 |
+
border: none;
|
| 72 |
+
border-radius: 12px;
|
| 73 |
+
padding: 14px 32px;
|
| 74 |
+
font-weight: 600;
|
| 75 |
+
font-size: 16px;
|
| 76 |
+
transition: all 0.3s ease;
|
| 77 |
+
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
|
| 78 |
+
width: 100%;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.stButton > button:hover {
|
| 82 |
+
transform: translateY(-2px);
|
| 83 |
+
box-shadow: 0 12px 35px rgba(102, 126, 234, 0.6);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.bmi-result {
|
| 87 |
+
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
| 88 |
+
color: white;
|
| 89 |
+
padding: 1.5rem;
|
| 90 |
+
border-radius: 20px;
|
| 91 |
+
text-align: center;
|
| 92 |
+
box-shadow: 0 15px 35px rgba(17, 153, 142, 0.4);
|
| 93 |
+
font-size: 1.2rem;
|
| 94 |
+
font-weight: 600;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.bmi-underweight { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); box-shadow: 0 15px 35px rgba(240, 147, 251, 0.4); }
|
| 98 |
+
.bmi-normal { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); box-shadow: 0 15px 35px rgba(79, 172, 254, 0.4); }
|
| 99 |
+
.bmi-overweight { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); box-shadow: 0 15px 35px rgba(250, 112, 154, 0.4); }
|
| 100 |
+
.bmi-obese { background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%); box-shadow: 0 15px 35px rgba(255, 154, 158, 0.4); }
|
| 101 |
+
|
| 102 |
+
.metric-card {
|
| 103 |
+
background: rgba(255, 255, 255, 0.9);
|
| 104 |
+
padding: 1.5rem;
|
| 105 |
+
border-radius: 16px;
|
| 106 |
+
text-align: center;
|
| 107 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
| 108 |
+
margin: 1rem 0;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
.error-message {
|
| 112 |
+
background: #fee;
|
| 113 |
+
color: #c33;
|
| 114 |
+
padding: 1rem;
|
| 115 |
+
border-radius: 12px;
|
| 116 |
+
border-left: 4px solid #c33;
|
| 117 |
+
}
|
| 118 |
</style>
|
| 119 |
""", unsafe_allow_html=True)
|
| 120 |
|
| 121 |
+
st.title("๐ช Fitness Profile Builder")
|
| 122 |
+
|
| 123 |
+
# Sidebar for instructions
|
| 124 |
+
with st.sidebar:
|
| 125 |
+
st.markdown("## ๐ How to Use")
|
| 126 |
+
st.markdown("- Fill in your details")
|
| 127 |
+
st.markdown("- Select your fitness preferences")
|
| 128 |
+
st.markdown("- Click **Calculate BMI**")
|
| 129 |
+
st.markdown("- Get your personalized fitness profile!")
|
| 130 |
+
st.markdown("---")
|
| 131 |
+
st.markdown("*Ready to transform your fitness journey? ๐*")
|
| 132 |
+
|
| 133 |
+
# Initialize session state
|
| 134 |
+
if 'show_result' not in st.session_state:
|
| 135 |
+
st.session_state.show_result = False
|
| 136 |
+
|
| 137 |
+
# Personal Information
|
| 138 |
+
st.markdown('<div class="fitness-card">', unsafe_allow_html=True)
|
| 139 |
+
st.subheader("๐ค Personal Information")
|
| 140 |
+
col1, col2, col3 = st.columns(3)
|
| 141 |
with col1:
|
| 142 |
+
name = st.text_input("Full Name", key="name", help="Enter your full name")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
with col2:
|
| 144 |
+
height_cm = st.number_input("Height (cm)", min_value=0.1, value=170.0, step=0.1, key="height", help="Enter height in centimeters")
|
| 145 |
+
with col3:
|
| 146 |
+
weight_kg = st.number_input("Weight (kg)", min_value=0.1, value=70.0, step=0.1, key="weight", help="Enter weight in kilograms")
|
| 147 |
+
|
| 148 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 149 |
+
|
| 150 |
+
# Fitness Details
|
| 151 |
+
st.markdown('<div class="fitness-card">', unsafe_allow_html=True)
|
| 152 |
+
st.subheader("๐ฏ Fitness Details")
|
| 153 |
+
|
| 154 |
+
col4, col5, col6 = st.columns([1,1,1])
|
| 155 |
+
with col4:
|
| 156 |
+
goal = st.selectbox("Fitness Goal", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"], key="goal")
|
| 157 |
+
with col5:
|
| 158 |
+
fitness_level = st.selectbox("Fitness Level", ["Beginner", "Intermediate", "Advanced"], key="level")
|
| 159 |
+
with col6:
|
| 160 |
+
equipment = st.multiselect("Available Equipment",
|
| 161 |
+
["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment", "Barbell", "Pull-up Bar", "Treadmill"],
|
| 162 |
+
default=["No Equipment"], key="equip")
|
| 163 |
+
|
| 164 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 165 |
+
|
| 166 |
+
# Calculate button
|
| 167 |
+
if st.button("๐งฎ Calculate BMI & Generate Profile", key="calc", help="Click to compute your BMI and view profile"):
|
| 168 |
+
# Validation
|
| 169 |
+
if not name.strip():
|
| 170 |
+
st.error("โ Please enter your name.")
|
| 171 |
+
st.session_state.show_result = False
|
| 172 |
+
elif height_cm <= 0:
|
| 173 |
+
st.error("โ Height must be greater than 0.")
|
| 174 |
+
st.session_state.show_result = False
|
| 175 |
+
elif weight_kg <= 0:
|
| 176 |
+
st.error("โ Weight must be greater than 0.")
|
| 177 |
+
st.session_state.show_result = False
|
| 178 |
else:
|
| 179 |
+
# BMI Calculation
|
| 180 |
+
height_m = height_cm / 100
|
| 181 |
+
bmi = round(weight_kg / (height_m ** 2), 2)
|
| 182 |
+
|
| 183 |
+
# BMI Category
|
| 184 |
+
if bmi < 18.5:
|
| 185 |
+
category = "Underweight"
|
| 186 |
+
category_class = "bmi-underweight"
|
| 187 |
+
elif 18.5 <= bmi < 25:
|
| 188 |
+
category = "Normal"
|
| 189 |
+
category_class = "bmi-normal"
|
| 190 |
+
elif 25 <= bmi < 30:
|
| 191 |
+
category = "Overweight"
|
| 192 |
+
category_class = "bmi-overweight"
|
| 193 |
+
else:
|
| 194 |
+
category = "Obese"
|
| 195 |
+
category_class = "bmi-obese"
|
| 196 |
+
|
| 197 |
+
st.session_state.bmi = bmi
|
| 198 |
+
st.session_state.category = category
|
| 199 |
+
st.session_state.category_class = category_class
|
| 200 |
+
st.session_state.show_result = True
|
| 201 |
+
|
| 202 |
+
# Display Results
|
| 203 |
+
if st.session_state.show_result:
|
| 204 |
+
st.markdown('<div class="fitness-card">', unsafe_allow_html=True)
|
| 205 |
+
st.subheader(f"โ
Profile for {name.title()}")
|
| 206 |
+
|
| 207 |
+
# BMI Result Card
|
| 208 |
+
bmi_html = f'''
|
| 209 |
+
<div class="bmi-result {st.session_state.category_class}">
|
| 210 |
+
<h2 style="margin: 0;">BMI: {st.session_state.bmi}</h2>
|
| 211 |
+
<h3 style="margin: 0 0 1rem 0;">{st.session_state.category}</h3>
|
| 212 |
+
<p>Height: {height_cm} cm | Weight: {weight_kg} kg</p>
|
| 213 |
+
</div>
|
| 214 |
+
'''
|
| 215 |
+
st.markdown(bmi_html, unsafe_allow_html=True)
|
| 216 |
+
|
| 217 |
+
# Summary Cards
|
| 218 |
+
col_a, col_b, col_c = st.columns(3)
|
| 219 |
+
with col_a:
|
| 220 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 221 |
+
st.metric("Goal", goal)
|
| 222 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 223 |
+
with col_b:
|
| 224 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 225 |
+
st.metric("Level", fitness_level)
|
| 226 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 227 |
+
with col_c:
|
| 228 |
+
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
|
| 229 |
+
st.metric("Equipment", ", ".join(equipment))
|
| 230 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 231 |
+
|
| 232 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 233 |
+
|
| 234 |
+
# Footer
|
| 235 |
+
st.markdown("---")
|
| 236 |
+
st.markdown("<p style='text-align: center; color: rgba(255,255,255,0.8); font-size: 0.9rem;'>Deployed on Hugging Face Spaces | Built with โค๏ธ using Streamlit</p>", unsafe_allow_html=True)
|
| 237 |
|
|
|