import streamlit as st from transformers import AutoTokenizer, AutoModelForSeq2SeqLM import torch # 1. Basic Configuration st.set_page_config(page_title="FitPlan AI", page_icon="💪", 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() generator = load_model() # 2. Enhanced CSS st.markdown(""" """, unsafe_allow_html=True) # -------------------------------------------------- # UI Header Section # -------------------------------------------------- st.markdown('

💪 FitPlan AI

', unsafe_allow_html=True) st.markdown('

Your personalized gym companion

', unsafe_allow_html=True) # -------------------------------------------------- # Fitness Profile Form # -------------------------------------------------- with st.form("fitness_form", clear_on_submit=False): st.markdown('

🧍‍♂️ 1. PERSONAL INFORMATION

', unsafe_allow_html=True) name = st.text_input("Full Name *", placeholder="Enter your full name") col1, col2 = st.columns(2) with col1: height = st.number_input("Height (cm) *", min_value=0.0, step=1.0, value=0.0) with col2: weight = st.number_input("Weight (kg) *", min_value=0.0, step=0.1, value=0.0) st.markdown("
", unsafe_allow_html=True) st.markdown('

🏋️ 2. FITNESS DETAILS

', unsafe_allow_html=True) 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"], default=["No Equipment"]) level = st.radio("Fitness Level", ["Beginner", "Intermediate", "Advanced"], horizontal=True) # SUBMIT BUTTON if st.button(" Submit Profile"): if not name: st.error("Please enter your name.") elif height <= 0 or weight <= 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""" You are a certified professional fitness trainer. Create a detailed 5-day workout plan. User Information: - Gender: {gender} - BMI: {bmi:.2f} ({bmi_status}) - Goal: {goal} - Fitness Level: {fitness_level} - Equipment Available: {equipment_list} Start directly with: Day 1: """ with st.spinner("Generating your AI workout plan..."): inputs = tokenizer(prompt, return_tensors="pt", truncation=True) outputs = model.generate( **inputs, max_new_tokens=900, temperature=0.7, do_sample=True ) result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip() st.subheader(" Your Personalized Workout Plan") st.write(result)