Skip to content

madjacksparrow/leaflogic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeafLogic

A Flask web app that identifies medicinal (Ayurvedic) plant leaves from a photo using a Teachable Machine-trained image classification model.

Overview

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

Tech Stack

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 (fetch API for async prediction requests)
  • Bootstrap 4 (via CDN)
  • Custom CSS

Machine Learning

  • Model exported from Teachable Machine (model/keras_model.h5), loaded through tf_keras for compatibility with modern TensorFlow

Project Structure

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

Prerequisites

  • 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)

Getting Started — How to Run Locally

  1. Clone the repository

    git clone <your-repo-url>
    cd LEAFLOGIC
  2. Create and activate a virtual environment

    macOS/Linux:

    python3 -m venv venv
    source venv/bin/activate

    Windows:

    python -m venv venv
    venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    cp .env.example .env

    Defaults work out of the box — you only need to edit .env if you want to change the port or enable debug mode.

  5. Run the app

    python app.py
  6. Open your browser at http://127.0.0.1:5000

Features

Leaf Prediction

Scroll to the "Prediction" section, upload an image, and click Classify. The image is sent to the /predict endpoint, which:

  1. Rejects the image if a face is detected in it (basic guard against non-leaf photos)
  2. Resizes and normalizes the image to match the model's expected input
  3. 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]

Real-Time Webcam Classification

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.py

Press q to quit.

[Screenshot placeholder — add image here]

Informational Landing Page

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]

API Endpoints

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
}

Future Improvements

  • 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 /predict endpoint and CI to catch dependency/model-loading regressions early

License

Licensed under the MIT License.

About

Flask + Teachable Machine web app that identifies Ayurvedic medicinal leaves from a photo

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors