Skip to content

Nikita-baghela07/Agromind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


🌱 AgroMind Backend β€” AI Crop Recommendation, Disease Detection & IoT Farm Intelligence

AgroMind backend is a full-stack FastAPI-powered engine that delivers AI crop recommendations, plant disease detection, real-time IoT soil telemetry, market insights, and an LLM-powered advisory system for farmers. It integrates weather, soil, and market APIs with device-level IoT data and advanced ML models to provide actionable agricultural insights.


πŸ“Œ Features

🌾 AI Crop Recommendation

  • Uses soil chemistry, temperature, rainfall, humidity, and market price signals.
  • Supports future integration with soil sensors & weather IoT nodes.

πŸƒ Plant Disease Detection

  • Upload leaf images or feed IoT camera inputs.
  • Runs ML inference and returns disease + cure recommendations.

πŸ“‘ IoT Integration

  • Device registration, provisioning, and secure token-based access.
  • Telemetry ingestion for soil moisture, pH, temperature, etc.
  • IoT image ingestion for edge disease detection.

🌦️ External API Integrations

  • OpenWeather API for weather data
  • SoilGrids API for soil nutrient and texture information
  • Market API (mock or real) for commodity pricing data

πŸ€– LLM Advisory Agent

  • Farmers ask questions via text or voice.
  • Backend uses an LLM + retrieval pipeline to give precise answers.

πŸŽ™οΈ Voice Assistant

  • STT β†’ LLM β†’ TTS pipeline
  • Returns both text and audio response.

πŸ› οΈ Modular, Extendable Architecture

  • Clear separation: routes, services, ML logic, database, integrations
  • Ready for Docker, CI/CD, and cloud deployment
  • IoT-ready MQTT support (optional)

πŸ“ Project Structure

backend/
  app/
    api/
      routes/
        user.py
        auth.py
        crop_recommendation.py
        disease.py
        devices.py
        iot_webhook.py
        feedback.py
        llm_agent.py
        voice.py
        integrations.py
      router.py
    core/
      config.py
      logger.py
      security.py
      middleware.py
    integrations/
      weather_client.py
      soil_client.py
      market_client.py
    services/
      user_service.py
      token_service.py
      storage.py
      utils.py
      iot_service.py
    ml_services/
      crop_service.py
      image_service.py
    models/
      db_models.py
      schemas.py
    workers/
      celery_app.py
      tasks.py
    main.py

βš™οΈ Setup & Installation

1. Clone the repository

git clone https://github.com/<your-username>/agromind-backend.git
cd agromind/backend

2. Create virtual environment

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

πŸ” Environment Variables

Create a .env file using .env.example:

SECRET_KEY=<generated_key>
DATABASE_URL=postgresql://postgres:password@localhost:5432/agromind
OPENWEATHER_API_KEY=<your_key>
SOIL_API_KEY=
MARKET_API_URL=
MARKET_API_KEY=
REDIS_URL=redis://localhost:6379/0

Generate a secure key:

openssl rand -hex 32

πŸƒ Running the Backend

Start FastAPI

uvicorn app.main:app --reload

API docs available at:

http://localhost:8000/docs
http://localhost:8000/redoc

πŸ§ͺ Testing the API

Check health

GET /health/

Predict crop

POST /crop/recommend
{
  "soil_type": "loamy",
  "temperature": 28,
  "humidity": 60,
  "rainfall": 140
}

Detect disease

Upload image using:

POST /disease/predict (multipart/form-data)

IoT telemetry ingestion

POST /iot/telemetry
{
  "device_id": "device123",
  "temperature": 28,
  "moisture": 18,
  "ph": 6.2
}

πŸ”Œ Integrations

Weather

integrations/weather_client.py

Functions:

  • get_current_weather(lat, lon)
  • get_forecast(lat, lon, days)
  • get_historical(lat, lon, start_unix)

Soil

integrations/soil_client.py

Functions:

  • get_soil_properties(lat, lon)

Market

integrations/market_client.py

Functions:

  • get_latest_price(commodity, region)
  • get_price_history(commodity, region)

πŸ€– LLM Agent

API:

POST /agent/query
{
  "user_id": 1,
  "text": "What should I do if my crop leaves turn yellow?"
}

Uses retrieval + LLM pipeline to generate exact farming advice.


πŸŽ™οΈ Voice Assistant

POST /voice/ask
audio_file + user_id

Pipeline:

  1. Speech-to-Text
  2. LLM advisory
  3. Text-to-Speech
  4. Returns audio + transcript

πŸ—„οΈ Database

Uses SQLAlchemy ORM.

Tables include:

  • Users
  • Devices
  • Telemetry
  • Feedback
  • Images
  • TokenBlocklist (for refresh-token revocation)

Supports PostgreSQL, SQLite (dev), MySQL.


🧰 Services Provided

  • user_service β†’ user CRUD & auth
  • token_service β†’ JWT + refresh token system
  • storage β†’ local/S3 file upload handling
  • iot_service β†’ telemetry + device images
  • ml_services β†’ crop & disease prediction models
  • utils β†’ image validation, job utils

🧱 Future Enhancements

  • ONNX/TFLite edge deployment
  • Full MQTT ingestion pipeline
  • Retraining automation via Celery
  • Role-based access control
  • Region-language support for LLM answers
  • Offline-first IoT sync

🀝 Contributing

Pull requests are welcome. Open an issue for feature requests or discussions.


πŸ“œ License

MIT License

About

AgroMind is an AI-driven agriculture platform that provides crop recommendations, disease detection from leaf images, and real-time IoT soil monitoring. It integrates weather, soil, and market APIs with LLM- and voice-based advisory to deliver actionable insights directly to farmers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages