Module2 / src /streamlit_app.py
js02vel's picture
Update src/streamlit_app.py
7d9664c verified
raw
history blame
4.46 kB
import streamlit as st
# --------------------------------------------------
# Page Configuration
# --------------------------------------------------
st.set_page_config(
page_title="FitPlan AI",
page_icon="πŸ’ͺ",
layout="centered"
)
# --------------------------------------------------
# Custom CSS (Ensuring High Visibility)
# --------------------------------------------------
st.markdown("""
<style>
/* Force a clean, light background for the whole app */
.stApp {
background-color: #F0F2F6;
}
/* Card-style container for the form */
div[data-testid="stForm"] {
background-color: #FFFFFF !important;
padding: 30px !important;
border-radius: 15px !important;
border: 1px solid #E0E0E0 !important;
box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
/* Force all text labels and headers to be Dark Blue/Black */
h1, h2, h3, p, label, .stMarkdown {
color: #1A1C25 !important;
}
/* Style the Input boxes for clarity */
input {
color: #1A1C25 !important;
background-color: #F8F9FA !important;
}
/* Button styling */
.stButton > button {
width: 100%;
background: linear-gradient(90deg, #2563eb, #1d4ed8);
color: white !important;
font-weight: bold;
border: none;
padding: 10px;
border-radius: 8px;
}
</style>
""", unsafe_allow_html=True)
# --------------------------------------------------
# Header
# --------------------------------------------------
st.title("πŸ’ͺ FitPlan AI")
st.markdown("### Milestone 1: Fitness Profile & BMI Analysis")
st.write("Complete your profile below to calculate your health metrics.")
# --------------------------------------------------
# Fitness Profile Form
# --------------------------------------------------
with st.form("fitness_form"):
st.markdown("#### πŸ§β€β™‚οΈ 1. Personal Information")
name = st.text_input("Full Name *", placeholder="e.g. John Doe")
col1, col2 = st.columns(2)
with col1:
# Added min_value logic to prevent negatives
height = st.number_input("Height (cm) *", min_value=0.0, step=1.0, format="%.1f")
with col2:
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1, format="%.1f")
st.markdown("---")
st.markdown("#### πŸ‹οΈ 2. Fitness Details")
goal = st.selectbox(
"Fitness Goal",
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
)
equipment = st.multiselect(
"Available Equipment (Select all that apply)",
["Dumbbells", "Resistance Band", "Yoga Mat", "Kettlebell", "Pull-up Bar", "No Equipment"],
default=["No Equipment"]
)
level = st.radio(
"Fitness Level",
["Beginner", "Intermediate", "Advanced"],
horizontal=True
)
submit = st.form_submit_button("Generate Profile")
# --------------------------------------------------
# Logic & Output
# --------------------------------------------------
if submit:
# Validation checks
if not name.strip():
st.error("🚨 Name is required.")
elif height <= 50 or weight <= 10: # Realistic safety checks
st.error("🚨 Please enter valid height and weight values.")
else:
# BMI Calculation
height_m = height / 100
bmi = weight / (height_m ** 2)
bmi_display = round(bmi, 2)
# Precise BMI Classification
if bmi < 18.5:
category, color, progress = "Underweight", "blue", 0.25
elif 18.5 <= bmi < 25.0:
category, color, progress = "Normal", "green", 0.50
elif 25.0 <= bmi < 30.0:
category, color, progress = "Overweight", "orange", 0.75
else:
category, color, progress = "Obese", "red", 1.0
# Results Display
st.success(f"βœ… Profile generated for {name}")
m_col1, m_col2 = st.columns(2)
with m_col1:
st.metric("Your BMI", f"{bmi_display}")
with m_col2:
# Using bold colored markdown for high visibility
st.markdown(f"**Status:** :{color}[{category}]")
st.markdown("### πŸ“Š BMI Visual Indicator")
st.progress(progress)
# Summary Box
st.info(f"**Profile Summary:**\n\n* **Goal:** {goal}\n* **Experience:** {level}\n* **Equipment:** {', '.join(equipment) if equipment else 'None'}")