Skip to content

opbot-xd/AgriAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AgriAgent - Multimodal AI Agricultural Advisor

A comprehensive AI-powered agricultural advisory system that provides farmers with expert guidance through chat, image analysis, and voice queries in multiple Indian languages.

🌾 Features

  • Multilingual Chat: Ask farming questions in Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Punjabi, and English
  • Image Analysis: Upload crop images for disease detection and treatment recommendations
  • Voice Queries: Record voice messages in any supported language for hands-free interaction
  • Weather Integration: Real-time weather data for location-specific advice
  • Market Insights: Current market prices and trends
  • AI-Powered Responses: Advanced machine learning models for accurate recommendations
  • Text-to-Speech: Audio responses in the user's preferred language
  • Price Prediction : Predict future crop prices using trained ML models.

πŸš€ Quick Start with Docker

Prerequisites

  • Docker and Docker Compose installed
  • OpenAI API key (optional but recommended)
  • Weather API key (OpenWeatherMap)

1. Clone the Repository

git clone https://github.com/opbot-xd/AgriAgent.git
cd agriagent

2. Create Environment File

Create a .env file in the root directory:

# Database
DATABASE_URL=sqlite+aiosqlite:///./agriagent.db

# Security
SECRET_KEY=your_super_secret_key

# Token
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60

# Google Gemini/Generative AI
GOOGLE_API_KEY=your_google_api_key
GEMINI_API_KEY=your_gemini_api_key

# Dhenu AI
DHENU_API_KEY=your_dhenu_api_key

# Weather API
WEATHER_API_KEY=your_weather_api_key

# CORS
FRONTEND_URL=http://localhost:3000

#huggingface
HF_TOKEN=your_huggingface_token
HF_API_URL=https://api-inference.huggingface.co/models/linkanjarad/mobilenet_v2_10_224-plant-disease-identification

# OpenAI
OPENAI_API_KEY=your_openai_api_key

3. Start the Application

# Build and start all services
docker-compose up --build

# Or run in detached mode
docker-compose up -d --build

4. Access the Application

πŸ› οΈ Manual Setup (Development)

Backend Setup

  1. Create Virtual Environment
cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install Dependencies
pip install -r requirements.txt
  1. Create a .env file
# Database
DATABASE_URL=sqlite+aiosqlite:///./agriagent.db

# Security
SECRET_KEY=your_super_secret_key

# Token
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60

# Google Gemini/Generative AI
GOOGLE_API_KEY=your_google_api_key
GEMINI_API_KEY=your_gemini_api_key

# Dhenu AI
DHENU_API_KEY=your_dhenu_api_key

# Weather API
WEATHER_API_KEY=your_weather_api_key

# CORS
FRONTEND_URL=http://localhost:3000

#huggingface
HF_TOKEN=your_huggingface_token
HF_API_URL=https://api-inference.huggingface.co/models/linkanjarad/mobilenet_v2_1.0_224-plant-disease-identification

# OpenAI
OPENAI_API_KEY=your_openai_api_key
  1. Start Backend Server
uvicorn main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

  1. Install Node.js Dependencies
cd frontend
npm install
  1. Configure Environment

Create .env in frontend directory:

REACT_APP_API_URL=http://localhost:8000
  1. Start Frontend Server
npm start

πŸ“ Project Structure

AgriAgent/
β”œβ”€β”€ backend/ # FastAPI backend
β”‚ β”œβ”€β”€ dataset/ # Training / data files
β”‚ β”œβ”€β”€ models/ # AI/ML models
β”‚ β”œβ”€β”€ routes/ # API route definitions
β”‚ β”œβ”€β”€ schemas/ # Pydantic schemas
β”‚ β”œβ”€β”€ services/ # Business logic and services
β”‚ β”œβ”€β”€ utils/ # Utility/helper functions
β”‚ β”œβ”€β”€ venv/ # Python virtual environment (local only, not in Docker)
β”‚ β”œβ”€β”€ agriagent.db # SQLite database (dev)
β”‚ β”œβ”€β”€ database.py # Database connection setup
β”‚ β”œβ”€β”€ Dockerfile # Backend Docker configuration
β”‚ β”œβ”€β”€ main.py # FastAPI entry point
β”‚ β”œβ”€β”€ requirements.txt # Python dependencies
β”‚ β”œβ”€β”€ schema.sql # Database schema (optional if using migrations)
β”‚ β”œβ”€β”€ .env # Environment variables (local)
β”‚ β”œβ”€β”€ .env.sample # Example environment file
β”‚ └── README.md # Backend documentation
β”‚
β”œβ”€β”€ frontend/ # Next.js frontend
β”‚ β”œβ”€β”€ app/ # App router (Next.js 13+)
β”‚ β”œβ”€β”€ components/ # UI components
β”‚ β”œβ”€β”€ lib/ # Utility libraries
β”‚ β”œβ”€β”€ public/ # Static assets
β”‚ β”œβ”€β”€ .next/ # Next.js build output (ignored in git)
β”‚ β”œβ”€β”€ Dockerfile # Frontend Docker configuration
β”‚ β”œβ”€β”€ package.json # Node.js dependencies
β”‚ β”œβ”€β”€ package-lock.json # Lockfile
β”‚ β”œβ”€β”€ tsconfig.json # TypeScript configuration
β”‚ β”œβ”€β”€ next.config.ts # Next.js config
β”‚ β”œβ”€β”€ eslint.config.mjs # ESLint config
β”‚ β”œβ”€β”€ postcss.config.mjs # PostCSS config
β”‚ β”œβ”€β”€ tailwind.config.js # Tailwind CSS configuration
β”‚ β”œβ”€β”€ components.json # ShadCN components registry
β”‚ β”œβ”€β”€ .env # Frontend environment variables
β”‚ β”œβ”€β”€ .env.sample # Example environment file
β”‚ └── README.md # Frontend documentation
β”‚
β”œβ”€β”€ docker-compose.yml # Docker services configuration
β”œβ”€β”€ README.md # Main project documentation
└── .gitignore # Git ignore file

πŸ”§ Configuration – API Keys

AgriAgent requires several API keys for different features.
All keys should be added in the .env file located in the backend/ directory.

1. Database

  • DATABASE_URL
    Default: sqlite+aiosqlite:///./agriagent.db
    You can change this to PostgreSQL, MySQL, etc. if required.

2. Security

  • SECRET_KEY – Any random secure string for JWT tokens.
  • ALGORITHM – Default: HS256
  • ACCESS_TOKEN_EXPIRE_MINUTES – Token validity in minutes (default: 60).

3. Google Gemini / Generative AI

  • GOOGLE_API_KEY

  • GEMINI_API_KEY

    • Alternative Gemini key (if using a different project setup).

4. Dhenu AI

  • DHENU_API_KEY

5. Weather API

  • WEATHER_API_KEY
    • Sign up at OpenWeather
    • Generate a free API key
    • Add it here.

6. CORS

  • FRONTEND_URL
    • The URL of your frontend app.
    • Example: http://localhost:3000

7. Hugging Face

  • HF_TOKEN

  • HF_API_URL

    • Default:
      https://api-inference.huggingface.co/models/linkanjarad/mobilenet_v2_1.0_224-plant-disease-identification
      
    • Used for plant disease detection.

8. OpenAI

  • OPENAI_API_KEY
    • Sign up at OpenAI
    • Generate API key
    • Add it here.

🌐 API Endpoints

Authentication

  • POST /auth/signup - Register new user
  • POST /auth/login - User login

Core Features

  • POST /chat - Text chat queries and also voice queries
  • POST /upload - Image analysis
  • POST /forecast - predict future rates of your crop

API Documentation

Visit http://localhost:8000/docs for interactive API documentation.

🌍 Supported Languages

  • English (en)
  • Hindi (hi)
  • Bengali (bn)
  • Tamil (ta)
  • Telugu (te)
  • Marathi (mr)
  • Gujarati (gu)
  • Punjabi (pa)

πŸ”’ Security Features

  • JWT-based authentication
  • Password hashing with bcrypt
  • HTTPS support (configure in production)
  • Input validation and sanitization
  • Rate limiting (Redis-based)

πŸ› Troubleshooting

Common Issues

  1. Database Connection Error

    • Ensure PostgreSQL is running
    • Check DATABASE_URL configuration
    • Verify user permissions
  2. Redis Connection Error

    • Ensure Redis server is running
    • Check REDIS_URL configuration
  3. AI Model Loading Issues

    • Ensure sufficient disk space (models can be large)
    • Check internet connection for model downloads
    • Verify write permissions in models directory
  4. Audio Processing Issues

    • Install ffmpeg: sudo apt-get install ffmpeg
    • Check microphone permissions in browser

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For support and questions:

  • Create an issue on GitHub
  • Check documentation at /docs endpoint
  • Review troubleshooting section above

🎯 Roadmap

Phase 1 (Current)

  • βœ… Multilingual chat support (Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Punjabi, English)
  • βœ… Crop image upload and disease detection (Hugging Face model)
  • βœ… Voice query support with text-to-speech responses
  • βœ… Weather integration and market insights
  • βœ… AI-powered price prediction

Phase 2 (Planned)

  • SMS/WhatsApp/IVR integration for wider accessibility
  • Farmer community features for peer-to-peer learning and sharing
  • Mobile application (Flutter) for better farmer experience
  • Improved ML models for accurate disease diagnosis and recommendations

Phase 3 (Future)

  • Offline/low-connectivity mode for remote villages
  • Partnerships with NGOs, AgriTech companies, and government bodies
  • Advanced analytics dashboard for farmers
  • Continuous AI learning from farmer queries and images

πŸ™ Acknowledgments

  • OpenAI and Google Gemini for providing powerful AI language models.
  • Hugging Face for open-source transformer models and APIs.
  • Weather APIs (for real-time weather and climate data integration).
  • Dhenu – for agri advices
  • The agricultural research community for datasets, insights, and continued innovation.
  • Open-source contributors whose projects, tools, and libraries made this work possible.

AgriAgent

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •