Author: Mohanad Mallooki
SmartRecipeApp is a web-based application that combines deep learning image classification and recipe recommendation.
It identifies fruits or vegetables from an uploaded image and recommends recipes containing that ingredient using the Spoonacular API.
This project integrates:
- π§© TensorFlow (MobileNetV2) β Transfer learning model for image recognition
- π§ͺ Streamlit β Interactive web application for deployment
- π Spoonacular API β Recipe search and filtering by calories, protein, sugar, and type
- π Python data pipeline β Image preprocessing, feature extraction, and prediction logic
SmartRecipeApp/ β βββ model/ β βββ train_model.py # Training script using MobileNetV2 transfer learning β βββ fruit_model.h5 # Trained model file (generated after training) β βββ labels.json # Class label map (generated after training) β βββ Data/ β βββ Training/ # Training images (each class = folder name) β βββ Test/ # Validation images β βββ streamlit_app.py # Main Streamlit web app βββ requirements.txt # Python dependencies (TensorFlow + Streamlit) βββ README.md # Project documentation βββ .streamlit/ βββ secrets.toml # API key storage (not committed to Git)
-
Model Training
- Uses MobileNetV2 pretrained on ImageNet.
- Fine-tunes the last layers to classify fruits and vegetables.
- The model is trained using images organized by folder structure:
Data/Training/apple/ Data/Training/banana/ Data/Training/tomato/ - The trained model is saved as:
model/fruit_model.h5 model/labels.json
-
Prediction Phase
- The Streamlit app loads the trained model and class labels.
- Users upload an image of a fruit or vegetable.
- The model predicts the ingredient name (e.g., βBananaβ).
- The app queries Spoonacular API to recommend recipes using that ingredient.
-
Recipe Filtering
- Users can filter recipes by:
- Calories per serving
- Number of servings
- Protein range
- Sugar range
- Recipe type (Sweet, Savory, Snack, Drink, etc.)
- Users can filter recipes by:
-
Results Display
- Streamlit displays a list of matching recipes with titles, links, and images.
git clone https://github.com/<your-username>/SmartRecipeApp.git
cd SmartRecipeApp
2οΈβ£ Create Virtual Environment
python -m venv .venv
.venv\Scripts\activate # (Windows)
source .venv/bin/activate # (Mac/Linux)
3οΈβ£ Install Dependencies
pip install -r requirements.txt
4οΈβ£ Prepare Dataset
Organize your dataset into subfolders (each representing a class):
Data/
βββ Training/
β βββ apple/
β βββ banana/
β βββ carrot/
βββ Test/
βββ apple/
βββ banana/
βββ carrot/
5οΈβ£ Train the Model
cd model
python train_model.py
This generates fruit_model.h5 and labels.json.
6οΈβ£ Run the Streamlit App
cd ..
streamlit run streamlit_app.py
βοΈ Deployment (Streamlit Cloud)
Push your project to GitHub.
Go to Streamlit Cloud
.
Connect your GitHub repo and select the streamlit_app.py file.
Under App Settings β Advanced, set:
Python version: 3.11
Dependencies: Use requirements.txt
Add your Spoonacular API key in Streamlitβs Secrets Manager:
[general]
SPOONACULAR_API_KEY = "your_actual_api_key"
π§ Model Architecture (MobileNetV2)
Input (224Γ224Γ3)
β
MobileNetV2 (pretrained on ImageNet)
β
GlobalAveragePooling2D
β
Dense(256, ReLU)
β
Dropout(0.5)
β
Dense(N, Softmax)
Base model: MobileNetV2 (frozen for first training phase)
Optimizer: Adam (lr = 0.001 β fine-tuned at 1e-5)
Loss: Categorical Cross-Entropy
Epochs: 10 (frozen) + 10 (fine-tuned)
Metrics: Accuracy
π Example Output
Input: Image of a banana π
Model Prediction: Banana (98.2% confidence)
Recipe Results:
Banana Smoothie
Chocolate Banana Bread
Peanut Butter Banana Oats
π§Ύ Requirements
Package Version
TensorFlow 2.15.0
Streamlit 1.39.0
NumPy Latest
Pillow Latest
Requests Latest
π§© Future Enhancements
π³ Add ingredient detection for mixed dishes.
π§ Incorporate nutritional prediction from image (calories, macros).
π£οΈ Enable voice or text input to combine ingredients.
π± Optimize for mobile view.
π License
MIT License β Free for educational and research use.
π Acknowledgements
TensorFlow Team for MobileNetV2 pretrained weights
Spoonacular API for recipe data
Streamlit for rapid web app development
Eastern University β DTSC691 for providing the academic foundation for this capstone project
---
## πͺ Notes for You
- You can edit the author line or add your student ID for submission.
- The βFuture Enhancementsβ section is optional but adds a strong academic touch.
- Once this file is saved as `README.md` in your repo root, GitHub and Streamlit Cloud will both display it beautifully.
---
Would you like me to add a short **βProject Abstractβ** section at the top (for academic submission β about 5β6 lines summarizing purpose, methods, and outcome)? It helps for DTSC691 documentation.