Warning
Crop Cure is a WhatsApp bot that uses a custom ResNet9 Hybrid deep learning model to detect diseases in grape leaves from images sent by farmers. It responds with the disease name, symptoms, treatment advice, and product recommendations — all in the user's preferred language (English, Marathi, or Hindi).
- 📸 AI-powered disease detection — Custom ResNet9 with ECA (Efficient Channel Attention) and Spatial Attention modules
- 🍇 Detects 4 classes — Black Rot, Esca (Black Measles), Leaf Blight (Isariopsis Leaf Spot), and Healthy
- 🌍 Multilingual support — English, Marathi (मराठी), Hindi (हिंदी)
- 💊 Treatment advice — Cultural, chemical, and organic solutions for each disease
- 🛒 Product recommendations — Direct links to relevant products via WhatsApp button
- ⚡ FastAPI backend with async message handling via
pywa_async
User (WhatsApp)
│
▼
WhatsApp Cloud API
│
▼
FastAPI Backend (main.py)
├── pywa_async — WhatsApp message handler
├── googletrans — Multi-language translation
├── src/model.py — ResNet9 Hybrid model inference
└── src/dict.py — Disease info & product catalog
| Disease | Class Name |
|---|---|
| Black Rot | Grape__Black_rot |
| Esca (Black Measles) | Grape__Esca_(Black_Measles) |
| Leaf Blight (Isariopsis) | Grape__Leaf_blight_(Isariopsis_Leaf_Spot) |
| Healthy Leaf | Grape__healthy |
- Python 3.11+
- ngrok (for local development)
- WhatsApp Business API credentials (Facebook Developer App)
git clone <your-repo-url>
cd be_projectcp .env.example .envEdit .env and fill in your credentials:
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_secretpip install -r requirements.txtOpen two separate terminals:
Terminal 1 — Start the ngrok tunnel:
ngrok http --url=your-custom-url.ngrok-free.app 8080Terminal 2 — Start the FastAPI server:
fastapi dev main.py --port 8080Make sure
CALLBACK_URLin your.envmatches your ngrok URL.
- Send "Hi" or "Hello" to the bot on WhatsApp
- Select your preferred language (English / मराठी / हिंदी)
- Send a clear image of a grape leaf
- The bot responds with:
- Disease name & description
- Symptoms
- Treatment solutions (cultural, chemical, organic)
- A product recommendation button (if applicable)
Build and run with Docker:
docker build -t crop-cure .
docker run -p 8080:8080 --env-file .env crop-cureThe container uses Gunicorn + Uvicorn workers for production-grade async performance.
Use the provided deployment script:
export PROJECT_ID=your-gcp-project-id
export REGION=us-central1
bash deploy.shThe script will:
- Build and push the Docker image to Google Container Registry
- Deploy the service to Cloud Run
- Output the live service URL
After deployment, update the webhook URL in your WhatsApp Business API settings to
<SERVICE_URL>/webhook.
- Architecture: ResNet9 Hybrid with ECA + Spatial Attention
- Classes: 4 (3 diseases + healthy)
- Confidence Threshold: 98% — images below this are marked as
Unclassified - Weights file:
best_resnet9_hybrid_model.pth - Input: 224×224 RGB image (ImageNet normalization)
be_project/
├── main.py # FastAPI app & WhatsApp bot logic
├── src/
│ ├── model.py # ResNet9 Hybrid model & inference
│ └── dict.py # Disease info dictionary & product catalog
├── best_resnet9_hybrid_model.pth # Trained model weights
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── deploy.sh # Google Cloud Run deployment script
├── app.yaml # Google App Engine configuration
├── .env.example # Environment variable template
└── start.sh # Startup script
| Variable | Description |
|---|---|
PHONE_NUMBER_ID |
WhatsApp Business phone number ID |
ACCESS_TOKEN_LTM |
Long-term access token from Meta |
CALLBACK_URL |
Publicly accessible webhook URL |
VERIFY_TOKEN |
Custom token for webhook verification |
APP_ID |
Facebook/Meta App ID |
APP_SECRET |
Facebook/Meta App Secret |
PORT |
Server port (default: 8080) |
| Layer | Technology |
|---|---|
| Backend | FastAPI + Uvicorn / Gunicorn |
| WhatsApp SDK | pywa / pywa_async |
| ML Framework | PyTorch + torchvision |
| Translation | googletrans |
| Containerization | Docker |
| Cloud Platform | Google Cloud Run |