Skip to content

PGV-da/Green-Guard-AI

Repository files navigation

🌿 GreenGuard AI - AI-Powered Agricultural Assistant

An intelligent web application providing comprehensive agricultural solutions through AI-powered crop management, disease detection, and farming assistance.

πŸ“– Overview

GreenGuard AI is a Flask-based web application designed to empower farmers and agricultural enthusiasts with cutting-edge AI technology. The platform combines machine learning models, real-time data integration, and intelligent chatbot assistance to provide end-to-end agricultural support - from crop selection to disease management and market analysis.

Target Users: Farmers, agricultural researchers, gardening enthusiasts, and agribusiness professionals seeking data-driven farming solutions.

πŸš€ Features

🌱 Plant Disease Detection

  • AI-powered image analysis using MobileNet deep learning model
  • Support for 40+ plant diseases across multiple crop types (Apple, Bell Pepper, Corn, Tomato, etc.)
  • Real-time diagnosis with confidence scoring
  • Treatment recommendations and symptom analysis for identified diseases

🌾 Intelligent Crop Recommendation

  • ML-based crop prediction using soil and environmental parameters
  • Input parameters: Nitrogen, Phosphorus, Potassium levels, temperature, humidity, pH, rainfall
  • 22 crop varieties supported including Rice, Maize, Cotton, Coffee, and more
  • Data-driven suggestions for optimal crop selection

πŸ§ͺ Fertilizer Recommendation System

  • Decision tree-based fertilizer suggestions tailored to specific crop and soil conditions
  • Comprehensive input analysis: soil color, NPK levels, pH, rainfall, temperature, crop type
  • Personalized recommendations with detailed fertilizer information and application guidelines

☁️ Weather & Market Intelligence

  • Real-time weather data integration via OpenWeather API
  • Current and forecast weather for location-based farming decisions
  • Commodity price tracking using government data sources (data.gov.in API)
  • Price prediction models for 23+ agricultural commodities
  • Market trend analysis for informed selling decisions

πŸ’¬ AI Chat Assistant "Bloom"

  • RAG-powered chatbot using LangChain and Ollama/Groq LLMs
  • Agriculture-specific knowledge base with vector embeddings
  • Natural language queries for farming advice and troubleshooting
  • Context-aware responses limited to 10-30 words for quick insights

🀝 Community Platform

  • Farmer community forum for knowledge sharing
  • Image and text posting capabilities
  • Real-time message exchange among registered users
  • Experience sharing and collaborative problem-solving

πŸ“° Agricultural News Integration

  • Automated news scraping from agricultural news sources
  • Region-specific updates (Tamil Nadu agriculture focus)
  • Latest market trends and government policy updates

πŸ› οΈ Tech Stack

Backend Framework:

  • Flask 2.x - Python web framework
  • SQLite - Database for user management and community features
  • Gunicorn - WSGI HTTP Server for production deployment

Machine Learning & AI:

  • TensorFlow/Keras - Deep learning models for disease detection
  • scikit-learn - Crop recommendation and fertilizer prediction models
  • LangChain - RAG framework for AI chatbot
  • Ollama - Local LLM deployment (Llama 3.1)
  • ChromaDB - Vector database for document embeddings

Data Processing:

  • NumPy & Pandas - Data manipulation and analysis
  • BeautifulSoup4 - Web scraping for news aggregation
  • Requests - API integration for weather and price data

Frontend Technologies:

  • HTML/CSS/JavaScript - Responsive web interface
  • Bootstrap 4 - UI framework
  • jQuery - Frontend JavaScript library
  • Chart.js - Data visualization

Security & Authentication:

  • bcrypt - Password hashing
  • Flask Sessions - User session management
  • CSRF Protection - Secure form handling

πŸ“ Project Structure

GreenGuardAPP-master/
β”œβ”€β”€ app.py                    # Flask application entry point
β”œβ”€β”€ config.py                 # Configuration settings and API keys
β”œβ”€β”€ main.db                   # SQLite database
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ runtime.txt              # Python version specification
β”‚
β”œβ”€β”€ routes/                   # Blueprint route modules
β”‚   β”œβ”€β”€ auth_routes.py       # Authentication (login/register/logout)
β”‚   β”œβ”€β”€ crop_routes.py       # Crop recommendation functionality
β”‚   β”œβ”€β”€ disease_routes.py    # Disease detection and analysis
β”‚   β”œβ”€β”€ fertilizer_routes.py # Fertilizer recommendation
β”‚   β”œβ”€β”€ weather_routes.py    # Weather data integration
β”‚   β”œβ”€β”€ price_routes.py      # Commodity price prediction
β”‚   β”œβ”€β”€ chat_routes.py       # AI chatbot functionality
β”‚   β”œβ”€β”€ community_routes.py  # Community forum features
β”‚   β”œβ”€β”€ news_routes.py       # Agricultural news aggregation
β”‚   └── general_routes.py    # General pages (index, about)
β”‚
β”œβ”€β”€ models/                   # Pre-trained ML models
β”‚   β”œβ”€β”€ crop_recommendation/ # Crop prediction models and scalers
β”‚   β”œβ”€β”€ disease_detection/   # MobileNet disease classification model
β”‚   └── fertilizer_recommendation/ # Decision tree and transformer
β”‚
β”œβ”€β”€ utils/                    # Utility modules
β”‚   β”œβ”€β”€ authentication.py   # Password hashing and login decorators
β”‚   β”œβ”€β”€ database.py         # Database connection and table creation
β”‚   └── chatbot/             # AI chatbot components
β”‚       β”œβ”€β”€ models.py        # LangChain model initialization
β”‚       └── ingest.py        # Document processing for RAG
β”‚
β”œβ”€β”€ services/                 # Business logic services
β”‚   β”œβ”€β”€ disease_detection.py # Image preprocessing and prediction
β”‚   └── crops.py             # Crop-related data processing
β”‚
β”œβ”€β”€ resources/               # Data files and configurations
β”‚   β”œβ”€β”€ disease.py          # Disease information database
β”‚   └── fertilizer.py       # Fertilizer details and recommendations
β”‚
β”œβ”€β”€ data/                    # Historical crop price data
β”‚   └── crop_data/          # CSV files for 23 commodities
β”‚
β”œβ”€β”€ templates/               # HTML templates
β”‚   β”œβ”€β”€ index.html          # Dashboard homepage
β”‚   β”œβ”€β”€ login.html          # User authentication
β”‚   β”œβ”€β”€ disease-detection.html
β”‚   β”œβ”€β”€ crop-prediction.html
β”‚   β”œβ”€β”€ fertilizer-recommendation.html
β”‚   β”œβ”€β”€ chat-assistant.html
β”‚   β”œβ”€β”€ community.html
β”‚   └── [other templates]
β”‚
└── static/                  # Static assets
    β”œβ”€β”€ css/                # Stylesheets
    β”œβ”€β”€ js/                 # JavaScript files
    β”œβ”€β”€ images/             # Application images
    └── uploads/            # User-uploaded files

βš™οΈ Installation Guide

Prerequisites

  • Python 3.10.8 (specified in runtime.txt)
  • pip package manager
  • Git for version control

Step 1: Clone the Repository

git clone https://github.com/PGV-da/Green-Guard-AI.git
cd Green-Guard-AI

Step 2: Create Virtual Environment

# Windows
python -m venv venv
venv\Scripts\activate

# macOS/Linux
python3 -m venv venv
source venv/bin/activate

Step 3: Install Dependencies

pip install -r requirements.txt

Step 4: Environment Configuration

Create a config.env file in the root directory:

SECRET_KEY=your_secret_key_here
DATABASE_URL=main.db
WEATHER_API_KEY=your_openweather_api_key
GROQ_API_KEY=your_groq_api_key
PORT=4000

Step 5: Set Up AI Models

For Local Ollama Setup:

# Install Ollama (https://ollama.ai/)
ollama pull llama3.1
ollama pull tazarov/all-minilm-l6-v2-f32

Alternative: Use Groq API (recommended for production)

Step 6: Initialize Database

python app.py
# This will create the SQLite database and required tables

πŸ’» How to Run

Development Mode

# Activate virtual environment
venv\Scripts\activate  # Windows
# source venv/bin/activate  # macOS/Linux

# Run the application
python app.py

The application will be available at http://localhost:4000

Production Deployment

# Using Gunicorn (included in requirements.txt)
gunicorn --bind 0.0.0.0:4000 app:app

# Or with environment variables
PORT=4000 gunicorn --bind 0.0.0.0:$PORT app:app

Docker Deployment (Optional)

FROM python:3.10.8-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .
EXPOSE 4000

CMD ["gunicorn", "--bind", "0.0.0.0:4000", "app:app"]

πŸ§ͺ Testing

Manual Testing

  1. User Registration/Login

    • Navigate to /register to create an account
    • Use / to login with credentials
  2. Disease Detection

    • Go to /disease/diseasedetection
    • Upload a plant image (JPEG/PNG)
    • Verify disease prediction and confidence score
  3. Crop Recommendation

    • Access /crop/crop-recommendation
    • Input soil parameters (N, P, K, temperature, humidity, pH, rainfall)
    • Check recommended crop output
  4. AI Chatbot

    • Visit /chatassistant
    • Ask agriculture-related questions
    • Verify contextual responses from Bloom AI
  5. Weather Integration

    • Test /currentweather with location coordinates
    • Verify real-time weather data display

API Testing

# Test commodity prices API
curl -X GET "http://localhost:4000/api/commodity-prices"

# Test chat API
curl -X POST "http://localhost:4000/chat" \
  -H "Content-Type: application/json" \
  -d '{"message": "How to prevent tomato blight?"}'

Model Validation

  • Disease Detection: Test with sample plant images from each disease category
  • Crop Recommendation: Validate with known good/bad parameter combinations
  • Price Prediction: Compare predictions with historical price data

Contributing: Fork the repository, create feature branches, and submit pull requests for improvements.

License: Check the LICENSE file for project licensing information.

Support: Open issues on GitHub for bug reports or feature requests.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published