Project

Crop Cure — Grape Disease Detection via WhatsApp

A WhatsApp bot that classifies grape-leaf diseases from photos and replies with multilingual treatment guidance.

Deep Learning Jun 1, 2025 3 min read
FastAPI PyTorch WhatsApp Docker GCP

Status

This project is not under active maintenance right now. The core workflow and deployment setup are documented here, but some parts of the implementation may need cleanup before production use.

Problem

Farmers often need disease guidance from the device they already use most: WhatsApp. Crop Cure was built as a lightweight diagnosis flow where a farmer can send a grape-leaf image, get a prediction, and receive treatment guidance in a familiar chat interface.

What the Bot Does

  • Accepts a grape-leaf image over WhatsApp
  • Classifies the image with a custom ResNet9 hybrid model
  • Returns the disease label, symptoms, and treatment options
  • Supports English, Marathi, and Hindi
  • Can attach product recommendations through WhatsApp buttons

System Flow

User (WhatsApp)
|
v
WhatsApp Cloud API
|
v
FastAPI backend
|- pywa_async for message handling
|- googletrans for translation
|- src/model.py for inference
`- src/dict.py for disease and treatment content

Supported Classes

DiseaseClass name
Black RotGrape__Black_rot
Esca (Black Measles)Grape__Esca_(Black_Measles)
Leaf Blight (Isariopsis Leaf Spot)Grape__Leaf_blight_(Isariopsis_Leaf_Spot)
Healthy leafGrape__healthy

User Flow

  1. The user sends a greeting on WhatsApp.
  2. The bot asks for a language choice.
  3. The user uploads a grape-leaf photo.
  4. The backend runs model inference and returns:
    • predicted class
    • short disease explanation
    • symptoms
    • treatment suggestions
    • optional product link

Demo

Local Development

Requirements

  • Python 3.11+
  • ngrok for local webhook development
  • WhatsApp Business API credentials

Setup

Terminal window
git clone https://github.com/VedantAndhale/Crop_Cure_Bot.git
cd Crop_Cure_Bot
cp .env.example .env
pip install -r requirements.txt

Environment variables

Terminal window
PHONE_NUMBER_ID=your_phone_number_id
ACCESS_TOKEN_LTM=your_long_term_access_token
CALLBACK_URL=https://your-domain.ngrok-free.app
VERIFY_TOKEN=your_webhook_verify_token
APP_ID=your_facebook_app_id
APP_SECRET=your_facebook_app_secret

Run locally

In one terminal:

Terminal window
ngrok http --url=your-custom-url.ngrok-free.app 8080

In another:

Terminal window
fastapi dev main.py --port 8080

Deployment

Docker

Terminal window
docker build -t crop-cure .
docker run -p 8080:8080 --env-file .env crop-cure

Cloud Run

Terminal window
export PROJECT_ID=your-gcp-project-id
export REGION=us-central1
bash deploy.sh

After deployment, the WhatsApp webhook URL should be updated to:

<SERVICE_URL>/webhook

Model Notes

  • Architecture: ResNet9 hybrid with ECA + spatial attention
  • Classes: 4
  • Confidence threshold: 98%
  • Weights file: best_resnet9_hybrid_model.pth
  • Input size: 224x224 RGB image

Project Structure

Crop_Cure_Bot/
|- main.py
|- src/
| |- model.py
| `- dict.py
|- best_resnet9_hybrid_model.pth
|- requirements.txt
|- Dockerfile
|- deploy.sh
|- app.yaml
|- .env.example
`- start.sh

Tech Stack

LayerTechnology
BackendFastAPI
Model inferencePyTorch
MessagingWhatsApp Cloud API + pywa
Translationgoogletrans
ContainerizationDocker
DeploymentGoogle Cloud Run

Outcome

Crop Cure shows how a computer-vision model can be wrapped in a practical messaging workflow instead of a separate dashboard. The value here is less about raw model novelty and more about delivering the prediction through a channel that fits the user.