Project
Crop Cure — Grape Disease Detection via WhatsApp
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).
[!WARNING] ⚠️ Under Development — This project has not been actively maintained for some time. Some features may be incomplete, unstable, or subject to breaking changes without notice.
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).
✨ Features#
- 📸 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
🏗️ Architecture#
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🦠 Supported Diseases#
| 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 |
🚀 Getting Started#
Prerequisites#
- Python 3.11+
- ngrok (for local development)
- WhatsApp Business API credentials (Facebook Developer App)
1. Clone the repository#
git clone <your-repo-url>cd be_project2. Set up environment variables#
cp .env.example .envEdit .env and fill in your credentials:
PHONE_NUMBER_ID=your_phone_number_idACCESS_TOKEN_LTM=your_long_term_access_tokenCALLBACK_URL=https://your-domain.ngrok-free.appVERIFY_TOKEN=your_webhook_verify_tokenAPP_ID=your_facebook_app_idAPP_SECRET=your_facebook_app_secret3. Install dependencies#
pip install -r requirements.txt4. Run locally (with ngrok)#
Open 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.
🤖 Bot Usage#
- 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)
Demo Video#
🐳 Docker#
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.
☁️ Deploy to Google Cloud Run#
Use the provided deployment script:
export PROJECT_ID=your-gcp-project-idexport REGION=us-central1bash 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.
🧠 Model Details#
- 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)
📁 Project Structure#
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🔑 Environment Variables#
| 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) |
🛠️ Tech Stack#
| Layer | Technology |
|---|---|
| Backend | FastAPI + Uvicorn / Gunicorn |
| WhatsApp SDK | pywa / pywa_async |
| ML Framework | PyTorch + torchvision |
| Translation | googletrans |
| Containerization | Docker |
| Cloud Platform | Google Cloud Run |