Skip to content

An AI-powered chatbot that allows users (especially farmers and gardeners) to upload images of plant leaves or describe symptoms via text, and receive accurate plant disease diagnosis and treatment recommendations using image processing and natural language processing techniques.

Notifications You must be signed in to change notification settings

kavanatn/AI_PlantDocBot

Repository files navigation

🌿 Plant Disease Chatbot

An AI-powered conversational chatbot for diagnosing plant diseases using computer vision (CNN) and natural language processing (BERT).

✨ Features

  • 🤖 Conversational AI: Interactive chatbot that asks clarifying questions
  • 📸 Image Diagnosis: Upload leaf photos for CNN-based disease detection
  • 💬 Text Diagnosis: Describe symptoms for BERT-based analysis
  • 🎯 Pattern-Based Detection: Recognizes characteristic disease patterns (e.g., Early Blight's target spots)
  • 💊 Treatment Recommendations: Detailed treatment and prevention advice for 35+ diseases
  • 🌍 Multi-Crop Support: Covers tomatoes, potatoes, apples, grapes, corn, peppers, and more

🚀 Quick Start

Prerequisites

  • Python 3.8+
  • pip

Installation

  1. Clone the repository:
git clone <your-repo-url>
cd final
  1. Create virtual environment:
python -m venv .venv
.venv\Scripts\activate  # Windows
# or
source .venv/bin/activate  # Linux/Mac
  1. Install dependencies:
pip install -r requirements.txt
  1. Download model files (not included in Git due to size):

    • bert_plant_chatbot_model.pt (438 MB)
    • cnn_model_final.h5 or final_saved_model/ (27-574 MB)
    • class_names.pkl
    • label_mapping.json

    Note: Contact the repository owner for model files or train your own using Training_code.ipynb

  2. Run the app:

streamlit run app.py
  1. Open in browser: http://localhost:8501

📁 Project Structure

final/
├── app.py                      # Main Streamlit application
├── chatbot/                    # Chatbot package
│   ├── chatbot_manager.py      # Conversational AI logic
│   ├── conversation_templates.py # Response templates
│   └── followup_templates.py   # Follow-up templates
├── knowledge_base/             # Knowledge base package
│   ├── disease_patterns.py     # Pattern-based disease detection
│   ├── treatments.py           # Treatment database (35 diseases)
│   └── detailed_treatments.py  # Detailed disease info
├── resources/                  # Static resources
│   ├── class_names.pkl         # CNN labels (not in Git)
│   └── label_mapping.json      # BERT labels (not in Git)
├── models/                     # Model files
│   ├── bert_plant_chatbot_model.pt # BERT model (not in Git)
│   └── final_saved_model/      # CNN model (not in Git)
├── requirements.txt            # Python dependencies
├── README.md                   # This file
└── .gitignore                  # Git ignore rules

🎯 Usage

1. Image Diagnosis

  • Upload a clear photo of affected plant leaves
  • Get instant CNN-based disease prediction
  • View confidence score and treatment recommendations

2. Text Diagnosis

  • Describe symptoms in natural language
  • Get BERT-based analysis with top 3 predictions
  • See detailed treatment plans

3. Chat Diagnosis (Conversational)

  • Start a conversation with the AI assistant
  • Answer clarifying questions about symptoms
  • Receive accurate diagnosis with high confidence
  • Get personalized treatment recommendations

Example Conversation:

🤖 Bot: Hello! Describe the symptoms you're seeing.

👤 User: My tomato plant has brown spots with rings on the leaves

🤖 Bot: Are the spots circular with concentric rings, like a target?

👤 User: Yes, exactly like a target pattern

🤖 Bot: I'm 70% confident this is Tomato Early Blight.
       
       Treatment: Remove infected leaves, apply fungicides...

🧠 How It Works

Dual Detection System

  1. Pattern-Based Detection (Primary):

    • Recognizes characteristic symptom patterns
    • High confidence (70-95%) for specific diseases
    • Examples: Early Blight (target spots), Powdery Mildew (white powder)
  2. BERT Model (Fallback):

    • Natural language understanding
    • Analyzes accumulated symptom descriptions
    • Works for diseases without specific patterns

Supported Diseases (35+)

Crops: Tomato (12 conditions), Potato (3), Apple (3), Corn (3), Grape (2), Pepper (3), and more

Disease Types: Fungal, bacterial, viral, pest-related, and healthy baselines

🛠️ Technical Stack

  • Frontend: Streamlit
  • ML Models:
    • TensorFlow/Keras (CNN for images)
    • PyTorch + Transformers (BERT for text)
  • Image Processing: PIL
  • Data: NumPy, Pickle, JSON

⚠️ Important Notes

Model Files Not Included

Due to GitHub file size limits, the following large files are not included in this repository:

  • bert_plant_chatbot_model.pt (438 MB)
  • final_saved_model/ or cnn_model_final.h5 (27-574 MB)
  • newmodel.h5 (574 MB)

To get the models:

  1. Contact the repository owner
  2. Or train your own using Training_code.ipynb
  3. Or use Git LFS for large files

Disclaimer

This tool provides general guidance and is not a replacement for professional diagnosis. For critical plant health issues, consult certified agricultural professionals.

📊 Performance

  • Pattern Detection: 70-95% confidence for characteristic diseases
  • BERT Model: 10-20% confidence (requires improvement)
  • CNN Model: Varies by disease
  • Inference Speed: 1-3 seconds on CPU

🔮 Future Enhancements

  • Improve BERT model training
  • Add more disease patterns
  • Mobile app version
  • Multi-language support
  • User accounts and history
  • Geographic disease tracking
  • Integration with weather data

🤝 Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

📄 License

[Add your license here]

👥 Authors

[Add your name/team here]

🙏 Acknowledgments

  • PlantDoc and PlantVillage datasets
  • BERT model from Hugging Face
  • Streamlit for the amazing framework

Built with ❤️ for healthier plants 🌱

About

An AI-powered chatbot that allows users (especially farmers and gardeners) to upload images of plant leaves or describe symptoms via text, and receive accurate plant disease diagnosis and treatment recommendations using image processing and natural language processing techniques.

Resources

Stars

Watchers

Forks

Packages

No packages published