
Nutritionist Generative AI Doctor using Gemini
Want to enhance your nutrition skills? The Nutritionist Generative AI Doctor, which employs the Gemini model, is here for you. With this project, one can understand dietary requirements, monitor calorie intake, and strive for a healthier lifestyle using Artificial Intelligence with ease. This project is appropriate for health-freaks as well as beginners. Now, let's look at the objective of this innovative project - how does it make it easier and smarter for you to achieve your nutrition targets!
Project Overview
The Nutritionist Generative AI Doctor is an advanced tool aimed at detecting meals and providing suitable diet recommendations. With the help of Google Gemini AI, this project is able to take any food image and extract calorie-based information. It also gives details on macronutrients and micronutrients from the meal image.
Be it for weight loss, dieting, understanding the food content of meals, or any other reason, this AI application makes it easier. It helps in computing the calorie values, evaluating the food quality, and offering appropriate diet suggestions. Furthermore, it prepares easy graphic reports in no time for health-conscious people. This project is very useful for health-conscious people, nutritionists, and fitness buffs.
And what’s great is, that you don’t even have to think about it. Just take a picture of your meal and the AI will do its magic. This project is designed to fit every person who wants to be healthier with the innovative technology in the present world.
Prerequisites
Let’s ensure you're all set before we start this exciting process of creating chatbots! Do not worry, it is all easy, but having some prerequisites in preparation will help everything to work efficiently.
- Basic understanding of Python programming.
- A Google Colab account to run the project.
- Knowledge of how to use Google Drive for storing data.
- Google Gemini API key to access the AI model.
- Knowledge in PIL to handle food image uploads.
- Internet connection for accessing online resources and APIs.
Approach
The Nutritionist Generative AI Doctor project follows a simple but effective approach to deliver personalized nutrition insights. First, it integrates the Google Gemini model. Which is set up in Google Colab using Python. Once an image of a meal is uploaded, the AI analyzes it by identifying the food items and breaking them down into calories, macronutrients, and micronutrients. The model calculates the total calorie count and also assesses the healthiness of the meal. This provides a percentage split of carbohydrates, proteins, fats, and more. By using Google’s advanced AI capabilities, the project creates an easy nutrition report within seconds. This makes the entire process seamless and user-friendly. With this step-by-step approach, anyone can track their dietary intake with precision, improving their health decisions effortlessly.
Workflow and Methodology
Workflow
This project is simple and easy to follow. That makes analyzing your meals quick and easy. Below is a breakdown of how this works step by step.
- Setup Google Colab: First set up Google Colab then install the necessary libraries.
- Get API Key: Obtain the Google API key to access the Gemini AI model.
- Upload Meal Image: Upload meal image to the Colab environment.
- Process Image: Using the Pillow library the image is processed to ensure compatibility.
- Send to AI Model: Send the processed image to the Google Gemini model.
- Analyze Food Items: The Gemini model identifies the food items and calculates the total calories and nutrients.
- Generate Report: The model generates a detailed nutrition report, including macronutrient percentages.
- View Results: Lastly, the report is displayed.
Methodology
- Data Input & Image Processing: Users upload a food image. Then it is processed using the Pillow library to ensure compatibility with the AI model.
- AI Model Integration: Google’s Gemini AI model identifies food items in the image and breaks them down into nutritional components.
- Analysis: The AI calculates total calories and also a breakdown of macronutrients and micronutrients.
- Report Generation: The model generates an easy report with suggestions for improvement if needed.
Data Collection and Preparation Workflow
- Image Collection: The project uses food images collected from different sources
- Preprocessing: Used the Pillow library to standardize the images in size and format.
Code Explanation
STEP 1:
Mounting Drive
This code shows how to connect your Google Drive account to a Colab workspace. It helps in accessing the files available in the user’s Google Drive by making it present in a particular folder (which is ‘/content/drive’).
# Mount Google Drive
from google.colab import drive
drive.mount('/content/drive/')
STEP 2:
This code installs the Google Generative AI library. The command ensures that the latest version of the library is installed and older versions are upgraded.
!pip install -q -U google-generativeai
This code imports all the essential libraries for handling files, formatting texts, and also interacting with the Google Generative AI tools. The code safely saves the API key in the user data of Google Colab. The to_markdown function is used for formatting text into markdown in order to present it properly in the colab environment.
import pathlib
import textwrap
import google.generativeai as genai
# Used to securely store your API key
from google.colab import userdata
from IPython.display import display
from IPython.display import Markdown
def to_markdown(text):
text = text.replace('•', ' *')
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
STEP 3:
This block of code securely gets the API key from Google Colab using userdata.get('api_key'). Next, assign it to the variable GOOGLE_API_KEY. After that, it configures the genai with the API key. This enables the project to make use of Google’s AI models for image analysis.
GOOGLE_API_KEY=userdata.get('api_key')
genai.configure(api_key=GOOGLE_API_KEY)
The following code creates loops to call to the entire models with the use of genai.list_models() These are made accessible by the Google Generative AI library. The code then checks for every model if the generateContent method is supported. If it does, then the name of the model is printed. This helps in identifying the possible AI models available for content generation purposes. This can be utilized in this project for evaluation or even writing text.