An AI-powered fitness assistant that generates personalized workout and diet plans using Google Gemini AI.
- π― Personalized Plans - AI-generated workout and diet plans tailored to your goals
- π Voice Features - Text-to-speech for plans and voice input for modifications
- πΌοΈ Image Generation - View exercise and meal images
- π PDF Export - Download your complete plan
- π Plan Modification - Request changes using text or voice (fixed at bottom)
- π Dark Mode - Toggle between light and dark themes
-
Install dependencies
npm install
-
Set up environment variables
Create
.env.localfile:GOOGLE_GENERATIVE_AI_API_KEY=your_google_api_key_here UNSPLASH_ACCESS_KEY=your_unsplash_key_here # Optional ELEVENLABS_API_KEY=your_elevenlabs_key_here # Optional
-
Run the app
npm run dev
- Google Gemini (Required): Get free key
- Unsplash (Optional): Get key
- ElevenLabs (Optional): Get key
Why Netlify?
- Better timeout limits: 26 seconds on Pro, 10 seconds on Free (vs Vercel's 25s edge limit)
- Background functions: Up to 15 minutes for long-running tasks!
- Free tier friendly: Perfect for Gemini API which takes 20-30 seconds
Steps:
- Push your code to GitHub
- Go to Netlify
- Click "Add new site" β "Import an existing project"
- Connect your GitHub repository
- Add environment variables in Netlify dashboard:
GOOGLE_GENERATIVE_AI_API_KEYUNSPLASH_ACCESS_KEY(optional)
- Deploy! Netlify will auto-detect Next.js
- Push to GitHub
- Import project in Vercel
- Add environment variables
- Deploy
Consider upgrading to Vercel Pro ($20/month) for 60-second timeouts if needed.
- Next.js 16 (App Router)
- React 19
- TypeScript
- Tailwind CSS v4
- Google Gemini 1.5 Flash (AI)
- Zustand (State Management)
- Unsplash API (Images)
ai_trainer/
βββ app/
β βββ api/
β β βββ generate-plan/ # AI plan generation endpoint
β β βββ generate-image/ # AI image generation endpoint
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Main application page
βββ components/
β βββ DietPlanDisplay.tsx # Diet plan UI
β βββ Header.tsx # App header with actions
β βββ LoadingScreen.tsx # Loading animation
β βββ TipsAndMotivation.tsx # Tips display
β βββ UserInputForm.tsx # Multi-step form
β βββ VoiceControl.tsx # Voice narration controls
β βββ WorkoutPlanDisplay.tsx # Workout plan UI
βββ lib/
β βββ store.ts # Zustand state management
β βββ utils.ts # Utility functions
β βββ voice.ts # Text-to-speech utilities
βββ types/
β βββ index.ts # TypeScript type definitions
βββ public/ # Static assets
- 5 Progressive Steps - Personal info β Goals β Workout prefs β Diet prefs β Optional details
- Validation - Real-time form validation with helpful error messages
- BMI Calculator - Automatic BMI calculation and categorization
- Progress Bar - Visual feedback on completion status
The app uses Google's Gemini 1.5 Pro to generate:
- 7-day workout schedules with detailed exercises
- Complete meal plans with nutritional breakdowns
- Personalized tips and motivation
- All content is structured JSON for easy parsing
- Browser TTS - Uses Web Speech API (free, no API costs)
- Playback Controls - Play, pause, resume, and stop
- Script Generation - Converts plan data into natural speech
- Section Selection - Choose workout, diet, or full plan
- On-Demand - Images from Unsplash stock photos
- Context-Aware - Searches based on exercise/meal names
- High Quality - Professional stock photography
- FREE - No API costs using Unsplash
- Professional Layout - Multi-page PDF with proper formatting
- Complete Data - Includes all workout, diet, and tip information
- Branded - Custom styling with color-coded sections
- Download Ready - One-click download with user's name in filename
To use a different AI provider (OpenAI, Claude, etc.), modify the API route:
// app/api/generate-plan/route.ts
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
const { text } = await generateText({
model: openai('gpt-4-turbo'),
prompt,
temperature: 0.7,
});Or use Anthropic's Claude:
import { anthropic } from '@ai-sdk/anthropic';
const { text } = await generateText({
model: anthropic('claude-3-5-sonnet-20241022'),
prompt,
temperature: 0.7,
});For higher quality TTS, integrate ElevenLabs:
- Get API key from ElevenLabs
- Add to
.env:ELEVENLABS_API_KEY=your_key - Create API route:
app/api/text-to-speech/route.ts - Update
VoiceControl.tsxto use the API
- User Input β Multi-step form collects user data
- State Management β Zustand stores data with persistence
- API Call β Data sent to
/api/generate-plan - AI Processing β OpenAI generates personalized plan
- Display β Plan rendered with interactive components
- Actions β Export PDF, generate images, play audio
- Progress tracking and check-ins
- Calendar integration for scheduling
- Social sharing features
- Workout video demonstrations
- Meal prep instructions
- Integration with fitness trackers
- Multi-language support
- Mobile app (React Native)
| Variable | Required | Description |
|---|---|---|
GOOGLE_API_KEY |
Yes | Google AI API key for Gemini |
ELEVENLABS_API_KEY |
No | For premium TTS (optional) |
OPENAI_API_KEY |
No | Alternative AI provider |
CLAUDE_API_KEY |
No | Alternative AI provider |
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
- Google AI for Gemini API
- Vercel for Next.js framework
- Tailwind Labs for Tailwind CSS
- Unsplash for stock photography
- All open-source contributors
If you encounter any issues or have questions, please open an issue on GitHub.
Built with β€οΈ and AI