readme configure
Browse files
README.md
CHANGED
|
@@ -1,99 +1,36 @@
|
|
| 1 |
-
# FarmRisk Backend
|
| 2 |
-
|
| 3 |
-
This is the backend service for FarmRisk, a multilingual agro-meteorological decision support platform. It is built using **FastAPI** and integrates Open-Meteo forecasts, Pinecone vector retrievals (RAG), and Gemini/Groq LLMs to generate crop-specific agricultural advisories.
|
| 4 |
-
|
| 5 |
---
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
β βββ api/ # API routers (FastAPI endpoints)
|
| 13 |
-
β β βββ advisory.py # Handles /api/advisory (orchestrating generation & translation)
|
| 14 |
-
β β βββ location.py # Handles /api/location (location utilities)
|
| 15 |
-
β β
|
| 16 |
-
β βββ core/ # Core system modules
|
| 17 |
-
β β βββ caching.py # In-memory spatial & translation cache manager
|
| 18 |
-
β β βββ config.py # Global application configurations & environment loading
|
| 19 |
-
β β βββ logging.py # Structured logging configuration
|
| 20 |
-
β β
|
| 21 |
-
β βββ llm/ # Large Language Model services
|
| 22 |
-
β β βββ advisory_engine.py# Core advisory prompt synthesis and generation
|
| 23 |
-
β β βββ providers.py # LLM clients for Gemini and Groq (JSON/Text generation)
|
| 24 |
-
β β
|
| 25 |
-
β βββ models/ # Data validation schemas (Pydantic)
|
| 26 |
-
β β βββ schemas.py # Request, Response, and Location models
|
| 27 |
-
β β
|
| 28 |
-
β βββ rag/ # Retrieval-Augmented Generation
|
| 29 |
-
β β βββ retriever.py # Pinecone query retriever for scientific guidelines
|
| 30 |
-
β β
|
| 31 |
-
β βββ services/ # External services and utility classes
|
| 32 |
-
β β βββ location.py # Nominatim reverse geocoding
|
| 33 |
-
β β βββ season.py # Month-based agricultural season resolver (Kharif/Rabi)
|
| 34 |
-
β β βββ translation.py # Multi-language translation pipeline
|
| 35 |
-
β β βββ weather.py # Open-Meteo 10-day forecast integration & risk rules
|
| 36 |
-
β β
|
| 37 |
-
β βββ main.py # FastAPI entry point & lifespan events
|
| 38 |
-
β
|
| 39 |
-
βββ config/ # Static JSON configuration files
|
| 40 |
-
β βββ crops.json # Supported crops configuration
|
| 41 |
-
β βββ states.json # Standardized Indian States configuration
|
| 42 |
-
β
|
| 43 |
-
βββ data/ # Data directory (scientific guides, JSON extracts)
|
| 44 |
-
β
|
| 45 |
-
βββ pipeline/ # Data parsing, chunking, and index uploading scripts
|
| 46 |
-
β βββ 02_parse.py # Parse raw ICAR guides into JSON
|
| 47 |
-
β βββ 03_validate.py # Validate guidelines format
|
| 48 |
-
β βββ 04_chunk.py # Text chunking for vector database
|
| 49 |
-
β βββ 05_embed_upload.py # Embed text chunks and upload to Pinecone
|
| 50 |
-
β βββ run_all.py # Master script to run the pipeline
|
| 51 |
-
β
|
| 52 |
-
βββ rag/ # RAG data extraction script
|
| 53 |
-
β βββ extract.py # Extract content text from PDFs
|
| 54 |
-
β
|
| 55 |
-
βββ .env # Local environment variable configuration
|
| 56 |
-
βββ requirements.txt # Python dependencies
|
| 57 |
-
βββ venv/ # Python virtual environment
|
| 58 |
-
```
|
| 59 |
-
|
| 60 |
---
|
| 61 |
|
| 62 |
-
#
|
| 63 |
|
| 64 |
-
|
| 65 |
-
* **Advisory (`advisory.py`)**: Receives farmer coordinate location, crop, target language, and crop stage. It resolves the coordinates into village/district boundaries, retrieves the 10-day weather forecast, performs semantic vector search for ICAR guidelines, triggers Gemini/Groq to generate the summary, caches results, and runs translation.
|
| 66 |
-
* **Location (`location.py`)**: Provides endpoints for searching or geocoding locations.
|
| 67 |
|
| 68 |
-
##
|
| 69 |
-
* **Advisory Engine (`advisory_engine.py`)**: Synthesizes the weather forecast context, risk alerts, and scientific guidelines into a prompt. It enforces strict two-paragraph output constraints, plain text styling, word count range (120-180 words), and structural partitions (expected weather in paragraph 1, recommendations in paragraph 2 ending with outlook).
|
| 70 |
-
* **LLM Providers (`providers.py`)**: Integrates with the official `google-genai` SDK and the `groq` SDK, implementing retry/backoff wrappers for transient error tolerance, supporting JSON and plain-text output formats.
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
##
|
| 77 |
-
* Performs a metadata-filtered vector similarity search on the Pinecone index `farmrisk` based on selected crop, state, and resolved agricultural season to retrieve precise scientific guidelines.
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
-
```powershell
|
| 90 |
-
.\venv\Scripts\Activate.ps1
|
| 91 |
-
```
|
| 92 |
-
2. **Install Dependencies**:
|
| 93 |
-
```bash
|
| 94 |
-
pip install -r requirements.txt
|
| 95 |
-
```
|
| 96 |
-
3. **Start the Development Server**:
|
| 97 |
-
```bash
|
| 98 |
-
python -m uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
|
| 99 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: FarmRisk
|
| 3 |
+
emoji: πΎ
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# FarmRisk
|
| 11 |
|
| 12 |
+
FarmRisk is an AI-powered agro-meteorological advisory backend built with FastAPI.
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
## Features
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
- π¦οΈ Weather forecast APIs
|
| 17 |
+
- π€ AI-generated crop advisories
|
| 18 |
+
- π Village and location resolution
|
| 19 |
+
- π± Crop-specific recommendations
|
| 20 |
+
- π Semantic search using Sentence Transformers (`BAAI/bge-small-en-v1.5`)
|
| 21 |
+
- β‘ Production-ready FastAPI backend
|
| 22 |
|
| 23 |
+
## Tech Stack
|
|
|
|
| 24 |
|
| 25 |
+
- FastAPI
|
| 26 |
+
- Python 3.12.1
|
| 27 |
+
- Sentence Transformers
|
| 28 |
+
- Hugging Face Transformers
|
| 29 |
+
- PyTorch
|
| 30 |
+
- Uvicorn
|
| 31 |
|
| 32 |
+
## Deployment
|
| 33 |
|
| 34 |
+
This project is configured to run as a **Docker Space** on Hugging Face.
|
| 35 |
|
| 36 |
+
The application starts automatically using the provided `Dockerfile`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|