An intelligent web application that helps farmers and gardeners identify plant diseases from leaf images using a custom PyTorch CNN model and provides interactive, multilingual agricultural advice through an advanced chatbot interface.
- Plant Disease Detection: Upload images of plant leaves to identify potential diseases
- Multilingual Support: Chatbot supports multiple languages (English/Hindi) with automatic language detection
- Custom CNN Model: Built from scratch using PyTorch (no pre-trained models)
- Interactive Chat: Get personalized farming advice and disease information
- Responsive Web Interface: Modern, user-friendly interface accessible on any device
- Secure Image Processing: All processing happens locally - your images stay private
- Python 3.10+
- pip (Python package manager)
- Modern web browser
-
Clone the repository
git clone https://github.com/yourusername/AgroBot-Universal.git cd AgroBot-Universal -
Create and activate a virtual environment (recommended)
python -m venv venv .\venv\Scripts\activate # On Windows source venv/bin/activate # On macOS/Linux
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
- Copy
.env.exampleto.envand update any necessary configurations
- Copy
-
Run the application
python app/app.py
- Open your browser and navigate to
http://localhost:5000
- Open your browser and navigate to
AgroBot-Universal/
├── .env # Environment variables
├── README.md # This file
├── requirements.txt # Python dependencies
├── app/
│ ├── __init__.py
│ ├── app.py # Main Flask application
│ ├── chatbot_logic.py # Chatbot responses and logic
│ ├── config.py # Configuration and constants
│ ├── custom_nlp.py # Custom NLP implementation
│ ├── custom_nlp_system.py # Advanced NLP processing
│ ├── enhanced_translator.py # Translation services
│ ├── multilingual_nlp_processor.py # Multilingual support
│ └── translator.py # Basic translation utilities
├── model/
│ ├── best_model.pth # Trained PyTorch model
│ ├── class_names.json # Class labels for predictions
│ ├── cnn_model.py # Custom CNN architecture
│ └── pytorch_model.py # Model loading and prediction logic
├── plantvillagedata/ # Dataset directory (for training)
├── static/ # Static files (CSS, JS, uploads)
│ ├── css/
│ ├── js/
│ └── uploads/
└── templates/ # HTML templates
└── index.html # Main web interface
To train the model with your own dataset:
-
Prepare your dataset
- Organize images in the
plantvillagedata/directory with subdirectories for each class - Example structure:
plantvillagedata/ ├── Tomato___Bacterial_spot/ ├── Tomato___Early_blight/ └── Tomato___healthy/
- Organize images in the
-
Start training
python model/cnn_model.py
- The trained model will be saved as
model/best_model.pth - Training metrics and model architecture will be logged
- The trained model will be saved as
To add support for additional languages:
- Update the language configuration in
app/multilingual_nlp_processor.py - Add translations in
app/chatbot_logic.py - Test the new language support using the language selection in the web interface
Important: This project must not use any pre-trained models. The provided architecture is a custom CNN.
-
Download PlantVillage dataset
-
Place the dataset in:
data/plantvillage
The directory inside should have one subfolder per class (category), e.g.:
data/plantvillage/
├─ Tomato___Early_blight/
├─ Tomato___Late_blight/
├─ ...
- Train Change directory to the model folder (or run with that as working directory), then:
python model/train_model.py
This will:
- Build the custom CNN in
model/model_architecture.py - Use Keras
ImageDataGeneratorwith augmentation and validation split - Save the trained model to
model/plant_disease_model.h5 - Save the class names to
model/class_names.json - Save training plots to
model/training_history.png
Notes:
- Training time depends on hardware and dataset size
- You can adjust hyperparameters in
model/train_model.py(epochs, batch size, learning rate)
Ensure you have a trained model and class_names.json in model/.
From project root:
python app/app.py
Then open:
http://localhost:5000
- Upload a leaf image (JPG/PNG) in the left panel and click "Analyze Image"
- View top prediction and top-3 probabilities, plus treatment advisory
- Use the chat panel to ask general farming questions or describe symptoms
- Toggle English/Hindi via header buttons
GET /— Returns the web UIPOST /chat— JSON:{ "message": "..." }- Response:
{ response: string, status: "success" }
- Response:
POST /predict— multipart form withfile(image), optionallang(en/hi)- Response:
{ disease, confidence, treatment, top_predictions[], status }
- Response:
GET /health— Health/status JSON
- A Flask server (
app/app.py) serves the UI and APIs - Inference:
- Uploaded image is preprocessed with Pillow (RGB, resize to 224, normalize)
- Custom CNN predicts class probabilities
- Top class name is mapped from
class_names.json - Treatment text is looked up from
DISEASE_TREATMENTinapp/config.py
- Chatbot:
- Language detection via
langdetect - Rule-based responses for greetings, general tips, and symptom advisories
- Optional translation via
googletrans(best-effort)
- Language detection via
- No pre-trained models are used. The CNN is defined and trained from scratch.
- Ensure
class_names.jsonlength matches the model output units; both are produced by the same training run.
- "Model not loaded" on
/predict:- Train the model and place
model/plant_disease_model.h5inmodel/
- Train the model and place
- Predictions return "Unknown":
class_names.jsonis empty or mismatched; re-train or provide the correct class list
- Translation errors or delays:
- The app falls back gracefully; you can disable translation or ignore
- File upload issues on Windows paths:
- The app writes to
static/uploads. Ensure the process has write permissions
- The app writes to
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- PlantVillage dataset for providing the training data
- PyTorch and Flask communities for their excellent documentation
- All the open-source libraries that made this project possible
For any questions or feedback, please open an issue on GitHub or contact the maintainers.