Skip to content

Smart app that suggest a recipe for the picture of any uploaded picture of fruits or vegetables

Notifications You must be signed in to change notification settings

muhand4u/SmartRecipeApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯— SmartRecipeApp β€” AI-Powered Food Recommender

Graduate Data Science Project β€” DTSC691

Author: Mohanad Mallooki


🧠 Overview

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

πŸš€ Project Structure

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)


βš™οΈ How It Works

  1. 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
      
  2. 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.
  3. Recipe Filtering

    • Users can filter recipes by:
      • Calories per serving
      • Number of servings
      • Protein range
      • Sugar range
      • Recipe type (Sweet, Savory, Snack, Drink, etc.)
  4. Results Display

    • Streamlit displays a list of matching recipes with titles, links, and images.

🧰 Installation & Setup

1️⃣ Clone the Repository

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.

About

Smart app that suggest a recipe for the picture of any uploaded picture of fruits or vegetables

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages