ZeniTsuIsSimP/npk-crop-recommendation
0
1---2title: NPK Crop Intelligence3emoji: ๐พ4colorFrom: green5colorTo: yellow6sdk: streamlit7sdk_version: "1.28.0"8app_file: app/npk_crop_recommendation_app.py9pinned: false10license: mit11---12 13# ๐พ NPK Crop Intelligence โ MLOps Edition14 15[](https://github.com/ZeniTsuisSimp/NPK-LIVE/actions/workflows/ci.yml)16[](https://huggingface.co/spaces/ZeniTsuisSimp/npk-crop-recommendation)17181920 21**Live Project:** https://huggingface.co/spaces/ZeniTsuisSimp/npk-crop-recommendation22 23 24Smart soil analysis and crop recommendation system powered by **Machine Learning**, built with **MLOps best practices** โ DVC, MLflow, Docker, and CI/CD.25 26---27 28## ๐๏ธ Architecture29 30```mermaid31graph LR32 A[๐ Dataset] -->|DVC tracked| B[๐ง Preprocessing]33 B --> C[๐ค Training]34 C -->|MLflow logged| D[๐ Evaluation]35 D --> E[โ
Model .pkl]36 E --> F[๐ Streamlit App]37 F -->|Docker| G[โ๏ธ Deployment]38 39 subgraph "CI/CD"40 H[GitHub Push] --> I[Lint + Test]41 I --> J[Train Pipeline]42 J --> K[Docker Build]43 K --> L[Deploy]44 end45```46 47## ๐ Project Structure48 49```50NPK-LIVE/51โโโ .github/workflows/ # CI/CD pipelines52โ โโโ ci.yml # Lint, test, train on push/PR53โ โโโ cd.yml # Docker build + deploy on main54โโโ src/ # Modular ML pipeline55โ โโโ data_preprocessing.py56โ โโโ train.py # MLflow-integrated training57โ โโโ evaluate.py # Metrics generation58โโโ app/ # Streamlit application59โ โโโ npk_crop_recommendation_app.py60โโโ tests/ # Unit tests61โ โโโ test_pipeline.py62โโโ data/ # Raw dataset63โ โโโ Crop_recommendation.csv64โโโ models/ # Trained model artifacts65โ โโโ npk_crop_model.pkl66โโโ notebooks/ # Jupyter notebooks67โโโ reports/ # Auto-generated metrics68โโโ params.yaml # Hyperparameter config69โโโ dvc.yaml # DVC pipeline stages70โโโ Dockerfile # Container config71โโโ docker-compose.yml # Docker Compose72โโโ requirements.txt # Production deps73โโโ requirements-dev.txt # Dev/test deps74```75 76## ๐ Quick Start77 78### 1. Clone & Install79```bash80git clone https://github.com/ZeniTsuisSimp/NPK-LIVE.git81cd NPK-LIVE82pip install -r requirements.txt83pip install -r requirements-dev.txt84pip install -e .85```86 87### 2. Run the ML Pipeline88```bash89# Step-by-step90python -m src.data_preprocessing91python -m src.train92python -m src.evaluate93 94# Or use DVC95dvc repro96```97 98### 3. Launch the App99```bash100streamlit run app/npk_crop_recommendation_app.py101```102 103### 4. Run with Docker104```bash105docker-compose up --build106# Visit http://localhost:8501107```108 109## ๐ฌ MLOps Stack110 111| Tool | Purpose |112|------|---------|113| **MLflow** | Experiment tracking (params, metrics, model artifacts) |114| **DVC** | Data versioning & reproducible pipelines |115| **Docker** | Containerized deployment |116| **GitHub Actions** | CI (lint + test) and CD (Docker + deploy) |117| **pytest** | Unit testing |118| **flake8** | Code linting |119 120### View MLflow Experiments121```bash122mlflow ui123# Visit http://localhost:5000124```125 126### Run DVC Pipeline127```bash128dvc repro # Run full pipeline129dvc metrics show # View latest metrics130dvc dag # Visualize pipeline DAG131```132 133## ๐งช Testing134```bash135pytest tests/ -v136```137 138## ๐ CI/CD Pipeline139 140### CI (on every push/PR)1411. **Lint** โ `flake8` syntax & style checks1422. **Test** โ `pytest` unit tests1433. **Train** โ Full preprocessing โ training โ evaluation1444. **Verify** โ Model and metrics artifacts exist145 146### GitHub Secrets Required147- `HF_USERNAME` โ Hugging Face username148- `HF_TOKEN` โ Hugging Face Write Token149 150## ๐ App Features151 152- ๐พ **Crop Prediction** โ ML-based crop recommendation from soil NPK values153- ๐งช **NPK Additions** โ Calculate nutrient amendments for target crops154- ๐ **Crop Rotation Advisor** โ Science-based next-crop suggestions155- ๐ **Soil Health Score** โ Composite 0-100 health rating with radar chart156- ๐
**Seasonal Calendar** โ Indian Kharif/Rabi/Zaid crop calendar157- ๐ **NPK History** โ Track soil readings over time158 159## ๐ Model Details160 161| Parameter | Value |162|-----------|-------|163| Algorithm | Random Forest Classifier |164| Features | N, P, K (mg/kg) |165| Crops | Rice, Wheat, Corn, Barley, Soybean, Cotton, Sugarcane, Tomato, Potato, Onion |166| Config | `params.yaml` |167 168---169 170*Built with โค๏ธ using Streamlit, scikit-learn, MLflow, and DVC*