A cutting-edge AI-powered meal planning and nutrition tracking application built with Next.js, FastAPI, and advanced Agentic RAG capabilities to help users create personalized meal plans based on available ingredients, dietary preferences, and nutritional goals.
- Overview
- Key Features
- Technology Stack
- Architecture
- Setup & Installation
- Usage Guide
- API Documentation
- Acknowledgments
AI Chef Mate is a comprehensive meal planning application that leverages Agentic RAG to create personalized meal plans based on user's available ingredients, dietary preferences, and nutritional goals. The application includes features for meal planning, nutrition tracking, and ingredient recognition, providing users with a complete solution for managing their diet and meal preparation.
- Ingredients-Based Meal Generation: Upload a photo of your ingredients or add them manually
- Dietary Preference Support: Accommodates various dietary needs (vegan, vegetarian, keto, etc.)
- Allergy Management: Excludes ingredients based on user-specified allergies
- Protein Goal Setting: Creates meal plans that meet daily protein targets
- Weekly Meal Prep: Generates recipes with quantities for 7-day meal prep
- Nutritional Information: Calculates macros for each meal and weekly totals
- Food Image Analysis: Upload photos of meals to automatically analyze nutritional content
- Manual Configuration: Manually edit any of the macros if necessary
- Daily & Weekly Summaries: View nutrition data by day or aggregated weekly
- Meals Eaten: View the meals you have eaten for the day
- Meal Plan Refinement: Chat with the AI to modify and customize meal plans
- Nutrition Questions: Ask questions about food, ingredients, and nutrition
- Save & Review: Save generated meal plans for future reference
- Context-Aware Conversations: The AI remembers previous interactions for better assistance
- User Authentication: Secure sign-up and login functionality
- Reset Password: Enter your email to get an instant password reset link
- Data Storage: Your meals and plans are stored for future viewing
- Next.js 15: React framework with server-side rendering
- TypeScript: For type-safe code
- Tailwind CSS: For utility-first styling
- Shadcn UI: Component library for a consistent UI
- React Hook Form: For form validation and handling
- Sonner: For toast notifications
- Lucide Icons: For a modern icon set
- FastAPI: Python-based API server for handling AI operations
- Supabase: Online PostgreSQL database with authentication services
- Python 3.12: For backend processing and AI integration
- Meta Llama 3.3 70B: Inferenced through SambaNova Systems for generating meal plans and nutritional guidance
- Meta Llama 3.2 11B Vision: Inferenced through SambaNova Systems to perform vision processing for food image analysis
- CrewAI: Framework for agent-based AI system
- Qdrant: Vector database for recipe search
- Embedding Models:
- All MiniLM L6 V2 provided by Sentence Transformer library for Qdrant
- Embed English v3.0 provided by Cohere for Crew AI memory
The application follows a client-server architecture:
-
Next.js Frontend:
- Handles user interface and interactions
- Communicates with both the FastAPI backend and Supabase
- Provides real-time feedback and displays AI-generated content
-
FastAPI Backend:
- Processes AI requests and manages LLM interactions
- Handles image analysis for food recognition
- Maintains conversation context and agent memory
- Provides nutrition data analysis
-
Supabase Database:
- Stores user accounts and authentication
- Maintains saved meal plans and nutrition tracking data
- Provides secure API access to user data
-
AI Components:
- LLM integration for AI Agent powered meal plan generation
- Vision models for food recognition and nutrition tracking
- Vector search for finding relevant recipes
- Node.js 18+ and npm/yarn
- Python 3.9+
- Git
- Supabase account
- Qdrant account
- API keys for SambaNova, and Cohere
- Once you create an account and a project, first go to the
Settingsand then theData APItab. Here you'll be able to find yourProject URL,Anon Key&Service Role Key. Copy these and paste them as explained below in the Environment Variables section. - Then head to the
Table Editortab to create the tables to store the data. - Create a table called saved_mps with columns
username, mp_name, mpas text data type and a column calledcreated_atwith data type as date. - Create a table called saved_macros with columns
username, meal_name, food_nameas text data type,calories, proteins, fats, carbsas int8 data type anddate_addedas date data type.
- Download the dataset:
- Go to the download page.
- Accept Terms and Conditions and download zip file.
- Unpack the zip file and you'll get the
full_dataset.csvfile in the dataset directory.
- Preprocess the dataset:
- First run all the cells in the
dataset_preprocessing.ipynbfile found in themiscfolder. This will allow you to get the preprocessed dataset and the dataset with 1,000,000 records.
- First run all the cells in the
- Upload the data to Qdrant:
- Next, run all the cells in the
upload_2_qdrant.ipynbfile located in themiscfolder so that your vector database is ready.
- Next, run all the cells in the
Create .env files in both the root directory and the api directory with the following variables:
SUPABASE_URL=your_supabase_url
SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
API_URL=http://localhost:8000
SAMBANOVA_API_KEY=your_sambanova_api_key
COHERE_API_KEY=your_cohere_api_key
QDRANT_URL=your_cluster_url
QDRANT_API_KEY=your_qdrant_api_key
- Clone the repository
Create a colder for the project
cd <your folder name>
git clone [email protected]:projects-2024-25/pxk232.git-
Install frontend dependencies
npm install
-
Install Python backend dependencies
cd api python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt cd ..
-
Start the development servers
npm run dev:all
The application will be available at http://localhost:3000, and the API server will run at http://localhost:8000.
- In the home page click the Get Started button to be redirected to the create acount page
- Enter your email ID and password and create your account. After that you will be signed in and redirected to the dashboard.
- If you already have an account, you can click on the sign in button to enter your details and login to your account
- Incase you forgot your password, you can click on the forgot password button and you will be redirected to another page where you
- In the dashboard, navigate to the "Create Meal Plan" page
- Follow the step-by-step process:
- Upload a photo of your ingredients or add them manually
- Select dietary preferences and allergies
- Set your daily protein target
- Review and generate your meal plan
- The AI will create a personalized weekly meal plan with:
- Breakfast, lunch, dinner, and snack recipes
- Ingredient quantities for 7 servings (batch cooking)
- Nutritional information per serving
- Preparation instructions
- Use the chat interface to:
- Ask questions about your meal plan
- Request modifications to recipes
- Get additional nutrition advice
- Save your customized meal plan for future reference
- Navigate to the "Nutrition Tracker" page
- Add meals by:
- Uploading a photo of your food
- Entering food details manually
- View your daily and weekly nutrition summaries
- Track progress over time with the weekly view
- Navigate to the "View Saved Meal Plans" page
- Here you'll be able to see all your saved meal plans
- Click on the "View Plan" button to view a meal plan
- Click on the pencil icon to change the name of a meal plan and hit the save button when done
- Click the trash bin icon to delete a meal plan. You will be asked to confirm before deleting.
To test the two different RAG methods you can use the rag_test.ipynb file located in the misc folder. Run all the cells and follow the guide given in the comments.
/chat: Processes chatbot conversations for meal planning/analyze-food-macros: Analyzes food images to extract nutritional information/save-macros: Saves meal nutrition data to the database/get-user-macros/{username}: Retrieves a user's daily nutrition data/get-user-weekly-macros/{username}: Gets weekly nutrition summaries
/api/chat: Proxy for the FastAPI chat endpoint/api/analyze-food-macros: Proxy for food analysis/api/save-meal-plan: Stores meal plans in Supabase/api/save-macros: Proxy for saving nutrition data
This project is licensed under a custom license. You may use the code for personal, non-commercial purposes only (e.g., running the app locally). Commercial use and redistribution are strictly prohibited. See the LICENSE file for more details.
This repository contains the code for the Final Year Project of Pranav Krishnakumar, a BSc Computer Science student at the University of Birmingham Dubai. A huge thank you to Professor Safdar Khan and Professor Syed Fawad Hussain for their support and guidance through the making of this project.