A modern web application that uses artificial intelligence to analyze food photos and provide detailed nutritional information including calories, macronutrients, vitamins, and minerals.
- π€ AI-Powered Analysis: Advanced computer vision with OpenAI GPT-4V
- β‘ Instant Results: Get nutrition facts in seconds
- π Comprehensive Data: Calories, macros, vitamins, minerals, and portion estimates
- π± Responsive Design: Works perfectly on desktop and mobile
- π¨ Beautiful UI: Modern, clean interface built with Tailwind CSS
- π Privacy-First: Images are processed temporarily and not stored
- Node.js 18+ installed
- OpenAI API key with GPT-4V access
-
Clone the repository
git clone https://github.com/yourusername/caldish.git cd caldish -
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env.local
Edit
.env.localand add your OpenAI API key:OPENAI_API_KEY=sk-your-openai-api-key-here NEXT_PUBLIC_APP_URL=http://localhost:3000
-
Run the development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
- Next.js 14 - React framework with App Router
- TypeScript - Type safety and better DX
- Tailwind CSS - Utility-first CSS framework
- React Query - Data fetching and state management
- Chart.js - Beautiful nutrition charts
- React Dropzone - Drag-and-drop file uploads
- Next.js API Routes - Serverless API endpoints
- OpenAI GPT-4V - AI vision for food analysis
- Sharp - High-performance image processing
- Zod - Runtime type validation
- Vercel - Recommended hosting platform
- Environment Variables - Secure API key management
- Upload Image: Drag and drop or click to select a food photo
- Configure Options: Choose analysis settings (vitamins, confidence level, etc.)
- Analyze: Click "Analyze Nutrition" to start AI processing
- View Results: Get detailed nutrition breakdown with confidence scores
- Export/Share: Save results or analyze another image
- JPEG (.jpg, .jpeg)
- PNG (.png)
- WebP (.webp)
- Maximum size: 10MB
- Recommended: Well-lit, clear images with full dish visible
POST /api/analyze-food
// Form Data
{
image: File,
options?: {
includeVitamins: boolean,
includeMinerals: boolean,
confidenceThreshold: number,
detailedBreakdown: boolean
}
}
// Response
{
success: boolean,
data: {
analysis: {
id: string,
foods: FoodItem[],
nutrition: NutritionData,
overallConfidence: number,
processingTime: number,
notes?: string,
warnings?: string[]
}
}
}GET /api/analyze-food
// Response
{
success: true,
message: "Food analysis API is running",
timestamp: string,
version: string
}| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key with GPT-4V access | Yes |
NEXT_PUBLIC_APP_URL |
Application URL for metadata | No |
NEXT_PUBLIC_MAX_FILE_SIZE |
Maximum upload size in bytes | No |
GEMINI_API_KEY |
Google Gemini API key (backup) | No |
// lib/constants.ts
export const IMAGE_CONFIG = {
maxSize: 10 * 1024 * 1024, // 10MB
allowedTypes: ['image/jpeg', 'image/png', 'image/webp'],
maxDimensions: { width: 2048, height: 2048 },
compressionQuality: 0.9,
};interface AnalysisOptions {
includeVitamins?: boolean; // Include vitamin analysis
includeMinerals?: boolean; // Include mineral analysis
confidenceThreshold?: number; // Minimum confidence (0.1-1.0)
detailedBreakdown?: boolean; // Detailed ingredient analysis
}# Type checking
npm run type-check
# Linting
npm run lint
# Build verification
npm run build-
Connect to Vercel
npm install -g vercel vercel
-
Set environment variables in Vercel dashboard
-
Deploy: Automatic deployment on git push
-
Build the application
npm run build
-
Start production server
npm run start
- Good Lighting: Use natural light when possible
- Full Dish: Capture the entire meal in frame
- Clear Focus: Avoid blurry or heavily filtered images
- Minimal Background: Reduce visual distractions
- Single Dish: Works best with one main dish per photo
- Visible Ingredients: Ensure key ingredients are clearly visible
- Standard Servings: Results are more accurate for typical portion sizes
- Fresh Foods: Better recognition for whole foods vs. heavily processed items
"Failed to analyze image"
- Check OpenAI API key is valid and has GPT-4V access
- Verify image meets size and format requirements
- Try with a clearer, well-lit image
"Network error"
- Check internet connection
- Verify API endpoint is accessible
- Check for any firewall or proxy issues
"Rate limit exceeded"
- OpenAI API rate limits reached
- Wait a few minutes before trying again
- Consider upgrading OpenAI plan for higher limits
Set NODE_ENV=development to see detailed error messages and logs.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Nutrition analysis is AI-generated and provided for informational purposes only. Results are estimates and may not be completely accurate. Always consult with healthcare professionals for dietary advice and medical nutrition therapy.
- OpenAI for GPT-4V technology
- Next.js team for the amazing framework
- Tailwind CSS for the beautiful styling system
- All contributors and users of this project
Made with β€οΈ by Raymond
For support or questions, please open an issue or contact your-email@example.com