AgriPrice Predict is an enterprise-grade forecasting platform designed to mitigate supply chain risks in the agricultural sector. It combines a robust Python-based predictive engine with a modern Next.js dashboard to provide real-time price intelligence and actionable business strategies.
- Backend: FastAPI (Python 3.12) serving a machine learning pipeline that includes SARIMA, XGBoost, and LSTM models.
- Frontend: Next.js (TypeScript) dashboard utilizing Recharts for visualization and Tailwind CSS for a premium UI.
- Data Pipeline: Automated cleaning, EDA, model training, and evaluation cycles.
- Deployment: Fully containerized with Docker and Docker Compose.
- Docker & Docker Compose
- Python 3.12+ (if running locally without Docker)
- Node.js 20+ (if running locally without Docker)
The easiest way to run the entire stack is using Docker Compose:
docker-compose up --build- Frontend:
http://localhost:3000 - Backend API:
http://localhost:8000 - API Docs:
http://localhost:8000/docs
- Navigate to the
backend/directory. - Install dependencies using
uvorpip:uv sync # OR pip install -r requirements.txt - Run the data pipeline to generate models and forecasts:
python main.py pipeline
- Start the FastAPI server:
python main.py server
- Navigate to the
frontend/directory. - Install dependencies:
npm install
- Start the development server:
npm run dev
The system follows a sequential pipeline:
- Cleaning (
Q1): Handles missing values via time-interpolation and removes outliers using the IQR method. - EDA & Training (
Q2): Performs seasonal decomposition and trains three models:- SARIMA: Statistical model for capturing seasonality.
- XGBoost: Gradient boosted trees for capturing non-linear patterns.
- LSTM: Deep learning model for long-term sequence dependencies.
- Evaluation (
Q3): Compares models using MAE, RMSE, and MAPE metrics. - Integration (
Q7): Exposes the XGBoost model via a REST API for real-time inference.
Configure these in your production environment or .env files:
| Variable | Description | Default |
|---|---|---|
PORT |
Backend server port | 8000 |
ALLOWED_ORIGINS |
CORS allowed origins (comma-separated) | * |
DATA_RAW |
Path to raw input CSV | data/raw/agricultural_prices.csv |
MODELS_DIR |
Directory to store trained models | models/ |
NEXT_PUBLIC_API_URL |
Frontend pointer to Backend API | http://localhost:8000 |
- CORS: In production, set
ALLOWED_ORIGINSto your frontend domain. - Secrets: Change
SECRET_KEYinbackend/.envto a secure random string. - Docker: The provided
Dockerfiles use multi-stage builds and non-root users (where applicable) for security.
- Health Check: Monitor
GET /healthfor backend status. - Logs: Backend uses standard Python logging for easier integration with ELK or CloudWatch.
- Price Trends: Interactive line charts showing historical vs. forecasted prices.
- What-if Analysis: A custom prediction form to test "what-if" scenarios based on the last 12 months of price data.
- Risk Mitigation: AI-driven strategy cards providing procurement and supply chain advice based on volatility forecasts.
This project is pre-configured for Render.com using the render.yaml blueprint.
- Connect your GitHub repository to Render.
- Select "Blueprint" and choose
Agriculture-Forecasting. - Render will automatically build the Docker container and deploy it.
- Important: The free tier has 512MB RAM. The
Dockerfileis optimized to usetensorflow-cpuand a single Gunicorn worker to stay within these limits.
The Next.js frontend is best deployed on Vercel.
- Connect your GitHub repository to Vercel.
- Add an Environment Variable:
NEXT_PUBLIC_API_URL: Your Render backend URL (e.g.,https://agri-forecast-backend.onrender.com).
- Vercel will handle the build and deployment automatically.
- Fork the repo.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.