Module2 / src /streamlit_app.py
js02vel's picture
Update src/streamlit_app.py
b539384 verified
raw
history blame
3.75 kB
import streamlit as st
# --------------------------------------------------
# Page Configuration
# --------------------------------------------------
st.set_page_config(
page_title="FitPlan AI",
page_icon="πŸ’ͺ",
layout="centered"
)
# --------------------------------------------------
# Custom Styling (HF Compatible)
# --------------------------------------------------
st.markdown("""
<style>
.stApp {
background: linear-gradient(135deg, #e3f2fd, #f8fbff);
}
.block-container {
background-color: white;
padding: 2rem;
border-radius: 15px;
max-width: 850px;
}
.stButton > button {
width: 100%;
height: 3em;
border-radius: 8px;
background-color: #FF4B4B;
color: white;
font-size: 16px;
border: none;
}
</style>
""", unsafe_allow_html=True)
# --------------------------------------------------
# Title Section
# --------------------------------------------------
st.title("πŸ’ͺ FitPlan AI")
st.subheader("Milestone 1: Fitness Profile & BMI Analysis")
st.write("Fill in your details to generate your BMI profile.")
# --------------------------------------------------
# Fitness Profile Form
# --------------------------------------------------
with st.form("fitness_form"):
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,
format="%.2f"
)
with col2:
weight = st.number_input(
"Weight (kg) *",
min_value=0.0,
step=0.1,
format="%.2f"
)
st.divider()
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 Logic
# --------------------------------------------------
if submit:
# -------- Input Validation --------
if not name.strip():
st.error("⚠ Please enter your name.")
elif height <= 0:
st.error("⚠ Height must be greater than 0 cm.")
elif weight <= 0:
st.error("⚠ Weight must be greater than 0 kg.")
else:
# -------- BMI Calculation --------
height_m = height / 100 # Convert cm to meters
bmi = weight / (height_m ** 2)
bmi = round(bmi, 2)
# -------- BMI Classification --------
if bmi < 18.5:
category = "Underweight"
color = "blue"
elif 18.5 <= bmi < 24.9:
category = "Normal"
color = "green"
elif 25 <= bmi < 29.9:
category = "Overweight"
color = "orange"
else:
category = "Obese"
color = "red"
# -------- Display Results --------
st.success(f"βœ… Profile successfully created for {name}!")
colA, colB = st.columns(2)
with colA:
st.metric("Your BMI", bmi)
with colB:
st.markdown(f"**BMI Category:** :{color}[{category}]")
st.info(f"🎯 Goal: {goal} | πŸ“ˆ Level: {level}")
if equipment:
st.write("πŸ‹ Available Equipment:", ", ".join(equipment))
else:
st.write("πŸ‹ Available Equipment: None selected")