Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒพ FarmAlert

เฐฎเฑ€ เฐชเฑŠเฐฒเฐ‚ เฐฎเฐพ เฐฌเฐพเฐงเฑเฐฏเฐค โ€” Your Farm. Stays Safe.

FarmAlert is a free, AI-powered agricultural decision-support platform built for smallholder farmers in Telangana, India. It delivers hyper-local climate risk forecasts, satellite-derived crop health analysis, bilingual AI advisories in Telugu and English, and a RAG-powered knowledge base grounded in official government documents โ€” all in one place.

๐ŸŒ Live Demo: farmalert.vercel.app


๐Ÿ—บ๏ธ System Architecture

FarmAlert System Architecture ๐Ÿ“„ Full Technical Documentation: FarmAlert_Technical_Documentation_v1.pdf

The system has two parallel AI pipelines that both converge at Gemini 2.0 Flash:

  • Advisory pipeline โ€” fetches live satellite + weather data, runs through risk and water engines, generates a bilingual action plan
  • RAG knowledge base pipeline โ€” embeds farmer questions, searches Pinecone vector index, retrieves grounded document chunks, generates verified answers

โœจ Features

๐ŸŒฆ๏ธ Hyper-local Climate Advisory

  • 14-day weather forecast via Open-Meteo API (temperature, rainfall, UV, ET0)
  • 22-year climate baseline anomaly detection via NASA POWER API
  • Real-time satellite indices via NASA MODIS โ€” NDVI, EVI, LST, LAI (180-day history)
  • 6 risk classifications โ€” Heatwave, Drought, Flooding, Soil Moisture Drop, Wind Damage, Pest Risk
  • FAO-56 Penman-Monteith crop water requirements with stage-specific Kc coefficients
  • Bilingual daily / weekly / monthly action plans in Telugu + English

๐Ÿค– RAG Knowledge Base

  • Floating chat widget on every page โ€” glass pill design mirroring the navbar
  • Answers grounded in 4 official government documents (346 vectors, Pinecone)
  • Query enrichment with farm context (crop + stage + location) for precision retrieval
  • In-memory OrderedDict cache (100 entries, LRU eviction) โ€” โšก instant on repeat questions
  • Animated letter-by-letter placeholder text, macOS-style expand animation
  • Attach saved farms from My Farms to personalize answers

๐Ÿ—บ๏ธ Farm Management

  • Interactive Leaflet map for GPS-based farm location
  • Save and manage multiple farms with risk history
  • My Farms dashboard with last risk status per farm

๐Ÿ—๏ธ Tech Stack

Layer Technology
Frontend React 18 ยท Vite ยท TailwindCSS ยท Leaflet ยท Framer Motion ยท motion/react
Backend FastAPI ยท Python 3.11 ยท asyncio ยท uvicorn
AI โ€” Advisory Gemini 2.0 Flash (gemini-2.0-flash)
AI โ€” RAG Generation Gemini 2.5 Flash (gemini-2.5-flash)
Embeddings gemini-embedding-001 ยท 768 dimensions ยท Matryoshka truncation
Vector Database Pinecone Serverless ยท farmalert-kb ยท cosine similarity ยท AWS us-east-1
Weather API Open-Meteo (14-day forecast ยท ET0)
Climate API NASA POWER (22-year baseline)
Satellite API NASA MODIS (NDVI ยท EVI ยท LST ยท LAI)
Frontend Hosting Vercel
Backend Hosting Render (free tier ยท 512MB RAM)

๐Ÿ“š Knowledge Base Documents

Document Source Pages Chunks
PM-KISAN Operational Guidelines pmkisan.gov.in 12 15
Telangana Kharif Agro-Advisory 2025 icar.org.in 7 12
ICAR Soil & Nutrient Management (NRM-2702) icar.org.in 115 104
PMFBY Crop Insurance Guidelines pmfby.gov.in 144 215
Total 278 346

๐Ÿ”Œ API Endpoints

Method Endpoint Description
POST /api/analyze Full farm analysis โ€” weather + satellite + risk + water + Gemini advisory
POST /api/knowledge-base RAG Q&A โ€” embedding + Pinecone search + grounded Gemini answer
GET / Health check

/api/analyze Request

{
  "lat": 17.9784,
  "lng": 79.5941,
  "crop_type": "cotton",
  "crop_stage": "flowering",
  "soil_type": "black",
  "location_name": "Warangal, Telangana"
}

/api/knowledge-base Request

{
  "question": "Am I eligible for PM-KISAN scheme?",
  "crop": "cotton",
  "stage": "flowering",
  "location": "Warangal, Telangana"
}

/api/knowledge-base Response

{
  "answer": "To be eligible for PM-KISAN...",
  "cached": false
}

๐Ÿš€ Local Setup

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • Pinecone account (free tier)
  • Google AI Studio API key(s)

Backend

cd backend
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -r requirements.txt

Create backend/.env:

GEMINI_API_KEY=your_gemini_api_key
GEMINI_RAG_API_KEY=your_rag_gemini_api_key
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_HOST=your_pinecone_index_host
python run.py

Frontend

cd frontend
npm install

Create frontend/.env:

VITE_API_URL=http://localhost:8000
npm run dev

Knowledge Base Ingestion

cd backend
# Add PDFs to data/source_docs/
python app/scripts/ingest.py

๐Ÿ›๏ธ Key Architecture Decisions

Decision Reason
No LangChain RAM constraints on Render free tier (512MB)
Raw Pinecone SDK Lighter footprint, direct control
PyMuPDF for PDF extraction pypdf and pdfplumber had silent text duplication bug on sliced PDFs
output_dimensionality=768 Matryoshka Representation Learning โ€” officially supported truncation, not lossy
RETRIEVAL_DOCUMENT vs RETRIEVAL_QUERY Different embedding modes for ingestion vs query time โ€” improves retrieval quality
Two separate Gemini API keys Isolates advisory and RAG quota pools โ€” prevents one feature from exhausting the other
In-memory cache (no Redis) Zero added dependencies, zero cost, adequate for current scale
localStorage for farms No database yet โ€” sufficient for MVP, clean migration path to Supabase later

๐Ÿ“ Project Structure

FARMALERT/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ main.py                 # FastAPI routes
โ”‚   โ”‚   โ”œโ”€โ”€ config.py               # Settings + env vars
โ”‚   โ”‚   โ”œโ”€โ”€ models.py               # Pydantic models
โ”‚   โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ gemini_service.py   # Advisory AI generation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ rag_service.py      # RAG pipeline
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ risk_engine.py      # 6-type risk classification
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ water.py            # FAO-56 water engine
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ weather.py          # Open-Meteo integration
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ climate.py          # NASA POWER integration
โ”‚   โ”‚   โ””โ”€โ”€ scripts/
โ”‚   โ”‚       โ”œโ”€โ”€ ingest.py           # RAG document ingestion (local only)
โ”‚   โ”‚       โ””โ”€โ”€ verify_pinecone.py  # Index verification
โ”‚   โ”œโ”€โ”€ data/
โ”‚   โ”‚   โ””โ”€โ”€ source_docs/            # PDF knowledge base documents
โ”‚   โ””โ”€โ”€ requirements.txt
โ”œโ”€โ”€ frontend/
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ”œโ”€โ”€ pages/
โ”‚       โ”‚   โ”œโ”€โ”€ AnalysePage.jsx     # Main farm analysis
โ”‚       โ”‚   โ””โ”€โ”€ MyFarmsPage.jsx     # Saved farms
โ”‚       โ””โ”€โ”€ components/
โ”‚           โ””โ”€โ”€ KnowledgeChat.jsx   # RAG chat widget
โ””โ”€โ”€ docs/
    โ””โ”€โ”€ farmalert_complete_system_architecture.png

๐ŸŒฑ Roadmap

  • Render deployment with all env vars (in progress)
  • Frontend RAG chat UI connected to live backend
  • Add 10โ€“15 more knowledge base documents
  • Supabase database for cross-device farm sync
  • Migrate gemini_service.py to new google-genai SDK
  • Mobile-responsive UI improvements
  • Push notifications for critical risk alerts
  • Telugu language input support in RAG chat

๐Ÿ‘จโ€๐Ÿ’ป Author

Suhas Naragani


๐Ÿ“„ License

This project is open source and available under the MIT License.


Built for Telangana farmers ๐ŸŒพ
เฐฎเฑ€ เฐชเฑŠเฐฒเฐ‚ เฐฎเฐพ เฐฌเฐพเฐงเฑเฐฏเฐค

About

AI-powered crop advisory platform for Telangana farmers hyper-local climate risk forecasts, satellite data (NASA MODIS), RAG knowledge base with official govt. documents, bilingual Telugu/English. Built with FastAPI, React, Pinecone & Gemini.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages