Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| import torch | |
| st.set_page_config(page_title="FitPlan AI", layout="centered") | |
| # LOAD MODEL (FIXED FOR FLAN-T5) | |
| 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() | |
| # --------------------------------------------------- | |
| # TITLE | |
| # --------------------------------------------------- | |
| st.title("πͺ FitPlan AI β User Fitness Profile") | |
| # --------------------------------------------------- | |
| # PERSONAL INFORMATION | |
| # --------------------------------------------------- | |
| st.subheader("π€ Personal Information") | |
| name = st.text_input("Enter Your Name") | |
| gender = st.radio( | |
| "Gender", | |
| ["Male", "Female"], | |
| horizontal=True | |
| ) | |
| # --------------------------------------------------- | |
| # HEIGHT & WEIGHT | |
| # --------------------------------------------------- | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| height = st.number_input( | |
| "Height (in cm)", | |
| min_value=0.0, | |
| max_value=250.0, | |
| value=0.0, | |
| step=0.1 | |
| ) | |
| with col2: | |
| weight = st.number_input( | |
| "Weight (in kg)", | |
| min_value=0.0, | |
| max_value=200.0, | |
| value=0.0, | |
| step=0.1 | |
| ) | |
| # --------------------------------------------------- | |
| # BMI FUNCTION | |
| # --------------------------------------------------- | |
| def bmi_category(bmi): | |
| if bmi < 18.5: | |
| return "Underweight" | |
| elif bmi < 25: | |
| return "Normal weight" | |
| elif bmi < 30: | |
| return "Overweight" | |
| else: | |
| return "Obese" | |
| # --------------------------------------------------- | |
| # BMI CALCULATION | |
| # --------------------------------------------------- | |
| bmi = None | |
| if height > 0 and weight > 0: | |
| height_m = height / 100 | |
| bmi = weight / (height_m ** 2) | |
| st.metric("π Your BMI", f"{bmi:.2f}") | |
| st.info(f"BMI Category: {bmi_category(bmi)}") | |
| # --------------------------------------------------- | |
| # FITNESS GOAL | |
| # --------------------------------------------------- | |
| st.subheader("π― Fitness Goal") | |
| goal = st.selectbox( | |
| "Select Your Goal", | |
| [ | |
| "Flexible", | |
| "Weight Loss", | |
| "Build Muscle", | |
| "Strength Gaining", | |
| "Abs Building" | |
| ] | |
| ) | |
| # --------------------------------------------------- | |
| # EQUIPMENT | |
| # --------------------------------------------------- | |
| st.subheader("ποΈ Available Equipment") | |
| equipment_map = {} | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| equipment_map["No Equipment"] = st.checkbox("No Equipment") | |
| equipment_map["Pull-up Bar"] = st.checkbox("Pull-up Bar") | |
| equipment_map["Dip Bars"] = st.checkbox("Dip Bars") | |
| equipment_map["Push-up Handles"] = st.checkbox("Push-up Handles") | |
| equipment_map["Dumbbells"] = st.checkbox("Dumbbells") | |
| equipment_map["Adjustable Dumbbells"] = st.checkbox("Adjustable Dumbbells") | |
| with col2: | |
| equipment_map["Barbell"] = st.checkbox("Barbell") | |
| equipment_map["Weight Plates"] = st.checkbox("Weight Plates") | |
| equipment_map["Kettlebells"] = st.checkbox("Kettlebells") | |
| equipment_map["Medicine Ball"] = st.checkbox("Medicine Ball") | |
| equipment_map["Yoga Mat"] = st.checkbox("Yoga Mat") | |
| equipment_map["Resistance Band"] = st.checkbox("Resistance Band") | |
| with col3: | |
| equipment_map["Bosu Ball"] = st.checkbox("Bosu Ball") | |
| equipment_map["Stability Ball"] = st.checkbox("Stability Ball") | |
| equipment_map["Foam Roller"] = st.checkbox("Foam Roller") | |
| equipment_map["Treadmill"] = st.checkbox("Treadmill") | |
| equipment_map["Exercise Bike"] = st.checkbox("Exercise Bike") | |
| equipment_map["Skipping Rope"] = st.checkbox("Skipping Rope") | |
| equipment = [item for item, selected in equipment_map.items() if selected] | |
| # --------------------------------------------------- | |
| # FITNESS LEVEL | |
| # --------------------------------------------------- | |
| st.subheader("π Fitness Level") | |
| fitness_level = st.radio( | |
| "Select 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) | |
| # Improved Prompt | |
| 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=400, | |
| temperature=0.7, | |
| do_sample=True | |
| ) | |
| result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip() | |