CoolFace
Apppublic

ZeniTsuIsSimP/npk-crop-recommendation

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
README.md170 linesDownload Raw Back to root
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[![CI Pipeline](https://github.com/ZeniTsuisSimp/NPK-LIVE/actions/workflows/ci.yml/badge.svg)](https://github.com/ZeniTsuisSimp/NPK-LIVE/actions/workflows/ci.yml)16[![Hugging Face Spaces](https://img.shields.io/badge/๐Ÿค—%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/ZeniTsuisSimp/npk-crop-recommendation)17![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)18![MLflow](https://img.shields.io/badge/MLflow-tracked-orange.svg)19![DVC](https://img.shields.io/badge/DVC-versioned-purple.svg)20 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*