
Are you curious about recreating delicious dishes from just a picture? Be My Chef AI is here to help! This project leverages advanced AI models to generate detailed recipes based on food images. By analyzing a picture of a dish, the system predicts the ingredients and provides step-by-step cooking instructions to recreate it.
Check out the live version of the project here.
Upload an image, and watch as the AI generates a complete recipe for you!
- Image-Based Ingredient Prediction: Upload a food image, and the AI predicts the ingredients present.
- Recipe Generation: Generates a detailed recipe with a title, ingredients list, and cooking instructions.
- Multiple Chef Models: Choose between different chef personas for varied recipe styles.
- User-Friendly Interface: Easy-to-use interface built with Streamlit.
The application uses a combination of Convolutional Neural Networks (CNNs) and Transformer models:
- CNN Encoder: Processes the input food image to extract visual features.
- Ingredient Decoder: Predicts the ingredients present in the dish.
- Transformer Decoder: Generates the cooking instructions based on the predicted ingredients and image features.
Download and install Miniconda from the official website suitable for your operating system.
You need to download three essential files for the model to function:
- Model Weights: Download
modelbest.ckpt
- Ingredients Vocabulary: Download
ingr_vocab.pkl
- Instruction Vocabulary: Download
instr_vocab.pkl
Place these files in the Foodimg2Ing/data/
directory within your project folder.
git clone https://github.com/GaneshAdimalupu/Recipe-Generation-from-Food-Image.git
cd Recipe-Generation-from-Food-Image
conda create -n chef python=3.10.16
conda activate chef
pip install -r requirements.txt
Start the Streamlit app by running:
streamlit run app.py
After running this command, you will see output similar to:
You can now view your Streamlit app in your browser.
Local URL: http://localhost:8501
Network URL: http://192.168.X.XXX:8501
Open the Local URL in your web browser to interact with the app.
- Upload a Food Image: Click on "Choose a food image" and select an image (jpg, jpeg, or png).
- View Uploaded Image: The app will display the image you've uploaded.
- Ingredient Prediction: The app processes the image and predicts the ingredients.
- Select Chef Model: Choose between "Chef Scheherazade" or "Chef Giovanni" for different recipe styles.
- Generate Recipe: Click on "Get Recipe!" to generate the recipe.
- View Recipe: The app will display the recipe title, ingredients list, and cooking instructions.
Since the test set is not available, we will evaluate the model based on a shared test set. This test set consists of 5% of the whole test (= 5,000 records), and we will generate five recipes for each input(= 25,000 records). The following table summarizes the scores obtained by the Chef Transformer and RecipeNLG as our baseline.
Model | COSIM | WER | ROUGE-2 | BLEU | GLEU | METEOR |
---|---|---|---|---|---|---|
RecipeNLG | 0.5723 | 1.2125 | 0.1354 | 0.1164 | 0.1503 | 0.2309 |
Chef Transformer * | 0.7282 | 0.7613 | 0.2470 | 0.3245 | 0.2624 | 0.4150 |
From the 5 generated recipes corresponding to each NER (food items), only the highest score was taken into account in the WER, COSIM, and ROUGE metrics. At the same time, BLEU, GLEU, Meteor were designed to have many possible references.
Then follow the steps mentioned in this contributing guide and you are good to go.
Special thanks to those who provided these fantastic materials.
- Use GPU: If your system supports GPU acceleration, PyTorch will automatically leverage it for faster model inference.
- Run on Cloud: You can deploy this app on platforms like Heroku, AWS, or Google Cloud for production-level scaling.
- Batch Processing: For processing multiple images at once, consider batching inputs to optimize performance.
- ModuleNotFoundError: If you encounter errors about missing modules, ensure that all dependencies are installed and that your Python environment is correctly set up.
- FileNotFoundError for Model Files: Verify that
modelbest.ckpt
,ingr_vocab.pkl
, andinstr_vocab.pkl
are placed in the correct directory (Foodimg2Ing/data/
). - AttributeError in Streamlit: If you receive errors like
'NoneType' object has no attribute 'format'
, ensure that the image generation function returns a valid image URL or handle cases where the image may beNone
. - CUDA Errors: If you encounter CUDA-related warnings and you don't have a GPU or prefer to run on CPU, you can disable CUDA by setting the environment variable before running the app:
export CUDA_VISIBLE_DEVICES=-1
- Port Already in Use: If Streamlit indicates that the default port 8501 is in use, specify a different port:
streamlit run app.py --server.port 8502
- Real-time Recipe Adjustments: Dynamically adjust recipes based on user preferences or dietary restrictions.
- Cultural Integration: Tailor recipes based on regional or cultural preferences.
- Voice Commands: Allow users to upload images and get recipes via voice commands.
- Mobile App: Convert the web app to a mobile app for easier accessibility.
You can easily deploy this app to Heroku by following these steps:
- Install the Heroku CLI: https://devcenter.heroku.com/articles/heroku-cli
- Login to Heroku:
heroku login
- Create a new Heroku app:
heroku create your-app-name
- Push the code:
git push heroku main
For full deployment instructions, visit Heroku's Documentation.
This project is built upon the efforts of the following repositories:
- Recipe Generation from Food Image by navassherif98
- Recipe Generation from Food Image by navassherif98
- Chef Transformer by chef-transformer
- Chef Transformer by chef-transformer
This project is licensed under the MIT License. See the LICENSE file for details.
- The model is inspired by the work from Inverse Cooking: Recipe Generation from Food Images.
- Thanks to the developers of Streamlit for providing an easy way to build web apps.
For any inquiries or support, please contact:
- Ganesh Adimalupu
- Email: [email protected]
- GitHub: GaneshAdimalupu