Spaces:
Sleeping
Sleeping
File size: 4,401 Bytes
176b1d7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch
# 1. Page Configuration
st.set_page_config(page_title="PERSONALIZED FITPLAN", layout="centered")
def load_model():
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
return tokenizer, model
tokenizer, model = load_model()
def bmi_category(bmi):
if bmi < 18.5:
return "Underweight"
elif 18.5 <= bmi < 24.9:
return "Normal"
elif 25 <= bmi < 29.9:
return "Overweight"
else:
return "Obese"
# 2. Clean Styling
st.markdown("""
<style>
.stApp {
background: linear-gradient(rgba(0,0,0,0.85), rgba(0,0,0,0.85)),
url("https://images.unsplash.com/photo-1534438327276-14e5300c3a48?q=80&w=2070");
background-size: cover;
}
h1, h2, h3, label, p, span, .stMarkdown {
color: #FFFFFF !important;
font-weight: 900 !important;
}
</style>
""", unsafe_allow_html=True)
# 3. Header
st.title("๐๏ธ PERSONALIZED FITPLAN")
st.markdown("---")
# 4. Athlete Profile Form
st.header("Athlete Profile")
col1, col2 = st.columns(2)
with col1:
name = st.text_input("NAME (Required)")
gender = st.selectbox("GENDER", ["Male", "Female", "Other"])
height_cm = st.number_input("HEIGHT (CM) (Required)", min_value=0.0, step=0.1)
with col2:
weight_kg = st.number_input("WEIGHT (KG) (Required)", min_value=0.0, step=0.1)
goal = st.selectbox("FITNESS GOAL", ["Build Muscle", "Weight Loss", "Strength Gain", "Abs Building", "Flexible"])
level = st.selectbox("FITNESS LEVEL", ["Beginner", "Intermediate", "Advanced"])
equipment_options = [
"Dumbbells", "Barbell", "Kettlebells", "Weight Plates",
"Resistance Band", "Yoga Mat", "Pull-up Bar", "Bench Press", "No Equipment"
]
equipment = st.multiselect("AVAILABLE EQUIPMENT", equipment_options)
st.markdown("---")
# 5. Logic and Results
if st.button(" Submit Profile"):
if not name:
st.error("Please enter your name.")
# ๐ง FIXED VARIABLES
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 CALCULATION (missing earlier)
height_m = height_cm / 100
bmi = weight_kg / (height_m ** 2)
bmi_status = bmi_category(bmi)
equipment_list = ", ".join(equipment)
prompt = f"""
You are a certified professional gym trainer.
Generate a COMPLETE 5-day workout schedule.
FORMAT:
Day 1:
Warm-up:
-
Workout:
-
Rest:
Day 2:
Warm-up:
-
Workout:
-
Rest:
Day 3:
Warm-up:
-
Workout:
-
Rest:
Day 4:
Warm-up:
-
Workout:
-
Rest:
Day 5:
Warm-up:
-
Workout:
-
Rest:
User Details:
Gender: {gender}
BMI: {bmi:.2f} ({bmi_status})
Goal: {goal}
Fitness Level: {level}
Available Equipment: {equipment_list}
Generate the full 5-day workout plan.
"""
with st.spinner("Generating your AI workout plan..."):
inputs = tokenizer(prompt, return_tensors="pt", truncation=True)
outputs = model.generate(
**inputs,
max_new_tokens=600,
temperature=0.3,
do_sample=False
)
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
st.subheader(" Your Personalized Workout Plan")
st.write(result)
# Validation block (unchanged)
if not name or height_cm <= 0 or weight_kg <= 0:
st.error("๐จ VALIDATION FAILED: PLEASE PROVIDE NAME, HEIGHT, AND WEIGHT.")
else:
height_m = height_cm / 100
bmi_val = round(weight_kg / (height_m ** 2), 2)
if bmi_val < 18.5: category = "Underweight"
elif 18.5 <= bmi_val < 24.9: category = "Normal"
elif 25 <= bmi_val < 29.9: category = "Overweight"
else: category = "Obese"
st.success(f"PROFILE SUBMITTED SUCCESSFULLY! HELLO {name.upper()}")
st.markdown(f"### BMI: {bmi_val} | CATEGORY: {category.upper()}")
athlete_data = {
"Name": name,
"Gender": gender,
"BMI": bmi_val,
"Goal": goal,
"Fitness Level": level,
"Equipment": equipment
}
st.json(athlete_data)
|