Skip to content

VedantAndhale/Crop_Cure_Bot

Repository files navigation

🌿 Crop Cure — Grape Disease Detection via WhatsApp

Python FastAPI PyTorch WhatsApp Multilingual Status Docker GCP

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_project

2. Set up environment variables

cp .env.example .env

Edit .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_secret

3. Install dependencies

pip install -r requirements.txt

4. Run locally (with ngrok)

Open two separate terminals:

Terminal 1 — Start the ngrok tunnel:

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

Terminal 2 — Start the FastAPI server:

fastapi dev main.py --port 8080

Make sure CALLBACK_URL in your .env matches your ngrok URL.


🤖 Bot Usage

  1. Send "Hi" or "Hello" to the bot on WhatsApp
  2. Select your preferred language (English / मराठी / हिंदी)
  3. Send a clear image of a grape leaf
  4. The bot responds with:
    • Disease name & description
    • Symptoms
    • Treatment solutions (cultural, chemical, organic)
    • A product recommendation button (if applicable)

🐳 Docker

Build and run with Docker:

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

The 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-id
export REGION=us-central1
bash deploy.sh

The script will:

  1. Build and push the Docker image to Google Container Registry
  2. Deploy the service to Cloud Run
  3. 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

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors