- Load real-world fitness data
- Collect user health goals
- Generate custom, actionable recommendations
Prerequisites
Storing your API key in plaintext is insecure. Use environment variables or a secrets manager instead of hardcoding it in your script.
1. Setup and Imports
Create a file namedpersonal_trainer.py and add:
2. Load Fitness Data
Load your CSV dataset containing sleep, health, and lifestyle metrics. Update the file path as needed:Ensure the CSV file has columns like
sleep_duration, diet_quality, and stress_level for best results.3. Collect User Health Goals
Prompt the user to enter one or more goals. Typedone to finish:
4. Define the Trainer Function
This function builds a chat prompt from user goals and context, then calls the OpenAI chat completion API:API calls may incur costs. Monitor your usage on the OpenAI dashboard.