Hackathon Contest
Youth Digital Citizen Challenge 2025 Theme: AI for Climate: Twin Transition in Action
This project is developed as part of Youth Digital Citizen Challenge 2025, focusing on applying Artificial Intelligence to address climate-related challenges, particularly in agriculture and food security.
The solution aligns with the Twin Transition approach:
-
Green transition: reducing crop loss and chemical overuse through early disease detection
-
Digital transition: leveraging AI, data, and automation to support farmers’ decision-making
Rice AI Backend – Disease Detection & Outbreak Risk API
Problem Statement
Rice farmers often face significant crop losses due to late detection of rice diseases and lack of early warning systems for disease outbreaks. Traditional inspection methods are manual, time-consuming, and do not scale well across large farming regions.
Additionally, farmers usually lack actionable information after detecting a disease, such as:
-
What disease it is ?
-
How serious the infection might be ?
-
Whether it could spread into an outbreak ?
-
What treatment actions should be taken ?
Solution Overview
Rice AI Backend is a FastAPI-based AI service that provides:
Image-based rice disease detection using a deep learning model (DINOv2)
Outbreak risk prediction based on recent disease reports and environmental signals
Disease knowledge retrieval (RAG) to suggest symptoms and treatment information
RESTful APIs designed for easy integration with mobile or web applications
The system is designed for hackathon deployment, rapid integration, and future scalability.
Key Features
-
Rice disease classification from images
-
Outbreak risk forecasting (low / medium / high)
-
Retrieval-Augmented Generation (RAG) for disease knowledge & treatment
-
Asynchronous inference using background tasks
-
Clean REST API for frontend & mobile teams
-
Pre-trained AI models (ready-to-use artifacts)
Project Structure
.
├── main.py # FastAPI entry point
├── api/ # API routes
│ ├── disease.py # Disease detection endpoints
│ ├── outbreak.py # Outbreak prediction endpoints
│ ├── rag.py # Disease knowledge (RAG)
│ └── health.py # Health check
├── services/ # Core AI logic
│ ├── disease_service.py
│ └── outbreak_service.py
├── models/ # Pydantic schemas
├── rag/ # RAG pipeline (FAISS + LLM)
├── knowledge/ # Disease knowledge base
├── artifact/ # Trained model artifacts
├── core/ # Configuration
└── data/
Setup & Installation
Prerequisites
Python 3.10+
pip
CPU environment (GPU optional)
OS: Windows / Linux / macOS
Install Dependencies
pip install -r requirements.txt
Main dependencies:
fastapi
uvicorn
pydantic
numpy
joblib
scikit-learn
xgboost
torch
torchvision
python-multipart
faiss-cpu
sentence-transformers
transformers
requests
Run Instructions
Local Host
uvicorn app.main:app --reload
API Documentation (Swagger UI)
http://localhost:8000/docs
Health Check
GET /health
Response:
{
"status": "ok"
}
User Guide – API Usage
1. Disease Detection (Image Upload)
Backbone: DINOv2 (Vision Transformer)
Framework: PyTorch
Input: Leaf image (JPEG / PNG)
Output:
-
Disease name
-
Confidence score
-
Full probability distribution
-
Health status (healthy / unhealthy)
Asynchronous inference is handled using FastAPI BackgroundTasks to improve responsiveness.
Endpoint
POST /observations
Request
-
multipart/form-data
-
Field: image (JPEG / PNG)
Response
{
"observation_id": "uuid",
"status": "queued"
}
POST/observation response
2. Get Disease Detection Result
Endpoint
GET /observations/{observation_id}
Response
{
"status": "done",
"result": {
"status": "unhealthy",
"disease": "Bacterial Leaf Blight",
"confidence": 0.92,
"all_probabilities": {
"Bacterial Leaf Blight": 0.92,
"Brown Spot": 0.04,
"Healthy Rice Leaf": 0.04
}
}
}
GET/observation/{observation_id} response
3. Outbreak Risk Prediction
Model: Classical ML (Logistic Regression)
Inputs:
-
Recent disease reports (3d / 7d / 14d)
-
User diversity signals
-
Climate indicators (rainfall, temperature)
Outputs:
-
Outbreak risk score
-
Risk level (low / medium / high)
-
Binary outbreak prediction
This component enables early warning signals for regional disease spread.
Endpoint
POST /outbreak/predict
Request Body
{
"dominant_disease": "Bacterial Leaf Blight",
"reports_3d": 12,
"reports_7d": 30,
"reports_14d": 55,
"unique_users_7d": 18,
"same_disease_ratio": 0.7,
"rainfall_7d": 120,
"avg_temp_7d": 29
}
Response
{
"outbreak_risk_score": 0.78,
"risk_level": "high",
"outbreak_predicted": 1,
"threshold": 0.6,
"model_info": {
"created_at": "2025-01",
"description": "XGBoost outbreak forecasting model"
}
}
POST/outbreak/predict input
POST/outbreak/predict output
4. Disease Information & Treatment (RAG)
Embeddings: Sentence Transformers
Vector Database: FAISS
Knowledge Source: Structured disease JSON documents
Function:
-
Retrieve disease-specific symptoms & treatments
-
Return structured, explainable responses
A dedicated ingestion pipeline builds the FAISS index before API runtime.
Endpoint
POST /rag/disease-info
Request Body
{
"disease": "Bacterial Leaf Blight",
"status": "unhealthy"
}
Response
{
"status": "unhealthy",
"disease": "Bacterial Leaf Blight",
"symptoms": [...],
"treatment": [...]
}
RAG/rag/disease-info input
RAG/rag/disease-info output
AI Models Used
Disease Classification
Backbone: DINOv2 (ViT)
Framework: PyTorch
Outbreak Prediction
Model: Classical ML (XGBoost)
RAG System
Embeddings: Sentence Transformers
Vector DB: FAISS
Notes for Hackathon
Fake in-memory database is used for observations
Models are preloaded on startup
System is optimized for demo & prototype scale
Ready for cloud deployment (Render, Docker, etc.)