Spaces:
Sleeping
Sleeping
| def calculate_bmi(weight, height): | |
| """ | |
| Calculate BMI from weight (kg) and height (cm) | |
| """ | |
| height_m = height / 100 | |
| return weight / (height_m ** 2) | |
| def bmi_category(bmi): | |
| """ | |
| Categorize BMI value | |
| """ | |
| if bmi < 18.5: | |
| return "Underweight" | |
| elif bmi < 25: | |
| return "Normal Weight" | |
| elif bmi < 30: | |
| return "Overweight" | |
| else: | |
| return "Obese" | |
| def build_prompt(name, age, gender, height, weight, goal, fitness_level, equipment): | |
| """ | |
| Build a prompt for the Llama model including all user parameters | |
| Optimized for Llama's instruction-following capabilities | |
| """ | |
| bmi = calculate_bmi(weight, height) | |
| bmi_status = bmi_category(bmi) | |
| equipment_list = ", ".join(equipment) if equipment else "No Equipment" | |
| # Age-specific considerations | |
| age_considerations = "" | |
| if age < 18: | |
| age_considerations = "\nImportant: User is under 18. Focus on proper form and bodyweight exercises. Avoid heavy lifting." | |
| elif age > 50: | |
| age_considerations = "\nImportant: User is over 50. Focus on joint-friendly exercises, mobility work, and lower impact activities." | |
| # Goal-specific instructions | |
| goal_instructions = { | |
| "Weight Loss": "Focus on compound exercises and include cardio intervals. Higher reps (12-15) with moderate weight.", | |
| "Build Muscle": "Focus on hypertrophy with moderate weights (8-12 reps). Include progressive overload and mind-muscle connection.", | |
| "Strength Gain": "Focus on lower reps (5-8) with heavier weights. Include compound lifts like squats, deadlifts, bench press.", | |
| "Abs Building": "Include core-specific exercises along with full-body compound movements. Focus on controlled movements.", | |
| "Flexibility": "Include dynamic stretching, yoga poses, and mobility work. Hold stretches for 20-30 seconds." | |
| } | |
| specific_instruction = goal_instructions.get(goal, "Balance cardio and strength training.") | |
| # Llama-optimized prompt structure | |
| prompt = f"""<s>[INST] <<SYS>> | |
| You are a certified professional fitness trainer. Create a detailed, safe, and effective 5-day workout plan based on the user's profile below. | |
| <</SYS>> | |
| USER PROFILE: | |
| - Name: {name} | |
| - Age: {age} years | |
| - Gender: {gender} | |
| - Height: {height} cm | |
| - Weight: {weight} kg | |
| - BMI: {bmi:.2f} ({bmi_status}) | |
| - Primary Goal: {goal} | |
| - Fitness Level: {fitness_level} | |
| - Available Equipment: {equipment_list} | |
| {age_considerations} | |
| SPECIFIC FOCUS: {specific_instruction} | |
| REQUIREMENTS: | |
| 1. Create a COMPLETE 5-day workout plan with clear "DAY 1", "DAY 2", "DAY 3", "DAY 4", and "DAY 5" headers | |
| 2. For each day, include: | |
| - A warm-up section (5-10 minutes) | |
| - 4-6 main exercises | |
| - A cool-down/stretch section | |
| 3. For EACH exercise, specify: | |
| - Exercise name | |
| - Sets x Reps (e.g., "3 x 12") | |
| - Rest period between sets | |
| 4. Adjust intensity based on BMI category ({bmi_status}) and fitness level ({fitness_level}) | |
| 5. Ensure all exercises are safe and can be done with available equipment: {equipment_list} | |
| 6. If equipment is limited, provide bodyweight alternatives | |
| Please provide a well-structured, easy-to-follow 5-day workout plan. [/INST] | |
| Here is a comprehensive 5-day workout plan for {name}:</s> | |
| """ | |
| return prompt, bmi, bmi_status | |
| def build_fitness_assistant_prompt(name, age, gender, height, weight, goal, fitness_level, equipment): | |
| """ | |
| Alternative prompt optimized for the fitness-specific fine-tuned model | |
| """ | |
| bmi = calculate_bmi(weight, height) | |
| bmi_status = bmi_category(bmi) | |
| equipment_list = ", ".join(equipment) if equipment else "No Equipment" | |
| prompt = f"""Create a 5-day workout plan for: | |
| Name: {name} | |
| Age: {age} | |
| Gender: {gender} | |
| Height: {height}cm | |
| Weight: {weight}kg | |
| BMI: {bmi:.1f} ({bmi_status}) | |
| Goal: {goal} | |
| Level: {fitness_level} | |
| Equipment: {equipment_list} | |
| Requirements: | |
| - 5 days (Day 1 to Day 5) | |
| - Each day: warm-up, 4-6 exercises, cool-down | |
| - Each exercise: name, sets, reps, rest | |
| - Safe for {fitness_level} level | |
| - Use available equipment only | |
| Plan:""" | |
| return prompt, bmi, bmi_status |