A Python package to generate detailed meal information from natural language descriptions using Generative AI
Project description
Meal Generator
A Python package that uses a Generative AI model to parse natural language descriptions of meals and returns a detailed breakdown, including components, estimated weights, and a comprehensive nutrient profile.
Features
- Natural Language Processing: Understands descriptions of meals like "a bowl of oatmeal with a sliced banana and a drizzle of honey."
- Component Breakdown: Identifies individual ingredients within the meal.
- Nutrient Analysis: Provides estimated nutritional information for each component, including calories, macronutrients, and common allergens.
- Structured Output: Returns data as organized Python objects for easy integration into your applications.
Documentation
For a complete API reference and more detailed information, please visit the full documentation on Read The Docs.
Installation
Install the package using pip:
pip install meal-generator
You will also need to have a Google Gemini API key. You can set this as an environment variable:
export GEMINI_API_KEY="your-api-key"
Usage
Here is a quick example of how to use the MealGenerator:
from meal_generator import MealGenerator, MealGenerationError
# Initialize the generator (it will use the GEMINI_API_KEY environment variable)
generator = MealGenerator()
meal_description = "A grilled chicken salad with lettuce, tomatoes, cucumbers, and a light vinaigrette dressing."
try:
# Generate the meal object
meal = generator.generate_meal(meal_description)
# Print the meal's aggregated nutrient profile
print(f"Meal: {meal.name}")
print(f"Description: {meal.description}")
print("\n--- Aggregated Nutrients ---")
print(meal.nutrient_profile)
# Print details for each component
print("\n--- Meal Components ---")
for component in meal.component_list:
print(f"- {component.name} ({component.quantity}): {component.total_weight}g")
print(f" {component.nutrient_profile}")
except MealGenerationError as e:
print(f"Error generating meal: {e}")
except ValueError as e:
print(f"Input error: {e}")
Example Input & Output
Here is an example of the data generated from a specific natural language query.
Input String:
"large wrap with half a cup of rice, 100g of chilli, a tablespoon of soured cream"
Resulting meal Object Data:
The code would produce a meal object containing the following structured data:
{
"meal": {
"name": "Chilli Con Carne Wrap",
"description": "A large wheat tortilla wrap filled with chilli con carne, white rice, and a tablespoon of soured cream.",
"components": [
{
"name": "Large Wrap (Wheat Tortilla)",
"brand": null,
"quantity": "large wrap",
"totalWeight": 70.0,
"nutrientProfile": {
"energy": 220.0,
"fats": 5.0,
"saturated_fats": 1.0,
"carbohydrates": 38.0,
"sugars": 1.0,
"fibre": 2.0,
"protein": 6.0,
"salt": 0.8,
"contains_dairy": false,
"contains_high_dairy": false,
"contains_gluten": true,
"contains_high_gluten": true,
"contains_histamines": false,
"contains_high_histamines": false,
"contains_sulphites": false,
"contains_high_sulphites": false,
"contains_salicylates": false,
"contains_high_salicylates": false,
"contains_capsaicin": false,
"contains_high_capsaicin": false,
"is_processed": true,
"is_ultra_processed": true
}
},
{
"name": "Cooked White Rice",
"brand": null,
"quantity": "half a cup",
"totalWeight": 95.0,
"nutrientProfile": {
"energy": 125.0,
"fats": 0.3,
"saturated_fats": 0.1,
"carbohydrates": 28.0,
"sugars": 0.0,
"fibre": 0.3,
"protein": 2.5,
"salt": 0.0,
"contains_dairy": false,
"contains_high_dairy": false,
"contains_gluten": false,
"contains_high_gluten": false,
"contains_histamines": false,
"contains_high_histamines": false,
"contains_sulphites": false,
"contains_high_sulphites": false,
"contains_salicylates": false,
"contains_high_salicylates": false,
"contains_capsaicin": false,
"contains_high_capsaicin": false,
"is_processed": false,
"is_ultra_processed": false
}
},
{
"name": "Chilli (Con Carne/Stew)",
"brand": null,
"quantity": "100g",
"totalWeight": 100.0,
"nutrientProfile": {
"energy": 130.0,
"fats": 6.0,
"saturated_fats": 2.5,
"carbohydrates": 10.0,
"sugars": 3.0,
"fibre": 4.0,
"protein": 12.0,
"salt": 0.6,
"contains_dairy": false,
"contains_high_dairy": false,
"contains_gluten": false,
"contains_high_gluten": false,
"contains_histamines": true,
"contains_high_histamines": false,
"contains_sulphites": false,
"contains_high_sulphites": false,
"contains_salicylates": true,
"contains_high_salicylates": false,
"contains_capsaicin": true,
"contains_high_capsaicin": false,
"is_processed": true,
"is_ultra_processed": false
}
},
{
"name": "Soured Cream",
"brand": null,
"quantity": "a tablespoon",
"totalWeight": 15.0,
"nutrientProfile": {
"energy": 35.0,
"fats": 3.8,
"saturated_fats": 2.2,
"carbohydrates": 0.5,
"sugars": 0.5,
"fibre": 0.0,
"protein": 0.5,
"salt": 0.02,
"contains_dairy": true,
"contains_high_dairy": true,
"contains_gluten": false,
"contains_high_gluten": false,
"contains_histamines": true,
"contains_high_histamines": false,
"contains_sulphites": false,
"contains_high_sulphites": false,
"contains_salicylates": false,
"contains_high_salicylates": false,
"contains_capsaicin": false,
"contains_high_capsaicin": false,
"is_processed": true,
"is_ultra_processed": false
}
}
]
}
}
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file meal_generator-1.5.1.tar.gz.
File metadata
- Download URL: meal_generator-1.5.1.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95af0542ee2c26705473d86b0fd979c792c56d3d178a9c44f72771c69ddfe865
|
|
| MD5 |
af1e2c0a62d4b0066456d2c41b02469e
|
|
| BLAKE2b-256 |
39c4526fa33bca6960b4f6c489d881e2ae5749031dbf716a25926f3f2d7f0fba
|
Provenance
The following attestation bundles were made for meal_generator-1.5.1.tar.gz:
Publisher:
publish-to-pypi.yml on TomMcKenna1/meal-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
meal_generator-1.5.1.tar.gz -
Subject digest:
95af0542ee2c26705473d86b0fd979c792c56d3d178a9c44f72771c69ddfe865 - Sigstore transparency entry: 316716651
- Sigstore integration time:
-
Permalink:
TomMcKenna1/meal-generator@98c3afabbcaf2d0cb92bedd394342560ac9076ad -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TomMcKenna1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@98c3afabbcaf2d0cb92bedd394342560ac9076ad -
Trigger Event:
push
-
Statement type:
File details
Details for the file meal_generator-1.5.1-py3-none-any.whl.
File metadata
- Download URL: meal_generator-1.5.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b27b9ec2783e02d430dfedd3fa6aa0eed80407d4238454afbeea5bb114507eb
|
|
| MD5 |
45b17e52d0324423d4c631f8ff4cc882
|
|
| BLAKE2b-256 |
9e8ca00a7d35b62c49dabff82f8c2d780f9f9c885b89dfdd9b55b4a4d88bc16b
|
Provenance
The following attestation bundles were made for meal_generator-1.5.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on TomMcKenna1/meal-generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
meal_generator-1.5.1-py3-none-any.whl -
Subject digest:
3b27b9ec2783e02d430dfedd3fa6aa0eed80407d4238454afbeea5bb114507eb - Sigstore transparency entry: 316716660
- Sigstore integration time:
-
Permalink:
TomMcKenna1/meal-generator@98c3afabbcaf2d0cb92bedd394342560ac9076ad -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TomMcKenna1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@98c3afabbcaf2d0cb92bedd394342560ac9076ad -
Trigger Event:
push
-
Statement type: