Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The main object containing the nutritional information is called PassioFoodItem. This object is fetched from Passio's backend using one of several fetchFoodItemFor...
functions.
The PassioFoodItem is a top level object that can represent a single food like a banana, or a complex recipe like caesar salad.
The name
attribute is used to display the name of the food, while the details
contains additional information like the brand of the food or the name of the food which was used to populate the nutritional data
iconId
is used with the SDK function fetchIconFor
to fetch a small image of the food
refCode
is a parameter that can be used later on to retrieve the full food item again
amount
details the available serving size as well as the currently selected serving quantity and unit, used when calculating nutrients
There are three functions that can be used to fetch nutrient information for the PassioFoodItem:
The weight
function is used to fetch the sum mass of all of the ingredients.
This class holds the information about possible serving sizes and serving units, as well as the currently selected unit and quantity. Example of values for food item "apples"
serving units: small (2-3/4" dia), medium, large (3-1/4" dia), cup, oz, gram, ...
serving sizes: 1 small (2-3/4" dia), 2 cups, 100 grams, ...
selected quantity: 1
selected unit: medium
Serving units holds the list of all of the units that the system has the correct weight for. Serving sizes holds the list of predefines matches of a quantity and a serving unit. The selected quantity and unit are used to calculate nutrients on the PassioFoodItem level. While these values can be changed, the initial values are set by the SDK as a default portion.
Every PassioFoodItem has a list of ingredients. A food ingredient holds the nutritional information along with the portion size of each ingredient.
Similarly to #passiofooditem, the ingredient also has a name
, iconId
, refCode
, and amount
.
But, the most important part of the ingredient class is the PassioNutrients
and it's methods. The referenceNutrients attribute holds the referent (in most cases 100 grams) macronutrients and micronutrients, and are used to calculate the resulting nutrient values when changing serving sizes of the whole PassioFoodItem.
Also, an ingredient has PassioMetadata field, storing the information on the origin of the nutritional data, barcode value, possible ingredients (if the PassioFoodItem is a packaged food), and a list of tags.
The PassioFoodItem class encompasses both single food items like an avocado
as well as items with multiple ingredients such as homemade caprese salad
. The difference between these two items is how is the PassioFoodAmount calculated from the top-level PassioFoodItem.
Homemade caprese salad:
weight(): 176.5 grams
amount->selectedQuantity = 1
amount->selectedUnit = "serving"
ingredients: 1. fresh sliced cheese, 84 grams, amount->selectedQuantity = 3, amount-> selectedUnit = "oz" 2. balsamic vinegar, 16 grams, amount->selectedQuantity = 1, amount-> selectedUnit = "tbsp" 3. fresh basil, 3 grams, amount->selectedQuantity = 6, amount-> selectedUnit = "leaves" 4. tomatoes, 60 grams, amount->selectedQuantity = 3, amount-> selectedUnit = "medium slice" 5. olive oil, 13.5 grams, amount->selectedQuantity = 1, amount-> selectedUnit = "tbsp"
Invoking the function foodItem.nutrientsServingSize() will fetch the nutrients for the whole recipe, calculated by the weight of the serving size "1 serving".
Avocado:
weight(): 201 grams
amount->selectedQuantity = 1
amount->selectedUnit = "avocado"
ingredients:
1. avodaco, raw
, 201 grmas, amount->selectedQuantity = 1, amount->selectedUnit = "avocado"
A single food item will always have only one ingredient. Also, the amount object of the PassioFoodItem will be the same as the amount of the first ingredient. The ingredient is the item in the database used for nutritional data. For example, If the SDK recognises "milk" during the visual detection process, the default food item for "milk" is "milk, whole, 3.25% milkfat, without added vitamin a and vitamin d".
Fetch the PassioFoodItem
Use the name, details and iconId to create the food header view
Use the nutrientsSelectedSize->calories, carbs, protein and fat to show the marcos
Use the amount class to create the serving size view
Give the user the option to log the food
To use the SDK please make sure you receive your SDK license key from Passio. The SDK WILL NOT WORK without a valid SDK key.
To obtain an SDK key visit https://www.passio.ai/nutrition-ai
These are the minimum requirements for every supported platform
The SDK will only run or compile on iOS 13 or newer.
Passio SDK can only be used on a device and will not run on a simulator
The SDK requires access to iPhone's camera
Weight/Volume estimation will run only on iPhones with Dual Wide Camera (not on DualCamera). It will not run on the models below.
iPhone 11 Pro & Pro Max
iPhone 12 mini, Pro & Pro Max
iPhone 13 Pro & Pro Max
iPhone 14, Pro, Pro Max & Plus
Built with Kotlin version 1.6.10
Minimum Android SDK version is 26
The SDK requires access to the device's camera
The SDK is built upon CameraX, TensorFlow and Firebase's ML Vision so these dependencies will need to be added to the project manually
The configuration process of the SDK has severable responsibilities:
Validation of the license key
Validating the currently present files
Downloading or updating the files required by the SDK to do recognition
Preparing the files to be used for inference
The SDK is configured using a PassioConfiguration
object. This object is used to define the location of the files that the SDK requires.
The default behaviour (or by setting the sdkDownloadsModels field to true) of the SDK is to download the required files for local recognition. If the current files that are present on the device are older than the version of the SDK library, the SDK will download the newer version in the background, but still run the session with the older version of the files. Once the download is finished, the new files will be applied on the next session. Don't forget to add the import statement for the nutrition sdk.
The models required for the SDK to run local recognition can take some time for the first download. If the local recognition is not needed, setting the remoteOnly
to true on the PassioConfiguration process will skip the download of the models. Remote recognition functions like recognizeImageRemote or searchForFood will still work.
If remoteOnly
is used when configuring the SDK, calling startFoodDetection with visual or packaged food detection enabled will have no effect.
The result of the configuration process is a PassioStatus
object, containing a PassioMode attribute along with the missingFiles, debugMessage, error object and the active models number. The attribute that needs to looked at is the mode.
PassioMode
is an enum describing the current state of the Passio SDK configuration process:
notReady -> The configuration process hasn't started yet.
failedToConfigure -> There was an error during the configuration process.
isBeingConfigured -> The SDK is still in the configuration process. Normally, you shouldn't receive this mode as a callback to the configure method. If you do please contact our support team.
isDownloadingModels -> The files required by the SDK to work are not present and are currently being downloaded.
isReadyForDetection -> The SDK is configured with the set of files defined by the activeModels attribute.
The missingFiles variable contains a list of all the files missing for the SDK to work optimally. When this list is not null, this doesn't mean that the SDK is not operational. The SDK may be initialized with older files, but it will advocate the download of the newest files through this list.
The debugMessage usually gives more verbose and human-readable information about the configuration process. It will always give an error message if the mode is FAILED_TO_CONFIGURE.
The activeModels will give the version of the files installed and ran by the SDK if the configuration process ran successfully i.e. if the mode is IS_READY_FOR_DETECTION.
Make sure there is internet connection for the configuration process. The SDK needs to download the license file and the required files. If there is no internet connection the configuration status mode will be failedToConfigure.
The PassioStatus mode is notReady -> check debugMessage for the error, usually the wrong license key has been supplied or the files are missing.
The PassioStatus mode is isDownloadingModels -> register a PassioStatusListener
through the setPassioStatusListener method as it will enable tracking of the download progress.
The PassioStatus mode is isReadyForDetection -> still check the missingFiles because the SDK might be running with an older version of the files and newer need to be downloaded.
Welcome to Passio Nutrition-AI iOS SDK! When integrated into your app the SDK provides you with food recognition and nutrition assistant technology. The SDK creates a video preview layer and outputs foods recognized by our computer vision technology in the video feed of your live camera along with nutrition data related to the recognized foods.
As the developer, you have complete control of when to turn on/off the SDK and to configure the outputs which includes:
food names (e.g. banana, hamburger, fruit salad, quest chocolate bar)
lists of alternatives for recognized foods (e.g., soy milk would be an alternative of a visually recognized class milk)
barcodes detected on food packages
packaged foods recognized by the text detected on food packages
nutrition information detected on food packages via Passio's Nutrition Facts reader which returns information written in Nutrition Facts labels
nutrition information associated with the foods
food weight and volume for certain foods
By default the SDK does not record/store any photos or videos. Instead, as the end user hovers over a food item with his/her camera phone, the SDK recognizes and identifies food items in real time. This hovering action is only transitory/temporary while the end user is pointing the camera at a particular item and is not recorded or stored within the SDK. As a developer, you can configure the SDK to capture images or videos and store them in your app.
Passio Nutrition-AI SDK added data from Open Food Facts (https://en.openfoodfacts.org/). Each food that contains data from Open Food Facts will have the value set in its food origin list. In case you choose to display the these food items you agree to abide by the terms of the Open Food Facts license agreement (https://opendatacommons.org/licenses/odbl/1-0) and their terms of use (https://world.openfoodfacts.org/terms-of-use) and you will have to add to the UI the following license copy:
"This record contains information from Open Food Facts (https://en.openfoodfacts.org), which is made available here under the Open Database License (https://opendatacommons.org/licenses/odbl/1-0)"
The SDK can detect barcodes located on the packaging of packaged foods. To implement real-time barcode scanning, the camera setup for continuous image recognition is needed.
Specifically for barcode scanning, these steps are required:
When defining a FoodDetectionConfiguration
object, enable the detectBarcode
flag.
In the recognitionResults
callback, check the property candidate.barcodeCandidates
. If this list is empty, no barcodes have been recognised.
If there is a single or multiple barcode candidates, use their value property and invoke this function to fetch the full nutrition data.
On smaller packages, barcodes can be very small. When trying to scan these barcodes, the user usually brings to package to close to the camera creating focus issues. To avoid this, but the camera zoom level to 2.
To recognise a barcode in an image, refer to the recognizeImageRemote function. The result of the barcode scanning process will come in the packagedFoodItem
attribute, and the resultType will be Barcode.
Set up the camera preview and detection session to recognise barcodes
Create a result view with two states: search and result
If the candidate.barcodeCandidates is empty, show the search state. Else, fetch the PassioFoodItem, and use it's name and icon to show the result
Example of an image that produces multiple BarcodeCandidates:
Starting from the SDK version 3.1.4 the NutritionAdvisor is only accessible using the NutritionAI Hub key. A key bought for the previous NutritionAI product won't work with this feature.
The Nutrition Advisor is an intelligent chatbot designed to offer personalised guidance on nutrition, diets, and healthy eating habits. Whether you're looking to explore a new diet, understand the nutritional value of certain foods, or find delicious and balanced recipes, the Nutrition Advisor is here to assist. Users can interact with the Nutrition Advisor through text messages, engaging in a conversational experience where they can ask questions about various diets like keto, vegan, Mediterranean, and more. The chatbot provides detailed insights into the benefits, potential drawbacks, and suitability of these diets based on individual goals and preferences.
As opposed to the rest of the SDK, the Nutrition Advisor has a different API entry point:
NutritionAdvisor
Use these steps to initialise the conversation and enable users to send messages:
To start a conversation initConversation
has to be invoked. The response will either indicate a success state, which means message can be sent to the advisor. In case of an error, an error message will detail the cause.
Text messages are sent using the sendMessage
API. The reply (if successful) will contain a PassioAdvisorResponse
response. This object consist of:
threadId - identifies the conversation
messageId - identifies the specific message
markupContent - text response from the advisor denoted with markup tags. This can be used to style the text when rendering
rawConent - text response without the markup tags
tools - list of actions that can be executed by the advisor. Only should be used by the SDK
extracedIngredients - will contain a list of foods if the request to the advisor was an image recognition request or extract ingredients from text message request
Image are sent to recognition using sendImage
. As mentioned above, in the PassioAdvisorResponse object, the extractedIngredients
property will hold the recognised foods.
In the case that a PassioAdvisorResponse contains a tool called searchMatchIngredient
, the Advisor has the ability to parse the text response and return the list of foods. If a message that has this tool is passed to the fetchIngredients
API, the returned response will contain foods in the extracedIngredients field.
This feature is particularly useful when trying to log foods when directly communicating with the chatbot. A common use case is when user ask for a specific recipe. They can then initiate the extraction of foods from the message, and see their nutrition value and finally log the entire meal in one action.
Create a screen where the user can type messages and send images to the NutritionAdvisor. Upon initiating the screen, set up the conversation by calling initConversation
.
When the user types a message in the input text field and taps "Send", invoke the sendMessage
function. Because this is an asynchronous function, add an animation to indicate this behaviour.
If the response from the advisor contains a tool called searchMatchIngredient
show an action button "Find foods" to initiate extraction of the foods. Invoke the fetchIngredients
function using the response from the Advisor.
Create a view where the user can see the extracted foods, their serving size and have the ability to log them.
Add the ability for the user to select an image from the library of the phone. Once the image is obtained, invoke the sendImage
to get the list of foods. If foods are recognised, the response will contain a list of foods, use the same result view to show them.
There are cases when the barcode scanning item isn't present in the nutritional database. In the cases when the fetchFoodItemForProductCode doesn't yield a response, the user can scan the nutrition facts label on the packaging of the food and extract the data to create a new food item.
Similar to the real-time barcode scanning, the camera preview must be set up to enable continuous nutrition facts scanning. To start the Nutrition Facts scanning process a NutritionFactsRecognitionListener has to be defined. When the app is done with the nutrition fact scanning process, it should clear out the listener to avoid any unwanted UI updates.
The PassioNutritionFacts
contains all of the data that can be scanned from a nutrition facts label including:
Serving size (quantity and unit)
Weight
Calories
Carbs
Protein
Fat
Sugars
Other micronutrients like fiber, cholesterol...
To recognise nutrition facts in an image, refer to the recognizeImageRemote function. The result of the nutrition facts scanning process will come in the packagedFoodItem
attribute, and the resultType will be Nutrition Facts. The nutrients will be stored in the PassioNutrients object of the first ingredient, and the serving size info will be stored in the PassioFoodAmount.
There is a separate API called recognizeNutritionFactsRemote
that is specifically taylored for this task. The recognizeImageRemote has the ability to recognise multiple different aspects of food scanning, but if there is a use case where the only action is to extract the data from the nutrition facts label, it's advised to use the recognizeNutritionFactsRemote.
The barcode scanning process is always the most precise way to get nutritional information about a packaged food. If the barcode is not present in the nutritional database, give the user the option to scan the nutrition facts label.
If the user proceeds with the Nutrition Facts scan, register a listener to start receiving the results from the SDK. When a PassioNutritionFacts is returned from the callback, display the data so that the user can verify it's accuracy.
Enable to user to manually enter all of the other data that the Nutrition Facts scanner did not recognise.
Once a user saves this food item, be sure to include it in the search or barcode scanning results.
The Passio Nutrition AI SDK search functionality gives access to over 2.2 million food records in our nutritional database. The search api takes in a text query and returns a list of PassioFoodDataInfo results as well as a list of suggested searches
The PassioFoodDataInfo is used a reference object to fetch the full nutritional data. It has all of the attributes needed for displaying on a typical search screen: the name of the food, name of the brand (if possible), iconId, and a nutritional preview detailing the macro nutrients for a specified serving size and weight.
To fetch the PassioFoodItem using a search result, invoke the fetchFoodItemForDataInfo
.
The search will return 50 items that best match the input term, as well as a list of suggested searches that are semantically or contextually close to the input term.
Example: searching for term "coffee"
search results: "Coffee, Brewed", "Coffee, Breakfast Blend", Coffee - Brewed From Grounds", "Coffee, Brewed, Decaffeinated", "Coffee, Instant, Reconstituted Decaffeinated", ...
suggested searches: "coffee with whole milk", "coffee with creamer", "iced coffee"
Create an input text field to collect the user query
Create a horizontal list scroll to display the suggestions
Create a vertical list to display the results of the search
If the user clicks on a suggestion, pass that string to the search API and reload the UI with the new results
The SDK gives the ability to fetch food icons for a specific passioId
. There are two functions that can be used: lookupIconsFor
and fetchIconsFor
.
lookupIconsFor does a local search of the icons without doing any networking calls. It returns two icons. One is a placeholder icon depending on the type of food associated with the passioId. The second one is cached icon from a previous fetchIconsFor call, it it exists.
fetchIconsFor does a networking call to fetch an icon associated with the passioId, but it will check the local cache and return a previously fetched icon.
If displaying a PassioFoodItem, PassioIngredient or a PassioFoodDataInfo icon, pass the iconId
to the appropriate icon function.
Example of how to use both of these functions to first display the placeholder icon, and then fetch the remote icon:
A component for displaying food icons from the Passio SDK.
There are several functions that are used to retrieve the PassioFoodItem object, depending on the origin of the data. If the food item is being scanned using an image, the food item is fetched using either fetchFoodItemForPassioID
or fetchFoodItemForProductCode
. If search is being used to access to food item, the appropriate call is the fetchFoodItemForDataInfo
.
But if there is a use case that requires to save just one attribute to a database, that will later on be used to retrieve the full PassioFoodItem object, then the refCode
attribute is the answer. The refCode in combination with the fetchFoodItemForRefCode
will retrieve the original food item object from Passio's nutritional database.
refCode is a string hash of a complex object and can reach lengths above 180 characters.
If the implementing app is transitioning from generation 2
to generation 3
of the SDK, and has already stored generation 2 PassioID
s, invoking the fetchFoodItemLegacy
will retrieve the PassioFoodItem that was previously structured as PassioIDAttributes.
Follow these steps to include the SDK into your mobile application project.
Open your Xcode project.
Go to File > Swift Packages > Add Package Dependency.
In the "Add Package Dependency" dialog box, paste the URL: https://github.com/Passiolife/Passio-Nutrition-AI-iOS-SDK-Distribution
Click "Next". Xcode will validate the package and its dependencies.
In the next dialog box, you'll be asked to specify the version or branch you want to use. You can choose main for the latest version or specify a specific version or branch.
After you've made your selection, click "Next".
You'll then be prompted to select the targets in your project that should include the package. Check the boxes for the targets you want to include.
Click "Finish" to add the package to your project.
Xcode will download and add the PassioNutritionAISDK to your project. You can now import and start using the PassioNutritionAISDK.
Download the "PassioNutritionAISDK.xcframework.zip" file from https://github.com/Passiolife/Passio-Nutrition-AI-iOS-SDK-Distribution/blob/main/PassioNutritionAISDK.xcframework.zip
Unzip it and drag and drop it into your project. Make sure to select "Copy items if needed".
In project "General" -> "Frameworks, Libraries and Embedded Content" Change to "Embed & Sign"
If opening from Xcode, right click and select 'open as source code'
To allow camera usage add:
The Passio Android SDK is shipped in the form of an .aar file.
Visit the releases page of the Android-Passio-SDK-Distribution GitHub repository. Download the passiolib-release.aar file from the latest release.
To include the .aar file into your project go to the module that will contain the food recognition feature. Place the .aar file in the libs folder of the module. If the libs folder is missing, create one. Reference the .aar file in the build.gradle file of the implementing module.
Sync Project with Gradle Files and be sure that you can reference the PassioSDK class within your code.
Passio Android SDK is powered by TensorFlow and FirebaseVision with the camera being managed by CameraX. Add the dependencies to these three projects by adding these lines to the module's build.gradle file.
In order for the SDK to work add the following lines to the android section of the module's build.gradle file.
Running Sync Project with Gradle Files will enable access to the SDK.
1. Create a Github Personal Access Token (classic) with read:packages
access selected.
2. Create an .npmrc
file in the root of your project with the following lines replacing GITHUB_ACCESS_TOKEN
with the token you've created.
3. Add the Passio SDK dependency to your package.json
and run npm install
or yarn
.
or
4. Ensure the native dependencies are linked to your app.
For iOS, run pod install.
If pod install is failed with error message Specs satisfying the ReactNativePassioSDK (from ../node_modules/@passiolife/nutritionai-react-native-sdk-v3) dependency were found, but they required a higher minimum deployment target.
, ensure Podfile is configured with minimum ios version '13.0'
For Android, add this implementation line to the dependencies section on app/build.gradle
file.
Also for Android, make sure the android project is configured with minSdkVersion 26 or above (check the project's build.gradle
file).
The Flutter SDK is available as a package on pub.dev
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get
):
Alternatively, your editor might support flutter pub get
. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
Add to top build.gradle file (Project: android)
The nutrition_ai build.gradle file dependency section should look like (Module: nutrition_ai)
The Passio SDK has the ability the recognise anything from simple ingredients like blueberries and almonds to complex cooked dishes like a beef burrito with salad and fries.
There are two types of food recognition, each of them with their own strengths and weaknesses.
The Remote image recognition approach is good when the accuracy of the results is top priority, and waiting for the response is not an issue. This use case is implemented by taking static images from the camera or the library of the device and sending them for recognition in an asynchronous fashion.
The Local model approach is good when speed is of the essence. This use case is implemented using continuous frame recognition from the camera. A callback is registered to capture the results as they are coming from the camera stream.
This API sends an image as base64 format to an LLM on Passio's backend, and returns a list of recognised items.
The API can recognise foods raw or prepared, barcodes or nutrition facts tables. The type of recognition will be shown in the resultType
enum.
The default behaviour of this function is to resize the image to 512 pixels (longer dimension is resized, the other is calculated to keep aspect ratio). Using the PassioImageResolution
enum, the image can be either resized to 512, 1080 or keep the original resolution.
Create a screen where the user can snap one or multiple images using the camera of the device
Upon clicking next, the recognizeImageRemote
is invoked on each of the images in the list
Wait for all of the responses to come, add each results list to a final list of results. When the last asynchronous function is executed, present the final list to the user.
To set up the local model and the continuous scanning mode, the camera preview and the recognition session need to be defined.
To start using camera detection the app must first acquire the permission to open the camera from the user. This permission is not handled by the SDK.
Add the UI element that is responsible for rendering the camera frames:
Start by adding the PreviewView to your view hierarchy. Go to your layout.xml and add the following.
This approach is more manual but gives you more flexibility. You need to implement the PassioCameraViewProvider interface and supply the needed LifecycleOwner and the PreviewView added in the initial step.
After the user has granted permission to use the camera, start the SDK camera
PassioCameraFragment is an abstract class that handles Camera permission at runtime as well as starting the Camera process of the SDK. To use the PassioCameraFragment simply extend it in your own fragment and supply the PreviewView that has been added to the view hierarchy in the previous step.
To show the live camera preview, add the DetectionCameraView
to your view
The SDK can detect 3 different categories: VISUAL, BARCODE and PACKAGED. The VISUAL recognition is powered by Passio's neural network and is used to recognize over 4000 food classes. BARCODE, as the name suggests, can be used to scan a barcode located on a branded food. Finally, PACKAGED can detect the name of a branded food. To choose one or more types of detection, a FoodDetectionConfiguration object is defined and the corresponding fields are set. The VISUAL recognition works automatically.
The type of food detection is defined by the FoodDetectionConfiguration
object. To start the Food Recognition process a FoodRecognitionListener also has to be defined. The listener serves as a callback for all the different food detection processes defined by the FoodDetectionConfiguration. When the app is done with food detection, it should clear out the listener to avoid any unwanted UI updates.
Implement the delegate FoodRecognitionDelegate
:
Add the method startFoodDetection()
In viewWillAppear
request authorisation to use the camera and start the recognition:
Stop Food Detection in viewWillDisappear
:
Using the listener and the detection options start the food detection by calling the startFoodDetection method of the SDK.
Stop the food recognition in the onStop() lifecycle callback.
Add the method startFoodDetection()
and register a FoodRecognitionListener
Stop Food Detection on widget dispose:
The FoodCandidates
object that is returned in the recognition callbacks contains three lists:
detectedCandidates
detailing the result of VISUAL detection
barcodeCandidates
detailing the result of BARCODE detection
packagedFoodCandidates
detailing the result of PACKAGED detection
Only the corresponding candidate lists will be populated (e.g. if you define detection types VISUAL and BARCODE, you will never receive a packagedFoodCandidates list in this callback).
A DetectedCandidate represents the result from running Passio's neural network, specialized for detecting foods like apples, salads, burgers etc. The properties of a detected candidate are:
name
passioID (unique identifier used to query the nutritional databse)
confidence (measure of how accurate is the candidate, ranges from 0 to 1)
boundingBox (a rectangle detailing the bounds of the recognised item within the image dimensions)
alternatives (list of alternative foods that are visually or contextually similar to the recognised food)
croppedImage (the image that the recognition was ran on)
Implement the camera screen using the steps above
Create a result view that can have two states: scanning and result
If the callback returns an empty list, show the scanning state. If it returns the result, display the name from the detectedCandidate.name
Example of an image that produces a DetectedCandidate:
The SDK provides the ability to fetch a predefined set of suggested foods for logging, depending on the current time of day
Example of fetching suggestions for snack meal time:
banana, coffee, black tea, coke, cheddar cheese, chocolate chip cookies, potato chips, blueberry muffin, plain yogurt, strawberries, ...
UX Tip: Combine these predefined suggestions with user meal logs to provide a list of "quick suggestion" logs. This will enable users to log their meals even faster.
Meal Plans provide users suggestions which foods to consume depending on their dietary preference and time of day. The Meal Plan api is divided into two functions:
fetchMealPlans
that is used to retrieve all of the possible meal plans. These meal plans usually correlate with a specific diet like "Keto Diet".
fetchMealPlanForDay
is an api that is used to fetch specific foods recommended for a certain day of a target meal plan.
Some of the available meal plans:
Heart Healthy Diet, Ketogenic Diet, Managing Obesity, Managing Type 2 Diabetes, Low FODMAP, Healthy Kidney Diet, Balanced Diet, DASH Diet, PCOS Diet, Mediterranean Diet
The response, presented as a list ofPassioAdvisorFoodInfo
objects, contains the name, portion and weight in grams recognised by the LLM. These attributes can be used for debugging, but the data from the nutritional database is contained either in the foodDataInfo
if the result type is a Food Item, or packagedFoodItem
if it's a Barcode or Nutrition Facts. To fetch the for the PassioFoodDataInfo object, use the fetchFoodItemForDataInfo
function.
To start using the camera in your Activity/Fragment, implement the PassioCameraViewProvider interface. By implementing this interface the SDK will use that component as the lifecycle owner of the camera (when that component calls onPause() the camera will stop) and also will provide the Context in order for the camera to start. The component implementing the interface must have a in its view hierarchy.
To fetch the of a detected candidate use:
No, the image is sent to the backend for recognition
Very precise with all types of foods
On average 4-7 seconds
Yes, the recognition is done on the device
Good with single food items, struggles with complex cooked foods
Depending on the hardware of the device, ranges between 50-300ms
The recognizeSpeechRemote
function is primarily used to fetch food items using a voice command, although it can be used to extract food items from a recipe in a text form as well.
The input to this function is just a string in free format, so the implementing side needs to do speech-to-text before using the API.
This function will be able to extract several pieces of data:
meal action, is this food being added or removed from the logs
meal time (breakfast, dinner, lunch or snack)
date of log
recognised name from the LLM
portion and weight from the LLM
nutritional data reference as PassioFoodDataInfo
Example of logging a morning breakfast:
The SDK doesn't have the functionality to record the voice session, that has to be handled by the app.
Create a screen where the user can record the voice logging command. Make sure to add the appropriate permissions.
The UI should enable the user to start/stop voice recording on a tap of a button. When the voice recording is done collect the string and use the SDK to extract food.
Once the SDK returns the results, show the list to the user with the option to deselect incorrect predictions.