Create a command-line personal trainer application using Python and the OpenAI API to provide custom fitness recommendations based on user goals and data.
In this tutorial, you’ll create a command-line personal trainer application leveraging the OpenAI API and Python. You will:
import osimport pandas as pdfrom openai import OpenAI# Initialize the OpenAI client using an environment variableclient = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
$ python3 personal_trainer.pyEnter a health goal (type 'done' when finished): weight lossEnter a health goal (type 'done' when finished): healthier dietEnter a health goal (type 'done' when finished): stress reductionEnter a health goal (type 'done' when finished): donePersonal Trainer Recommendations:• Sleep Duration: Aim for 7–8 hours/night (current average: 6.2h) • Dietary Adjustments: – Reduce simple carbs by 20% – Increase protein at breakfast• Exercise Plan: – 3× weekly circuit training sessions (30 min) – 2× yoga or meditation sessions for stress control• Stress Management: – Implement 5-minute mindfulness breaks every 2 hours – Track HRV trends; maintain ≥50 ms daily