In today’s health-conscious world, understanding what we eat is crucial for maintaining a balanced lifestyle. Imagine an app that can analyze your meals just by looking at a photo — providing detailed calorie counts, nutritional breakdowns, and health assessments instantly. This exactly helps to build by leveraging the power of Google Gemini Pro Vision API.
Motivated by personal health goals and a passion for balanced nutrition, developed a food calorie and nutrition analysis app from scratch. The app enables users to upload images of their meals and receive comprehensive insights about calorie content, individual food items, and overall meal healthiness.
This Blog showcases how artificial intelligence, particularly computer vision combined with prompt engineering, can transform how we approach nutrition.
The app offers an intuitive, seamless experience built around these key functions:
Developing this AI-powered nutrition app involves below orchestrated steps:
Step | Description | Key Actions |
1 | Environment Setup | Create Python virtual environment (conda create -n vnv python=3.10) |
2 | Library Installation | Install dependencies (streamlit, google-generativeai, dotenv) |
3 | API Key Configuration | Secure API keys in .env and load them safely |
4 | Code Architecture | Build modular functions for image processing, API calls, and UI |
5 | Image Processing | Convert images to byte format compatible with the API |
6 | Prompt Design | Develop detailed prompts for precise nutrition analysis |
7 | Streamlit UI | Create a simple interface for image upload and result display |
8 | API Interaction & Response Handling | Send requests, parse responses, and update UI dynamically |
Here are some snippets that illustrate key parts of the app:
import streamlit as st import google.generativeai as gen import os from dotenv import load_dotenv load_dotenv() gen.configure(api_key=os.getenv("GOOGLE_API_KEY"))
uploaded_file = st.file_uploader("Choose an image", type=["jpg", "png"]) if uploaded_file: image_bytes = uploaded_file.read() image_data = {"mime_type": uploaded_file.type, "data": image_bytes}
def get_nutrition_response(prompt, image_part): model = gen.Model("gini Pro Vision") response = model.generate_content(prompt=prompt, image=image_part) return response.text
if st.button("Analyze Calories"): prompt = "You are an expert in nutrition. Analyze the food items in the image..." result = get_nutrition_response(prompt, image_data) st.write(result)
By entering Input Prompt and Uploading a meal image (.png, .jpg, .jpeg), will get an estimation of total calories in the meal.
As health tech continues to evolve, combining AI-driven image recognition with nutritional expertise promises to revolutionize personal wellness. This journey in building this calories and nutrition app shows how accessible and impactful such technology can be.
This would help to start building your own smart health tools today.
Neha Vittal Annam