Agricultural Intelligence System for Uganda β crop price forecasting, counterfeit input detection, and market intelligence delivered to farmers via web dashboard and USSD.
Built by Keith Ndiema Kissa (2025/BCS/101/PS) Β· Mbarara University of Science and Technology
Submitted: Ministry of ICT Government Systems Prototype Showcase 2026 Β·
Ugandan farmers face three compounding challenges:
- Price blindness β no reliable way to know if today is a good day to sell
- Counterfeit inputs β fake seeds and pesticides cost farmers yield and money
- Market fragmentation β price gaps between markets go unexploited because farmers lack data
AgriGuard is a three-module intelligence layer:
| Module | What it does | How |
|---|---|---|
| Price Forecasting | Predicts crop prices 4 weeks ahead | XGBoost + Prophet on WFP price history |
| Input Validator | Flags suspicious agro-input reports | Isolation Forest anomaly detection + Claude Vision label scanner |
| Market Intelligence | Cross-market comparisons, arbitrage signals | FastAPI serving WFP data with trend analytics |
Accessible via a Streamlit web dashboard and a USSD interface (*183*7#) for farmers without smartphones.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Streamlit Frontend (port 8501) β
β Home Β· Dashboard Β· USSD Simulator β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β HTTP / REST
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β FastAPI Backend (port 8000) β
β /forecasts /markets /prices /api/v1/predict β
β /api/v1/validate /health β
ββββββββ¬ββββββββββββββ¬βββββββββββββββ¬ββββββββββββββββββ
β β β
XGBoost Prophet MySQL DB
+ IsoForest fallback (price history)
.pkl models (no model)
β
WFP Uganda CSV β scripts/download_wfp_data.py
git clone https://github.com/Agri-Guard/AgriGuard.git
cd AgriGuard
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txtcp config/env.example config/.env
# Edit config/.env β set DB credentials and ANTHROPIC_API_KEYpython scripts/download_wfp_data.py # ~2 MB WFP Uganda CSV
python scripts/train_models.py # trains XGBoost + Isolation Forestdocker-compose up --build- Dashboard: http://localhost:8501
- API docs: http://localhost:8000/docs
# Terminal 1 β backend
uvicorn backend.app.main:app --reload --port 8000
# Terminal 2 β frontend
cd frontend
streamlit run Home.py --server.port 8501AgriGuard/
βββ backend/
β βββ Dockerfile
β βββ app/
β βββ main.py # FastAPI entry point + router wiring
β βββ config.py # Pydantic settings (env-var driven)
β βββ database.py # SQLAlchemy engine + session
β βββ model.py # ML model loader + inference
β βββ validator.py # Input validation
β βββ schemas.py # Core Pydantic schemas
β βββ models/
β β βββ price.py # SQLAlchemy ORM models
β βββ schemas/
β β βββ price.py # Price-domain Pydantic schemas
β βββ routers/
β β βββ forecasts.py # Prophet/XGBoost forecast endpoints
β β βββ markets.py # Market intelligence endpoints
β β βββ prices.py # CRUD price observation endpoints
β βββ services/
β βββ price_service.py
βββ frontend/
β βββ Dockerfile
β βββ Home.py # Landing page
β βββ pages/
β βββ dashboard.py # Main 5-tab dashboard
β βββ ussd_simulator.py # Feature-phone USSD demo
βββ scripts/
β βββ download_wfp_data.py # Fetch WFP Uganda CSV from HDX
β βββ train_models.py # Train XGBoost + Isolation Forest
βββ ml/
β βββ models/ # Saved .pkl files (gitignored)
β βββ metrics.json # Evaluation metrics (committed)
βββ data/
β βββ raw/ # WFP CSV (gitignored)
βββ config/
β βββ env.example # Copy to .env and fill in
βββ docker-compose.yml
βββ requirements.txt
βββ README.md
Features: temporal (year, month, week, day-of-year, cyclic month encoding), lag prices (1m, 3m, 6m), 3-month rolling average, label-encoded crop and market.
Training split: 80/20 time-ordered (no data leakage).
Metrics (see ml/models/metrics.json after training):
| Metric | Value |
|---|---|
| MAE | ~120 UGX/kg |
| MAPE | ~8% |
| RΒ² | ~0.91 |
Prophet is used as an alternative for single-series forecasting and as a confidence-interval reference.
Trained on the price feature space. Inputs that deviate significantly from the training distribution are flagged as potentially anomalous. contamination=0.05 (tunable based on field error rate estimates from MAAIF).
Full interactive docs at /docs when the backend is running.
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
System health check |
| POST | /api/v1/predict |
Quick price prediction |
| POST | /api/v1/validate |
Fake input detector |
| GET | /forecasts/{commodity} |
ML price forecast |
| GET | /forecasts/commodities |
List available crops/markets |
| GET | /markets/summary/{commodity} |
Best/worst market |
| GET | /markets/movers |
Biggest price gainers/losers |
| GET | /markets/national-summary |
All commodities snapshot |
| GET | /prices |
Paginated price history |
| GET | /prices/alerts |
Food security spike alerts |
- WFP VAM Food Prices β Uganda (HDX, open license) β historical crop prices across Ugandan markets
- Open-Meteo β free 7-day weather forecasts (no API key required)
- Anthropic Claude Vision API β counterfeit label scanning
- SMS push alerts via Africa's Talking
- Satellite crop health integration (Sentinel-2)
- District-level food security index
- Mobile app (React Native)
- Multi-country expansion (Kenya, Tanzania)
AGPL-3.0 β see LICENSE
Keith Ndiema Kissa
BSc Computer Science Β· Mbarara University of Science and Technology
veritasndiema@gmail.com Β· GitHub: Ve-stora