Overview • Features • Tech Stack • Project Structure • Getting Started • API Reference • Model Details
CropCast is a full-stack web application that predicts agricultural crop yield (in tonnes/hectare) using a machine learning model trained on 10 years of ICAR (Indian Council of Agricultural Research) crop production data.
Users can select their State, District, Season, Crop, Year, and Area (in hectares) — and receive an instant AI-driven prediction for expected yield and total production.
CropCast outperforms a baseline Linear Regression model by up to 34% with an expected RMSE of ~0.18.
- 🤖 XGBoost ML Model — High-accuracy gradient boosted regression for yield prediction
- ⚡ FastAPI Backend — Lightning-fast REST API with LRU caching for repeated predictions
- ⚛️ React + Vite Frontend — Modern, responsive UI with glassmorphism design
- 🗺️ India-wide Coverage — Supports all Indian states, districts, seasons, and crops
- 📊 Dual Output — Predicted yield per hectare + estimated total production
- 🔄 Dynamic Dropdowns — Fetched live from the API based on trained encoder classes
- 🌑 Dark Mode UI — Sleek dark-themed interface with animated glow effects
- 🐍 Streamlit Prototype — Included legacy Streamlit app for quick local testing
| Technology | Version | Purpose |
|---|---|---|
| Python | 3.10+ | Core language |
| FastAPI | 0.110.0 | REST API framework |
| Uvicorn | 0.28.0 | ASGI server |
| XGBoost | 2.0.3 | ML model for yield prediction |
| scikit-learn | 1.4.1 | Label encoding & preprocessing |
| Pandas | 2.2.1 | Data manipulation |
| Joblib | 1.3.2 | Model serialization |
| Technology | Version | Purpose |
|---|---|---|
| React | 19.x | UI framework |
| Vite | 8.x | Build tool & dev server |
| Vanilla CSS | — | Custom glassmorphism styling |
CropCast/
│
├── backend/
│ ├── app.py # Streamlit app (legacy prototype)
│ ├── main.py # FastAPI server (main backend)
│ ├── train_model.py # Script to train & save the XGBoost model
│ ├── Crop prediction model .py # Jupyter-style crop yield prediction notebook
│ ├── Crop recommendation .py # Crop recommendation logic
│ ├── Crop_Recommendation_Testing_Final.py # Final testing script
│ ├── Data Analysis & Visualization - crop yield dataset.py
│ ├── Crop_recommendation.csv # Crop recommendation dataset
│ ├── crop_production.csv # Main ICAR crop production dataset (10 years)
│ ├── xgb_model.pkl # Trained XGBoost model (serialized)
│ ├── le_dict.pkl # Label encoder dictionary (serialized)
│ └── requirements.txt # Python dependencies
│
├── frontend/
│ ├── public/
│ │ ├── bg.png # Background image
│ │ └── favicon.svg
│ ├── src/
│ │ ├── App.jsx # Main React component
│ │ ├── App.css # Component styles
│ │ ├── index.css # Global styles & design system
│ │ └── main.jsx # React entry point
│ ├── .env # Environment variables (see setup)
│ ├── index.html
│ ├── package.json
│ └── vite.config.js
│
├── .gitignore
└── README.md
- Python 3.10 or higher
- Node.js 18 or higher
- npm 9 or higher
git clone https://github.com/RitikOnWork/CropCast.git
cd CropCastcd backend
# Create and activate a virtual environment (recommended)
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
# Install dependencies
pip install -r requirements.txtpython train_model.pyuvicorn main:app --reload --port 8000The API will be available at: http://localhost:8000
Interactive docs at: http://localhost:8000/docs
cd ../frontend
# Install dependencies
npm installCreate a .env file in the frontend/ directory:
VITE_API_URL=http://localhost:8000npm run devThe app will be available at: http://localhost:5173
Returns all available dropdown options loaded from the trained label encoders.
Response:
{
"states": ["Andhra Pradesh", "Bihar", ...],
"districts": ["Agra", "Aligarh", ...],
"seasons": ["Kharif", "Rabi", "Whole Year", ...],
"crops": ["Apple", "Banana", "Rice", "Wheat", ...]
}Predicts crop yield for the given inputs.
Request Body:
{
"state": "Andhra Pradesh",
"district": "Guntur",
"season": "Kharif",
"crop": "Rice",
"year": 2025,
"area": 500.0
}Response:
{
"predicted_yield_per_hectare": 2.84,
"estimated_production": 1420.0
}| Field | Type | Description |
|---|---|---|
state |
string | Indian state name |
district |
string | District within the state |
season |
string | Crop season (Kharif, Rabi, etc.) |
crop |
string | Crop name |
year |
integer | Crop year (1990–2030) |
area |
float | Area under cultivation (hectares) |
| Property | Value |
|---|---|
| Model Type | XGBoost Regressor |
| Training Data | ICAR Crop Production Dataset (10 years) |
| Target Variable | Crop Yield (tonnes/hectare) |
| Features | State, District, Season, Crop, Year, Area |
| Encoding | Label Encoding (scikit-learn) |
| Serialization | Joblib (.pkl) |
| RMSE | ~0.18 |
| Improvement over Baseline | Up to 34% over Linear Regression |
- Categorical features (
State_Name,District_Name,Season,Crop) are label encoded and stored inle_dict.pkl. - The model is cached at load time using
@st.cache_resource(Streamlit) andlru_cache(FastAPI) to optimize repeated predictions.
- Filter districts dynamically based on selected state
- Add confidence intervals to predictions
- Historical yield trend visualizations (charts)
- Deploy backend on Render / Railway
- Deploy frontend on Vercel / Netlify
- Add crop recommendation feature to the UI
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Open a Pull Request
This project is licensed under the MIT License.
Made with ❤️ by Ritik