A Flask web app that identifies medicinal (Ayurvedic) plant leaves from a photo using a Teachable Machine-trained image classification model.
LeafLogic lets a user upload a photo of a leaf and get back an instant prediction of which medicinal plant it is, along with a confidence score. It's aimed at anyone curious about Ayurvedic herbs — students, hobbyist gardeners, or practitioners — who wants a quick way to identify a leaf without manual lookup.
Key features:
- Upload-and-classify leaf identification via a trained image model
- Rejects non-leaf images (e.g. selfies/photos containing a face) using face detection as a guardrail
- Ayurvedic-themed informational landing page (about, uses, contact)
- Standalone real-time webcam classification script for local experimentation
Backend
- Python 3
- Flask — web server and routing
- TensorFlow / tf-keras — loads and runs the trained classification model
- OpenCV (
opencv-python) — image decoding, resizing, and face detection (Haar cascade) - NumPy — image array processing
Frontend
- HTML5 + vanilla JavaScript (
fetchAPI for async prediction requests) - Bootstrap 4 (via CDN)
- Custom CSS
Machine Learning
- Model exported from Teachable Machine (
model/keras_model.h5), loaded throughtf_kerasfor compatibility with modern TensorFlow
LEAFLOGIC/
├── app.py # Flask app: routes, model loading, prediction endpoint
├── model/
│ ├── keras_model.h5 # Trained Teachable Machine image classifier
│ └── labels.txt # Class labels the model predicts
├── scripts/
│ └── webcam_predict.py # Standalone real-time webcam classification script
├── static/
│ ├── style.css
│ ├── mediaqueries.css
│ ├── script.js
│ └── *.png / *.jpg # Site images
├── templates/
│ └── index.html # Main page template
├── requirements.txt
├── .env.example
├── .gitignore
└── README.md
- Python 3.10+ (tested on Python 3.12)
- pip
- ~2 GB of free disk space (TensorFlow and its dependencies are the bulk of this)
- A webcam (only required to run
scripts/webcam_predict.py; not needed for the web app)
-
Clone the repository
git clone <your-repo-url> cd LEAFLOGIC
-
Create and activate a virtual environment
macOS/Linux:
python3 -m venv venv source venv/bin/activateWindows:
python -m venv venv venv\Scripts\activate -
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env
Defaults work out of the box — you only need to edit
.envif you want to change the port or enable debug mode. -
Run the app
python app.py
-
Open your browser at http://127.0.0.1:5000
Scroll to the "Prediction" section, upload an image, and click Classify. The image is sent to the /predict endpoint, which:
- Rejects the image if a face is detected in it (basic guard against non-leaf photos)
- Resizes and normalizes the image to match the model's expected input
- Runs inference and returns the predicted leaf name with a confidence score
Supported classes (see model/labels.txt): Mexican Mint, Neem, Peepal Leaf, Mint Leaf (Pudina), Papaya Leaf, plus fallback classes for "No Leaf Detected" and "Not a Medicinal Plant".
[Screenshot placeholder — add image here]
scripts/webcam_predict.py opens your default webcam and prints live predictions to the terminal as you hold leaves up to the camera. Run it with:
python scripts/webcam_predict.pyPress q to quit.
[Screenshot placeholder — add image here]
The homepage includes sections about Ayurvedic Pharmaceutics, common uses (stress management, skin/hair care, pain relief, etc.), and contact info.
[Screenshot placeholder — add image here]
| Method | Route | Description |
|---|---|---|
| GET | / |
Renders the main HTML page |
| POST | /predict |
Accepts a multipart form image (image field), returns JSON with leaf_name and accuracy_score |
Example /predict response:
{
"leaf_name": "Neem",
"accuracy_score": 92.15
}- Add a proper "Benefits" data source (currently a placeholder link in the UI) mapped per leaf class
- Replace the Haar-cascade face check with a more robust "is this actually a leaf" classifier
- Add automated tests for the
/predictendpoint and CI to catch dependency/model-loading regressions early
Licensed under the MIT License.