# 🌾 AgroAid Mandi Price Prediction API
## Overview
The AgroAid Mandi Price Prediction API is a Machine Learning-powered service that predicts agricultural commodity prices using historical mandi market data.
The API is designed to integrate with the AgroAid platform and provide:
* Real-time price prediction
* 7-day price forecasting
* Market trend analysis
* Confidence scoring
* Sell/Hold recommendations
The model is trained on historical APMC mandi data and deployed using FastAPI and Render.
---
# Project Architecture
```
AgroAid App
│
â–Ľ
Supabase Database
│
â–Ľ
Feature Generation
│
â–Ľ
Mandi Prediction API
│
â–Ľ
LightGBM Model
│
â–Ľ
Prediction Results
```
---
# Technology Stack
### Backend
* Python
* FastAPI
* Pandas
* NumPy
### Machine Learning
* LightGBM
* Scikit-Learn
* Joblib
### Database
* Supabase PostgreSQL
### Deployment
* Render
---
# Project Structure
```
mandi-price-api/
│
├── main.py
├── requirements.txt
├── district_mapping.json
├── commodity_mapping.json
├── README.md
│
├── mandi_price_model.pkl
│
└── training/
├── train_model.ipynb
├── clean_apmc_data.csv
└── feature_engineering.py
```
---
# File Descriptions
## main.py
Main FastAPI application.
Responsibilities:
* Load trained model
* Accept API requests
* Generate predictions
* Generate forecasts
* Calculate trends
* Calculate confidence scores
* Generate recommendations
Available endpoints:
* GET /
* POST /predict
* POST /forecast
* POST /trend
* POST /confidence
* POST /recommendation
---
## mandi_price_model.pkl
Serialized LightGBM model.
Generated after training.
Used for:
* Single day prediction
* Forecast generation
---
## district_mapping.json
District encoder mapping.
Example:
```json
{
"Rewa": 47,
"Bhopal": 12
}
```
Purpose:
Convert district names into numerical values used by the model.
---
## commodity_mapping.json
Commodity encoder mapping.
Example:
```json
{
"Wheat": 58,
"Soybean": 125
}
```
Purpose:
Convert commodity names into numerical values …