Smart Soil & Crop Health Advisor for African Farmers
# π± AgroSenseAI Backend - Crop Disease & Pest Detection API
This is the **backend service** of AgroSenseAI β a smart agriculture system that leverages machine learning to help farmers detect crop diseases and pests from images, and optionally analyze soil fertility using NPK sensor data.
Built with **FastAPI** and **PyTorch**, this backend provides clean and ready-to-use APIs to power modern precision farming solutions.
## π Features
- π§ **Crop Disease & Pest Detection** using ML models
- π€ **Image Upload API** with predictions in JSON
- π¦ **Dockerized** for easy deployment
- π **Auto-generated API docs** via Swagger (FastAPI)
## π§° Backend Tech Stack
- **Backend Framework**: FastAPI
- **Machine Learning**: PyTorch, Torchvision
- **Image Handling**: Pillow
- **API Validation**: Pydantic
- **Containerization**: Docker
- **Deployment**: Render, Railway, or any Docker-supported cloud
## π Project Structure
app/
βββ main.py # FastAPI entry point
βββ routes/ # API route handlers
βββ services/ # Model prediction logic
βββ models/ # Saved ML model files
βββ utils/ # Preprocessing tools
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker container setup
βββ README.md # Project documentation
## π API Endpoints
| Method | Endpoint | Description |
| ------ | ----------------- | --------------------------------- |
| POST | `/disease/detect` | Detect crop disease from an image |
| POST | `/pest/detect` | Detect pests from a crop image |
| GET | `/docs` | Swagger UI (API documentation) |
> All image uploads should be sent as `multipart/form-data`
## π³ Run with Docker
```bash
# Build Docker image
docker build -t agrosenseai-backend .
# Run container locally
docker run -p 8000:8000 agrosenseai-backend
```
API available at:
π
localhost
---
## π¦ Run Locally Without Docker
```bash
git clone
github.com
cd agrosense-backend
pi β¦