Skip to content

02aliabbas02/personalised_workout_planner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Fitness Planner

Personalized Workout AI with 1,500+ Exercises & Natural Language Interface

An intelligent fitness planning system that generates personalized workout routines using machine learning, trained on 57,861 real workout records with 80.37% prediction accuracy.

✨ Features

  • 🎯 Personalized Workouts: ML-powered recommendations based on goals, experience, and equipment
  • οΏ½ Natural Language Interface: "28 year old male, muscle gain, gym access, 4 days per week"
  • πŸ’ͺ 1,500+ Exercise Database: Comprehensive exercise library with equipment variations
  • οΏ½ Multi-Output Prediction: Sets, reps, intensity, weight, and RPE in one model
  • οΏ½ Safety First: Expert rules and constraints for injury prevention
  • ⚑ Fast API: RESTful API with <50ms response times
  • 🌐 CORS Ready: Easy integration with web/mobile applications
  • 🚫 No API Keys Required: Works completely offline with intelligent systems

πŸš€ Quick Start

Installation

  1. Clone the repository:
git clone <repository-url>
cd personal_fitness_ai
  1. Create a virtual environment:
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Train the model (required first time):
python train_model.py

Note: The model file (219MB) is excluded from GitHub due to size limits. This step recreates it locally.

  1. Start the API server:
python api_server.py

The server will start at http://localhost:8000

πŸ“Š Model Performance

Metric Score Description
Overall RΒ² 80.37% Excellent variance explanation
Weight Prediction 93.82% Near-perfect weight progression
Intensity Prediction 91.12% Superior intensity targeting
Reps Prediction 84.01% Strong rep range optimization
RPE Prediction 77.98% Good subjective measure accuracy

Practical Accuracy

  • 95.3% within Β±1 set (excellent for training)
  • 94.1% within Β±3 reps (highly practical)
  • 99.9% within Β±10% intensity (outstanding)

The model achieves human-level consistency with superior reliability.

Quick Test

curl -X POST "http://localhost:8000/plan" \
  -H "Content-Type: application/json" \
  -d '{"message": "25 year old female, weight loss, home workout, 3 days per week"}'

πŸ“– API Documentation

Base URL

http://localhost:8000

Endpoints

POST /plan - Generate Fitness Plan

Creates a personalized workout plan from natural language input.

Request:

{
  "message": "28 year old male, muscle gain, gym access, 4 days per week",
  "weeks": 4,
  "use_natural_language": true
}

Response:

{
  "plan": "Here's your 4-week workout plan! As a 28-year-old male focused on muscle gain...",
  "profile": {
    "Age": 28,
    "Gender": "Male",
    "Goal": "Muscle Gain",
    "Fitness_Level": "Intermediate",
    "Days_per_Week": 4,
    "Equipment": "Gym",
    "Body_Type": "Mesomorph",
    "Injuries": []
  },
  "source": "expert_rules",
  "structured_data": null
}

POST /parse - Parse Natural Language

Extracts structured profile data from natural language.

Request:

{
  "message": "30 year old female, wants to lose weight, 3 days per week, has knee injury"
}

Response:

{
  "profile": {
    "Age": 30,
    "Gender": "Female",
    "Goal": "Weight Loss",
    "Fitness_Level": "Intermediate",
    "Days_per_Week": 3,
    "Equipment": "Gym",
    "Body_Type": "Mesomorph",
    "Injuries": ["knee"]
  }
}

GET /health - Health Check

Returns system status and component availability.

GET / - API Info

Basic API information and version.

Interactive Documentation

Visit http://localhost:8000/docs for interactive API documentation powered by Swagger UI.

🎯 Usage Examples

Basic Muscle Building Plan

import requests

response = requests.post("http://localhost:8000/plan", json={
    "message": "22 year old male, wants to build muscle, gym access, 4 days per week",
    "weeks": 6
})
plan = response.json()
print(plan["plan"])

Home Workout for Weight Loss

response = requests.post("http://localhost:8000/plan", json={
    "message": "35 year old female, weight loss, home workouts only, 3 days per week",
    "weeks": 4
})

Injury-Adapted Workout

response = requests.post("http://localhost:8000/plan", json={
    "message": "40 year old male, strength training, gym access, has back injury, 3 days per week"
})

🧠 How It Works

1. Natural Language Processing

  • Extracts age, gender, goals, equipment, training frequency
  • Identifies injuries and physical limitations
  • Maps to structured profile format

2. Machine Learning Predictions

  • Uses trained Random Forest models (RΒ² 0.44-0.92 performance)
  • Predicts optimal sets, reps, and intensity for each exercise
  • Based on 57,000+ real workout records

3. Expert Rules Engine

  • Equipment Substitution: Replaces unavailable exercises
  • Injury Safety: Avoids contraindicated movements
  • Progressive Overload: Increases volume and intensity over time
  • Smart Scheduling: Distributes exercises across training days

4. Exercise Database

  • 1,500+ exercises from comprehensive fitness database
  • Categorized by muscle groups, equipment, and difficulty
  • Includes bodyweight, dumbbell, barbell, machine, and cable exercises

πŸ—‚οΈ Project Structure

personal_fitness_ai/
β”œβ”€β”€ api_server.py              # FastAPI server and main endpoints
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ README.md                  # This file
β”œβ”€β”€ start.sh                   # Easy startup script
β”œβ”€β”€ test_api.py               # API test suite
β”œβ”€β”€ .gitignore                # Git ignore patterns
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ exercises.json         # 1,500+ exercise database
β”‚   β”œβ”€β”€ workout_comprehensive.csv # Training data (57K+ records)
β”‚   β”œβ”€β”€ muscles.json          # Muscle group mappings
β”‚   β”œβ”€β”€ bodyparts.json        # Body part categories
β”‚   └── equipments.json       # Equipment types
└── model/
    β”œβ”€β”€ predict_sets.py       # ML prediction engine
    β”œβ”€β”€ nl_parser.py          # Natural language processing
    β”œβ”€β”€ llm_planner.py        # Workout plan generation
    β”œβ”€β”€ expert_rules.py       # Safety rules and substitutions
    β”œβ”€β”€ comprehensive_model.pkl # Trained ML model
    └── model_info.json       # Model metadata

πŸš€ Integration Examples

JavaScript/React

const generateWorkout = async (userMessage) => {
  const response = await fetch('http://localhost:8000/plan', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      message: userMessage,
      weeks: 4,
      use_natural_language: true
    })
  });
  const data = await response.json();
  return data.plan;
};

// Usage
const plan = await generateWorkout("25 year old, wants to get fit, 3 days per week");

Python Client

import requests

class FitnessPlanner:
    def __init__(self, base_url="http://localhost:8000"):
        self.base_url = base_url
    
    def create_plan(self, message, weeks=4):
        response = requests.post(f"{self.base_url}/plan", json={
            "message": message,
            "weeks": weeks,
            "use_natural_language": True
        })
        return response.json()
    
    def parse_profile(self, message):
        response = requests.post(f"{self.base_url}/parse", json={
            "message": message
        })
        return response.json()

# Usage
planner = FitnessPlanner()
plan = planner.create_plan("30 year old, muscle building, 4 days per week")

Mobile App Integration

// Flutter/Dart example
Future<Map<String, dynamic>> generateWorkoutPlan(String userInput) async {
  final response = await http.post(
    Uri.parse('http://localhost:8000/plan'),
    headers: {'Content-Type': 'application/json'},
    body: json.encode({
      'message': userInput,
      'weeks': 4,
      'use_natural_language': true,
    }),
  );
  return json.decode(response.body);
}

πŸ§ͺ Development

Running Tests

# Install test dependencies if needed
pip install requests

# Run the test suite
python test_api.py

Adding Custom Exercises

  1. Edit data/exercises.json
  2. Follow the existing format:
{
  "name": "Custom Exercise",
  "targetMuscles": ["chest", "triceps"],
  "equipments": ["dumbbell"],
  "bodyParts": ["upper body"],
  "category": "strength"
}

Retraining Models

# Update training data in data/workout_comprehensive.csv
# Run model training
python -c "from model.predict_sets import ComprehensiveFitnessPredictor; ComprehensiveFitnessPredictor().train_model()"

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Exercise database sourced from comprehensive fitness resources
  • ML models trained on anonymized workout data
  • Built with FastAPI, scikit-learn, and modern Python stack

πŸ“ž Support

  • Create an issue for bug reports or feature requests
  • Check the API documentation at /docs endpoint
  • Review example integrations in this README

Ready to revolutionize fitness planning? πŸš€

Start the server with python api_server.py and send your first natural language workout request!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors