Module_2 / app.py
srbhavya01's picture
Update app.py
451c68f verified
raw
history blame
2.72 kB
import streamlit as st
# -------------------------
# Page Config
# -------------------------
st.set_page_config(page_title="FitPlan AI", page_icon="💪")
st.title("💪 FitPlan AI — Personalized Workout Generator")
# -------------------------
# BMI Functions
# -------------------------
def calculate_bmi(weight, height):
height_m = height / 100
return weight / (height_m ** 2)
def bmi_category(bmi):
if bmi < 18.5:
return "Underweight"
elif bmi < 25:
return "Normal Weight"
elif bmi < 30:
return "Overweight"
else:
return "Obese"
# -------------------------
# Prompt Builder Function
# -------------------------
def build_prompt(name, gender, height, weight, goal, fitness_level, equipment):
bmi = calculate_bmi(weight, height)
bmi_status = bmi_category(bmi)
equipment_list = ", ".join(equipment) if equipment else "No Equipment"
prompt = f"""
You are a certified professional fitness trainer.
Create a STRICTLY FORMATTED 5-day personalized workout plan.
User Profile:
Name: {name}
Gender: {gender}
Height: {height} cm
Weight: {weight} kg
BMI: {bmi:.2f} ({bmi_status})
Goal: {goal}
Fitness Level: {fitness_level}
Available Equipment: {equipment_list}
Instructions:
• Divide into Day 1 to Day 5
• Include Warm-up
• Include Exercises with Sets × Reps
• Include Rest Time
• Adjust intensity based on BMI
"""
return prompt, bmi, bmi_status
# -------------------------
# User Inputs
# -------------------------
name = st.text_input("Enter Your Name")
gender = st.selectbox("Gender", ["Male", "Female", "Other"])
height = st.number_input("Height (cm)", min_value=0.0)
weight = st.number_input("Weight (kg)", min_value=0.0)
goal = st.selectbox(
"Fitness Goal",
["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"]
)
equipment = st.multiselect(
"Available Equipment",
["Dumbbells", "Resistance Band", "Yoga Mat", "Skipping Rope",
"Weight Plates", "Cycling", "Inclined Bench", "Pullups Bar", "No Equipment"]
)
fitness_level = st.radio(
"Fitness Level",
["Beginner", "Intermediate", "Advanced"]
)
# -------------------------
# Generate Plan
# -------------------------
if st.button("Generate Workout Plan"):
if not name or height <= 0 or weight <= 0:
st.error("Please fill all required fields")
else:
prompt, bmi, bmi_status = build_prompt(
name, gender, height, weight,
goal, fitness_level, equipment
)
st.success(f"BMI: {bmi:.2f} ({bmi_status})")
with st.spinner("Generating your personalized workout plan..."):
st.subheader("🏋️ Your Workout Plan")
st.write(result)