Skip to content

hill0106/Fruit-Vegetable-Classification

Repository files navigation

Fruit & Vegetable Classification (Streamlit)

Classify an image as a fruit or vegetable and get an estimated calorie value per 100g. Built with TensorFlow/Keras and a Streamlit UI.

Highlights

  • Streamlit app: upload image or use webcam
  • 36 classes: common fruits and vegetables
  • Calorie lookup: quick nutrition estimate (per 100g)

Tech Stack

  • Model: TensorFlow/Keras (version3.h5)
  • App: Streamlit + Pillow + NumPy

Repo Structure

  • app.py: Streamlit app
  • version3.h5: trained Keras model
  • requirements.txt: pinned dependencies
  • Procfile, setup.sh: deploy helpers

Quick Start

  1. Create and activate a virtual environment (recommended)
python3 -m venv .venv && source .venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Ensure the model file exists
  • The repo includes version3.h5 in the project root.
  • In app.py, update the model path to point to the local file if needed. Example:
# app.py (top of file)
model = load_model('version3.h5')  # make sure this path is correct
  1. Run the Streamlit app
streamlit run app.py

Then open the local URL that Streamlit prints (usually http://localhost:8501).

Usage

  • Upload a JPG/PNG/JPEG image, or capture one with the webcam widget.
  • Click "Predict" to see the predicted class and estimated calories per 100g.

Supported Classes (examples)

Apples, Bananas, Grapes, Kiwi, Lemon, Mango, Orange, Pear, Pineapple, Pomegranate, Watermelon, Beetroot, Bell Pepper, Chilli Pepper, Jalapeño, Cabbage, Paprika, Capsicum, Carrot, Cauliflower, Corn, Cucumber, Eggplant, Ginger, Lettuce, Onion, Peas, Potato, Radish, Soy Beans, Spinach, Sweetcorn, Sweet Potato, Tomato, Turnip.

Deployment

  • With the provided Procfile, you can adapt for platforms that support Procfiles. For Streamlit on Render or similar, set start command to:
streamlit run app.py --server.port $PORT --server.address 0.0.0.0

Troubleshooting

  • If you see a path error for the model, verify model = load_model('version3.h5') points to the actual file location.
  • If wheels fail to build for TensorFlow on Apple Silicon, ensure you use Python 3.9–3.10 per tensorflow==2.8.0, or upgrade TF and adjust versions accordingly.

License

MIT (or project’s original license). Update this section if different.