Skip to content

CaueGrassi7/leaflens-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LeafLens AI 🌿

A Universal Plant Disease Detection System powered by Deep Learning (MobileNetV2).

Python TensorFlow FastAPI Next.js Docker Tailwind CSS


πŸ“– About the Project

LeafLens AI is an end-to-end machine learning solution that detects plant diseases across multiple species using a single, universal deep learning model. Built with a modern tech stack, this project demonstrates a complete ML pipeline from data preparation and model training to deployment as a production-ready web application.

🌟 Key Highlights

  • Universal Model Architecture: A single MobileNetV2-based model capable of detecting diseases across multiple plant species (Apple, Cherry, Corn, Grape, Peach, Pepper, Potato, Tomato, and more), eliminating the need for species-specific models.

  • Confidence Threshold Safety: Implements a smart confidence threshold (70% default) that filters out non-plant images and low-confidence predictions, addressing the "Open World" problem in production ML systems.

  • Dynamic Model Loading: The backend dynamically loads model files and class names from JSON configuration, making it easy to update models without code changes.


✨ Key Features

  • 🐳 Dockerized: One command to run the entire stack (backend + frontend)
  • ⚑ Real-time Inference: Fast predictions using optimized MobileNetV2 architecture
  • 🎨 Modern UI: Beautiful drag-and-drop interface with instant feedback and dark mode support
  • 🧠 Smart Processing: Backend dynamically loads models and class names from JSON
  • πŸ”’ Production-Ready: Comprehensive error handling, logging, and health checks
  • πŸ“Š RESTful API: Well-documented FastAPI with automatic OpenAPI/Swagger documentation

πŸš€ How to Run

Prerequisites

Quick Start with Docker (Recommended)

  1. Clone the repository

    git clone https://github.com/cauegrassi7/leaflens-ai.git
    cd leaflens-ai
  2. Start the application

    docker-compose up --build
  3. Access the application

The Docker setup automatically:

  • Builds both backend and frontend containers
  • Mounts the ML models directory for the backend
  • Sets up proper networking between services
  • Includes health checks and auto-restart policies

Local Development (Alternative)

Backend Setup

# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Run the backend server
uvicorn backend.app.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

cd frontend

# Install dependencies
npm install

# Run development server
npm run dev

πŸ“ Project Structure

leaflens-ai/
β”œβ”€β”€ backend/                 # FastAPI backend application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/            # API route handlers
β”‚   β”‚   β”œβ”€β”€ core/           # Configuration and settings
β”‚   β”‚   β”œβ”€β”€ schemas/        # Pydantic response models
β”‚   β”‚   β”œβ”€β”€ services/       # Business logic layer
β”‚   β”‚   └── main.py         # FastAPI application entry point
β”‚   β”œβ”€β”€ Dockerfile          # Backend container definition
β”‚   └── run.py              # Backend startup script
β”‚
β”œβ”€β”€ frontend/               # Next.js frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── app/            # Next.js app directory
β”‚   β”‚       β”œβ”€β”€ page.tsx    # Main application page
β”‚   β”‚       └── layout.tsx  # Root layout component
β”‚   β”œβ”€β”€ Dockerfile          # Frontend container definition
β”‚   └── package.json        # Node.js dependencies
β”‚
β”œβ”€β”€ ml/                     # Machine learning pipeline
β”‚   β”œβ”€β”€ data/               # Training and validation datasets
β”‚   β”‚   └── raw/
β”‚   β”‚       β”œβ”€β”€ train/      # Training images (organized by class)
β”‚   β”‚       └── val/        # Validation images (organized by class)
β”‚   β”œβ”€β”€ models/             # Trained model files
β”‚   β”‚   β”œβ”€β”€ plant_disease_model_vuniversal_v1.keras
β”‚   β”‚   └── classes_vuniversal_v1.json
β”‚   β”œβ”€β”€ notebooks/          # Jupyter notebooks for exploration
β”‚   β”‚   β”œβ”€β”€ 1_data_exploration.ipynb
β”‚   β”‚   └── 2_model_training.ipynb
β”‚   └── scripts/
β”‚       └── train.py        # Model training script
β”‚
β”œβ”€β”€ docker-compose.yml      # Docker Compose configuration
β”œβ”€β”€ requirements.txt        # Python dependencies
└── README.md              # This file

Directory Purpose

  • ml/: Contains the complete ML pipeline including data preprocessing, model training scripts, and trained model artifacts. The training pipeline uses TensorFlow/Keras to build a MobileNetV2-based classifier.
  • backend/: FastAPI REST API that serves model predictions. Handles image preprocessing, model inference, and response formatting with proper error handling.
  • frontend/: Next.js 16 application with TypeScript and Tailwind CSS. Provides an intuitive drag-and-drop interface for uploading plant images and displaying prediction results.

πŸ“Έ Screenshots

Home Screen

The intuitive drag-and-drop interface makes it easy to upload plant images for analysis.

Home Screen

Prediction Result

Real-time disease detection with confidence scores and detailed information.

Prediction Result


πŸ”Œ API Endpoints

GET /

Root endpoint providing API metadata, version information, and available endpoints.

GET /health

Health check endpoint. Returns system status and model loading state.

Response:

{
  "status": "healthy",
  "classes_count": 38
}

POST /predict

Upload an image file to get a plant disease prediction.

Request: multipart/form-data with file field containing an image

Response (High Confidence):

{
  "class_name": "Tomato___Bacterial_spot",
  "confidence": 0.95
}

Response (Low Confidence):

{
  "class_name": "Unidentified",
  "confidence": 0.45,
  "low_confidence": true,
  "message": "Model confidence (45%) was too low. The image may not be of a known plant."
}

GET /docs

Interactive API documentation (Swagger UI)

GET /redoc

Alternative API documentation (ReDoc)


πŸ› οΈ Technology Stack

Backend

  • FastAPI: Modern, fast web framework for building APIs
  • TensorFlow/Keras: Deep learning framework for model inference
  • Pillow: Image processing library
  • Uvicorn: ASGI server for FastAPI

Frontend

  • Next.js 16: React framework with App Router
  • TypeScript: Type-safe JavaScript
  • Tailwind CSS 4: Utility-first CSS framework
  • Axios: HTTP client for API requests
  • Lucide React: Modern icon library

Machine Learning

  • TensorFlow 2.18: Deep learning framework
  • Keras 3.3+: High-level neural networks API
  • MobileNetV2: Efficient CNN architecture for mobile/edge devices
  • NumPy: Numerical computing
  • Pandas: Data manipulation and analysis

DevOps

  • Docker: Containerization
  • Docker Compose: Multi-container orchestration

πŸ“ License

This project is licensed under the terms specified in the LICENSE file.


🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


πŸ“§ Contact

For questions or inquiries, please open an issue on GitHub.


Built with ❀️ using Python, TensorFlow, FastAPI, and Next.js

About

End-to-end AI application for plant disease detection using Deep Learning (CNNs). Built with FastAPI, TensorFlow, and Next.js.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors