Module2 / src /streamlit_app.py
js02vel's picture
Update src/streamlit_app.py
074cc6d verified
raw
history blame
4.62 kB
import streamlit as st
# --------------------------------------------------
# Page Configuration
# --------------------------------------------------
st.set_page_config(
page_title="FitPlan AI",
page_icon="πŸ’ͺ",
layout="centered"
)
# --------------------------------------------------
# Custom CSS (HF Compatible + Visible UI)
# --------------------------------------------------
st.markdown("""
<style>
/* Page background */
.stApp {
background-color: #f4f7fb;
}
/* Main container */
.block-container {
background-color: #ffffff;
padding: 2.5rem;
border-radius: 18px;
max-width: 900px;
}
/* Headings */
h1, h2, h3 {
color: #0f172a !important;
}
/* Labels */
label {
color: #1e293b !important;
font-weight: 600;
}
/* Inputs */
input, textarea {
background-color: #ffffff !important;
color: #0f172a !important;
border-radius: 10px !important;
border: 1px solid #cbd5e1 !important;
}
/* Selectbox & Multiselect */
div[data-baseweb="select"] {
background-color: #ffffff !important;
border-radius: 10px;
}
/* Form card */
div[data-testid="stForm"] {
background-color: #f8fafc;
padding: 2rem;
border-radius: 14px;
box-shadow: 0 10px 25px rgba(0,0,0,0.08);
}
/* Main button */
.stButton > button {
width: 100%;
height: 3.2em;
border-radius: 10px;
background: linear-gradient(90deg, #2563eb, #1d4ed8);
color: white !important;
font-size: 17px;
font-weight: 600;
border: none;
}
</style>
""", unsafe_allow_html=True)
# --------------------------------------------------
# Title Section
# --------------------------------------------------
st.title("πŸ’ͺ FitPlan AI")
st.subheader("Milestone 1: Fitness Profile & BMI Analysis")
st.write("Enter your details to calculate BMI and generate your fitness profile.")
# --------------------------------------------------
# Fitness Profile Form
# --------------------------------------------------
with st.form("fitness_form"):
# -------- Section 1 --------
st.header("πŸ§β€β™‚οΈ 1. Personal Information")
name = st.text_input("Full Name *")
col1, col2 = st.columns(2)
with col1:
height = st.number_input("Height (cm) *", min_value=0.0, step=0.1)
with col2:
weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1)
st.divider()
# -------- Section 2 --------
st.header("πŸ‹οΈ 2. Fitness Details")
goal = st.selectbox(
"Fitness Goal",
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
)
equipment = st.multiselect(
"Available Equipment",
["Dumbbells", "Resistance Band", "Yoga Mat",
"Kettlebell", "Pull-up Bar", "No Equipment"]
)
level = st.radio(
"Fitness Level",
["Beginner", "Intermediate", "Advanced"]
)
submit = st.form_submit_button("Generate Profile")
# --------------------------------------------------
# Processing & Output
# --------------------------------------------------
if submit:
# -------- Validation --------
if not name.strip():
st.error("⚠ Please enter your name.")
elif height <= 0 or weight <= 0:
st.error("⚠ Height and weight must be greater than zero.")
else:
# -------- BMI Calculation --------
height_m = height / 100
bmi = round(weight / (height_m ** 2), 2)
# -------- BMI Classification --------
if bmi < 18.5:
category = "Underweight"
color = "blue"
progress = bmi / 18.5
elif 18.5 <= bmi < 24.9:
category = "Normal"
color = "green"
progress = bmi / 24.9
elif 25 <= bmi < 29.9:
category = "Overweight"
color = "orange"
progress = bmi / 29.9
else:
category = "Obese"
color = "red"
progress = 1.0
# -------- Results Section --------
st.success(f"βœ… Profile created successfully for **{name}**")
colA, colB = st.columns(2)
with colA:
st.metric("Your BMI", bmi)
with colB:
st.markdown(f"**BMI Category:** :{color}[{category}]")
# -------- BMI Progress Bar --------
st.markdown("### πŸ“Š BMI Progress Indicator")
st.progress(min(progress, 1.0))
# -------- Summary --------
st.info(f"🎯 Goal: {goal} | πŸ“ˆ Level: {level}")
if equipment:
st.write("🧰 Equipment:", ", ".join(equipment))
else:
st.write("🧰 Equipment: No equipment selected")