An intelligent web application providing comprehensive agricultural solutions through AI-powered crop management, disease detection, and farming assistance.
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.
- 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
- 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
- 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
- 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
- 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
- Farmer community forum for knowledge sharing
- Image and text posting capabilities
- Real-time message exchange among registered users
- Experience sharing and collaborative problem-solving
- Automated news scraping from agricultural news sources
- Region-specific updates (Tamil Nadu agriculture focus)
- Latest market trends and government policy updates
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
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
- Python 3.10.8 (specified in runtime.txt)
- pip package manager
- Git for version control
git clone https://github.com/PGV-da/Green-Guard-AI.git
cd Green-Guard-AI# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCreate 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=4000For Local Ollama Setup:
# Install Ollama (https://ollama.ai/)
ollama pull llama3.1
ollama pull tazarov/all-minilm-l6-v2-f32Alternative: Use Groq API (recommended for production)
- Sign up at Groq Console
- Add your API key to
config.env
python app.py
# This will create the SQLite database and required tables# Activate virtual environment
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
# Run the application
python app.pyThe application will be available at http://localhost:4000
# 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:appFROM 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"]-
User Registration/Login
- Navigate to
/registerto create an account - Use
/to login with credentials
- Navigate to
-
Disease Detection
- Go to
/disease/diseasedetection - Upload a plant image (JPEG/PNG)
- Verify disease prediction and confidence score
- Go to
-
Crop Recommendation
- Access
/crop/crop-recommendation - Input soil parameters (N, P, K, temperature, humidity, pH, rainfall)
- Check recommended crop output
- Access
-
AI Chatbot
- Visit
/chatassistant - Ask agriculture-related questions
- Verify contextual responses from Bloom AI
- Visit
-
Weather Integration
- Test
/currentweatherwith location coordinates - Verify real-time weather data display
- Test
# 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?"}'- 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.