| import streamlit as st |
| from transformers import pipeline |
|
|
| |
| |
| |
| st.set_page_config( |
| page_title="Fitness Profile", |
| page_icon="🏋️", |
| layout="centered" |
| ) |
|
|
| |
| |
| |
| @st.cache_resource |
| def load_model(): |
| return pipeline( |
| "text-generation", |
| model="google/flan-t5-base" |
| ) |
|
|
| generator = load_model() |
|
|
| st.title("🏋️ Personalized Fitness Profile") |
| st.markdown("---") |
|
|
| |
| |
| |
| st.header("1. Personal Information") |
|
|
| name = st.text_input("Name *") |
|
|
| gender = st.selectbox( |
| "Gender *", |
| ["Male", "Female"] |
| ) |
|
|
| height_cm = st.number_input( |
| "Height (in centimeters) *", |
| min_value=0.0, |
| format="%.2f" |
| ) |
|
|
| weight_kg = st.number_input( |
| "Weight (in kilograms) *", |
| min_value=0.0, |
| format="%.2f" |
| ) |
|
|
| |
| |
| |
| |
| |
| |
| def calculate_bmi(height_cm, weight_kg): |
| if height_cm > 0 and weight_kg > 0: |
| height_m = height_cm / 100 |
| return weight_kg / (height_m ** 2) |
| return 0 |
|
|
| def bmi_category(bmi): |
| if bmi < 18.5: |
| return "Underweight" |
| elif 18.5 <= bmi < 25: |
| return "Normal weight" |
| elif 25 <= bmi < 30: |
| return "Overweight" |
| else: |
| return "Obese" |
|
|
| |
| bmi = 0 |
| if height_cm > 0 and weight_kg > 0: |
| bmi = calculate_bmi(height_cm, weight_kg) |
| st.info(f"Your BMI is: {bmi:.2f} ({bmi_category(bmi)})") |
|
|
|
|
| |
| |
| |
| st.header("2. Fitness Details") |
|
|
| fitness_goal = st.selectbox( |
| "Fitness Goal", |
| ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"] |
| ) |
|
|
| equipment = st.multiselect( |
| "Available Equipment (Multiple selection allowed)", |
| ["Dumbbells", "Resistance Band", "Yoga Mat", "No Equipment"] |
| ) |
|
|
| fitness_level = st.radio( |
| "Fitness Level", |
| ["Beginner", "Intermediate", "Advanced"], |
| horizontal=True |
| ) |
|
|
| st.markdown("---") |
|
|
| |
| |
| |
| if st.button("Submit Profile"): |
|
|
| if not name: |
| st.error("Please enter your name.") |
|
|
| elif height_cm <= 0 or weight_kg <= 0: |
| st.error("Please enter valid height and weight.") |
|
|
| elif not equipment: |
| st.error("Please select at least one equipment option.") |
|
|
| else: |
| st.success("✅ Profile Submitted Successfully!") |
|
|
| bmi_status = bmi_category(bmi) |
| equipment_list = ", ".join(equipment) |
|
|
| prompt = f""" |
| Generate a 5-day structured workout plan. |
| |
| User Details: |
| Name: {name} |
| Gender: {gender} |
| BMI: {bmi:.2f} ({bmi_status}) |
| Goal: {fitness_goal} |
| Fitness Level: {fitness_level} |
| Available Equipment: {equipment_list} |
| |
| Requirements: |
| - Include warmup |
| - Include exercises with sets and reps |
| - Include rest time |
| - Adjust intensity based on BMI and fitness level |
| - Keep it structured day-wise |
| """ |
|
|
| with st.spinner("Generating your AI workout plan..."): |
| result = generator( |
| prompt, |
| max_new_tokens=400, |
| do_sample=True, |
| temperature=0.7 |
| )[0]["generated_text"] |
|
|
| st.subheader("🏋️ Your Personalized Workout Plan") |
| st.write(result) |
|
|