A full-stack AI application for detecting and classifying lemon leaf diseases from uploaded images using deep learning.
This project allows users to upload a lemon leaf image through a web interface and receive a disease prediction with confidence scores. It combines:
- a FastAPI backend for model inference
- a Next.js frontend for the user interface
- a deep learning classification model
- Docker Compose for running the full stack locally
- a research notebook for training and experimentation
Lemon leaf diseases can reduce plant health and crop quality if they are not identified early. Manual identification can be slow and inconsistent. This project provides a simple AI-based system that helps classify lemon leaf diseases from images in a faster and more accessible way.
- Upload lemon leaf images from the frontend
- Predict leaf disease using a trained deep learning model
- View confidence score and class probabilities
- FastAPI backend with clear API endpoints
- Next.js frontend with responsive UI
- Docker support for running backend and frontend together
- Research notebook for model training and experimentation
- FastAPI
- Python
- PyTorch
- Pillow
- Next.js
- TypeScript
- Tailwind CSS
- React
- Docker
- Docker Compose
- GitHub Actions
- Jupyter Notebook
- Kaggle / experimentation workflow
LEMON LEAF DISEASE DETECTION/
ββ backend/
β ββ app/
β β ββ __init__.py
β β ββ inference.py
β β ββ main.py
β ββ fastapi_artifacts/
β β ββ class_names.json
β β ββ ensemble_bundle.pth
β β ββ inference_config.json
β ββ .dockerignore
β ββ .env.example
β ββ Dockerfile
β ββ requirements.txt
β ββ start.sh
β
ββ frontend/
β ββ app/
β β ββ globals.css
β β ββ layout.tsx
β β ββ page.tsx
β ββ components/
β β ββ Footer.tsx
β β ββ Header.tsx
β β ββ HealthBadge.tsx
β β ββ ResultCard.tsx
β ββ lib/
β β ββ api.ts
β ββ types/
β β ββ api.ts
β ββ .env.example
β ββ Dockerfile
β ββ package.json
β ββ tsconfig.json
β
ββ research/
β ββ notebooks/
β ββ lemon-leaf-disease-kaggle-final.ipynb
β
ββ .github/
β ββ workflows/
β ββ backend-ci.yml
β ββ frontend-ci.yml
β
ββ docker-compose.yml
ββ README.md
-
The user uploads a lemon leaf image from the frontend
-
The frontend sends the image to the FastAPI backend
-
The backend preprocesses the image
-
The trained model performs inference
-
The backend returns:
- predicted class
- confidence score
- class probabilities
-
The frontend displays the result in a clean UI
Make sure these are installed:
- Python 3.10+
- Node.js 18+ or 20+
- npm
- Docker Desktop
- Git
cd backend
python -m venv .venv.venv\Scripts\activatesource .venv/bin/activatepip install -r requirements.txtuvicorn app.main:app --reload --host 0.0.0.0 --port 8000- API Root:
http://localhost:8000 - Health Check:
http://localhost:8000/health - Swagger Docs:
http://localhost:8000/docs
cd frontend
npm installCreate frontend/.env.local:
NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8000npm run dev- Frontend App:
http://localhost:3000
From the project root:
docker compose up --build- Frontend:
http://localhost:3000 - Backend:
http://localhost:8000 - Backend Docs:
http://localhost:8000/docs - Health Check:
http://localhost:8000/health
docker compose downdocker compose down
docker compose up --buildNote: If your backend uses a large model file, the first startup may take time depending on how the model is loaded or downloaded.
Returns basic API information.
Checks whether the backend is running and whether the model is loaded.
Accepts an uploaded image file and returns prediction results.
- Content-Type:
multipart/form-data - Field name:
file
{
"filename": "leaf.jpg",
"predicted_class": "Citrus Canker",
"confidence": 0.94,
"class_probabilities": {
"Anthracnose": 0.01,
"Bacterial Blight": 0.02,
"Citrus Canker": 0.94,
"Curl Virus": 0.01,
"Deficiency Leaf": 0.00,
"Dry Leaf": 0.00,
"Healthy Leaf": 0.01,
"Sooty Mould": 0.00,
"Spider Mites": 0.01
}
}The backend uses a trained image classification model for lemon leaf disease prediction.
Located in:
backend/fastapi_artifacts/
Important files:
ensemble_bundle.pthclass_names.jsoninference_config.json
- load trained model at startup
- preprocess uploaded image
- run prediction
- return class probabilities and confidence score
For deployment, large model files may need to be downloaded externally or handled separately from the main GitHub repository.
Training, experimentation, and model development are kept in:
research/notebooks/lemon-leaf-disease-kaggle-final.ipynb
This notebook contains the model training and research workflow used for the project.
File: frontend/.env.local
NEXT_PUBLIC_API_BASE_URL=http://127.0.0.1:8000Use .env or .env.example if needed for deployment-related configuration.
This project includes GitHub Actions workflows for checking backend and frontend changes.
backend-ci.ymlfrontend-ci.yml
These workflows help validate the project structure and build process.
Mahmudul Haque Sakib
GitHub: https://github.com/your-username
LinkedIn: https://linkedin.com/in/your-profile
Portfolio: https://mhsakib.vercel.app
cd backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd frontend
npm install
npm run devdocker compose up --build

