This is a simple web application built with Streamlit that allows you to calculate the calorie content of a meal by uploading an image of it. The application uses the OpenAI GPT-4 Vision model to analyze the image, identify the food items, and estimate their calorie counts.
The application leverages the power of OpenAI's vision capabilities. When you upload an image of your food:
- The image is sent to the GPT-4 Vision API.
- A prompt is provided to the model asking it to act as an expert nutritionist.
- The model analyzes the image to identify each food item present.
- It then calculates the estimated calories for each item and provides a total calorie count for the meal.
- The results are displayed in a clear and easy-to-read format.
To run this application locally, you'll need to follow these steps:
- Python 3.7+
- An OpenAI API key with access to the GPT-4 Vision model.
git clone <repository-url>
cd Chatbot-TrackerIt's recommended to use a virtual environment to manage project dependencies.
-
For macOS/Linux:
python3 -m venv venv source venv/bin/activate -
For Windows:
python -m venv venv .\venv\Scripts\activate
Install all the required Python packages using the requirements.txt file.
pip install -r requirements.txtThe application requires your OpenAI API key to function. Create a file named .env in the root of the project directory and add your API key to it.
OPENAI_API_KEY="your-openai-api-key-here"
Note: Your API key is sensitive information. Do not commit the .env file to version control. The included .gitignore file should already be configured to ignore it.
Once the setup is complete, you can run the Streamlit application with the following command:
streamlit run app.pyThis will start a local web server, and you can access the application in your browser at the URL provided in the terminal (usually http://localhost:8501).
- Open the application in your web browser.
- Click the "Upload an image of your food..." button to select an image file (JPG, JPEG, or PNG).
- Once the image is uploaded and displayed, click the "Calculate Calories" button.
- The application will process the image and display the calorie details for each food item and the total.
This project relies on the following Python libraries:
streamlit: For creating the web application interface.langchain-openai: For interacting with the OpenAI API.python-dotenv: For managing environment variables.Pillow: For image manipulation.langchain: Core LangChain library for building language model applications.