Krishi AI is a plant disease diagnosis project with a Flutter mobile app and a FastAPI backend powered by a PyTorch model. The app lets you pick or capture a leaf photo, send it to the backend, and show the prediction result plus an optional Grad-CAM heatmap.
- Flutter for the mobile app
- Dart for the client logic
- FastAPI for the backend API
- PyTorch and TorchVision for inference
- OpenCV and Grad-CAM for explainability output
- PostgreSQL for diagnosis history and feedback
- Docker for backend deployment
app/Flutter applicationbackend/FastAPI server and model inference codemodel/local PyTorch model weightsdata/raw and verified image storage
- Capture a leaf photo from camera or gallery
- Upload the image to the backend for diagnosis
- Show disease name, confidence, and AI heatmap
- Submit feedback to improve future predictions
- Store diagnosis history in PostgreSQL
- Flutter 3.x or newer
- Python 3.12 or newer
- PostgreSQL database
- A trained
.pthmodel file inmodel/ - Backend environment variables configured in
backend/.env - App environment variables configured in
app/.env
Install dependencies:
cd backend
pip install -r requirements.txtCreate a backend/.env file with values like:
DATABASE_URL=postgresql://user:password@localhost:5432/krishi_ai
LOCAL_MODEL_PATH=model/best_plant_model.pth
TRAINING_API_KEY=your_training_api_key
NUM_CLASSES=38
SKIP_HEATMAP=false
PROJECT_NAME=Krishi AI BackendRun the API locally:
cd backend
uvicorn main:app --host 0.0.0.0 --port 7860 --reloadThe API will be available at:
http://localhost:7860/healthhttp://localhost:7860/api/diagnose
Install packages:
cd app
flutter pub getCreate an app/.env file and point it to your backend URL:
BASE_URL=http://10.16.25.26:5407Run the app:
cd app
flutter runIf you are testing on a physical device, make sure the backend URL is reachable from that device and update it from the app settings screen if needed.
- Start the backend server.
- Open the Flutter app.
- Tap camera or gallery to choose a plant leaf image.
- Tap Diagnose Plant.
- Review the prediction, confidence score, and heatmap.
- If the result is wrong, submit feedback from the app.
The backend includes a Dockerfile, so you can build and run it with Docker:
cd backend
docker build -t krishi-ai-backend .
docker run -p 7860:7860 --env-file .env krishi-ai-backendBefore deploying, make sure the following are available in the container or host environment:
DATABASE_URLTRAINING_API_KEYNUM_CLASSESLOCAL_MODEL_PATH
Build the Android release APK:
cd app
flutter build apk --releaseIf you want iOS or web builds, use the normal Flutter release commands for those targets.
This project is licensed under the MIT License. See LICENSE for the full text.
- The Flutter app loads its backend URL from
app/.envand also lets you update it from the settings dialog. - The backend expects image uploads as multipart form data with the
filefield. - The model must be loaded before diagnosis will work; if it is missing, the backend returns a helpful error.