Module2 / src /streamlit_app.py
js02vel's picture
Update src/streamlit_app.py
8e2b12b verified
raw
history blame
2.87 kB
import streamlit as st
# Page Configuration
st.set_page_config(page_title="FitPlan AI", page_icon="💪", layout="centered")
# Custom Styling
st.markdown("""
<style>
.main {
background-color: #f5f7f9;
}
.stButton>button {
width: 100%;
border-radius: 5px;
height: 3em;
background-color: #FF4B4B;
color: white;
}
</style>
""", unsafe_allow_html=True)
st.title("💪 FitPlan AI")
st.subheader("Milestone 1: Fitness Profile & BMI Analysis")
st.write("Complete the form below to begin your personalized fitness journey.")
# --- Form Section ---
with st.form("fitness_form"):
st.header("1. Personal Information")
name = st.text_input("Full Name*", placeholder="Enter your name")
col1, col2 = st.columns(2)
with col1:
height = st.number_input("Height (cm)*", min_value=0.0, step=0.1, help="e.g., 175")
with col2:
weight = st.number_input("Weight (kg)*", min_value=0.0, step=0.1, help="e.g., 70")
st.divider()
st.header("2. Fitness Details")
goal = st.selectbox("Fitness Goal",
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
level = st.select_slider("Fitness Level",
options=["Beginner", "Intermediate", "Advanced"])
equipment = st.multiselect("Available Equipment",
["Dumbbells", "Resistance Band", "Yoga Mat", "Kettlebell", "Pull-up Bar", "No Equipment"],
default=["No Equipment"])
submit_button = st.form_submit_button("Generate Profile")
# --- Logic & Results ---
if submit_button:
# 5. Input 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:
# 3. Functional Requirements
height_m = height / 100 # Convert cm to meters
bmi = weight / (height_m ** 2)
bmi_rounded = round(bmi, 2)
# Classify BMI
if bmi < 18.5:
category = "Underweight"
color = "blue"
elif 18.5 <= bmi < 24.9:
category = "Normal"
color = "green"
elif 25.0 <= bmi < 29.9:
category = "Overweight"
color = "orange"
else:
category = "Obese"
color = "red"
# 4. Display Results
st.success(f"Profile Created Successfully for **{name}**!")
res_col1, res_col2 = st.columns(2)
with res_col1:
st.metric("Your BMI", bmi_rounded)
with res_col2:
st.markdown(f"**Category:** :{color}[{category}]")
st.info(f"**Goal:** {goal} | **Level:** {level}")
st.write(f"**Equipment:** {', '.join(equipment)}")