CoolFace
Apppublic

ZeniTsuIsSimP/npk-crop-recommendation

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

๐ŸŒพ NPK Crop Intelligence โ€” MLOps Edition

![CI Pipeline](https://github.com/ZeniTsuisSimp/NPK-LIVE/actions/workflows/ci.yml) ![Hugging Face Spaces](https://huggingface.co/spaces/ZeniTsuisSimp/npk-crop-recommendation) Python 3.11 MLflow DVC

Live Project: https://huggingface.co/spaces/ZeniTsuisSimp/npk-crop-recommendation

Smart soil analysis and crop recommendation system powered by Machine Learning, built with MLOps best practices โ€” DVC, MLflow, Docker, and CI/CD.


๐Ÿ—๏ธ Architecture

mermaid
graph LR
    A[๐Ÿ“Š Dataset] -->|DVC tracked| B[๐Ÿ”ง Preprocessing]
    B --> C[๐Ÿค– Training]
    C -->|MLflow logged| D[๐Ÿ“ˆ Evaluation]
    D --> E[โœ… Model .pkl]
    E --> F[๐ŸŒ Streamlit App]
    F -->|Docker| G[โ˜๏ธ Deployment]

    subgraph "CI/CD"
        H[GitHub Push] --> I[Lint + Test]
        I --> J[Train Pipeline]
        J --> K[Docker Build]
        K --> L[Deploy]
    end

๐Ÿ“‚ Project Structure

NPK-LIVE/
โ”œโ”€โ”€ .github/workflows/      # CI/CD pipelines
โ”‚   โ”œโ”€โ”€ ci.yml               # Lint, test, train on push/PR
โ”‚   โ””โ”€โ”€ cd.yml               # Docker build + deploy on main
โ”œโ”€โ”€ src/                     # Modular ML pipeline
โ”‚   โ”œโ”€โ”€ data_preprocessing.py
โ”‚   โ”œโ”€โ”€ train.py             # MLflow-integrated training
โ”‚   โ””โ”€โ”€ evaluate.py          # Metrics generation
โ”œโ”€โ”€ app/                     # Streamlit application
โ”‚   โ””โ”€โ”€ npk_crop_recommendation_app.py
โ”œโ”€โ”€ tests/                   # Unit tests
โ”‚   โ””โ”€โ”€ test_pipeline.py
โ”œโ”€โ”€ data/                    # Raw dataset
โ”‚   โ””โ”€โ”€ Crop_recommendation.csv
โ”œโ”€โ”€ models/                  # Trained model artifacts
โ”‚   โ””โ”€โ”€ npk_crop_model.pkl
โ”œโ”€โ”€ notebooks/               # Jupyter notebooks
โ”œโ”€โ”€ reports/                 # Auto-generated metrics
โ”œโ”€โ”€ params.yaml              # Hyperparameter config
โ”œโ”€โ”€ dvc.yaml                 # DVC pipeline stages
โ”œโ”€โ”€ Dockerfile               # Container config
โ”œโ”€โ”€ docker-compose.yml       # Docker Compose
โ”œโ”€โ”€ requirements.txt         # Production deps
โ””โ”€โ”€ requirements-dev.txt     # Dev/test deps

๐Ÿš€ Quick Start

1. Clone & Install

bash
git clone https://github.com/ZeniTsuisSimp/NPK-LIVE.git
cd NPK-LIVE
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -e .

2. Run the ML Pipeline

bash
# Step-by-step
python -m src.data_preprocessing
python -m src.train
python -m src.evaluate

# Or use DVC
dvc repro

3. Launch the App

bash
streamlit run app/npk_crop_recommendation_app.py

4. Run with Docker

bash
docker-compose up --build
# Visit http://localhost:8501

๐Ÿ”ฌ MLOps Stack

ToolPurpose
MLflowExperiment tracking (params, metrics, model artifacts)
DVCData versioning & reproducible pipelines
DockerContainerized deployment
GitHub ActionsCI (lint + test) and CD (Docker + deploy)
pytestUnit testing
flake8Code linting

View MLflow Experiments

bash
mlflow ui
# Visit http://localhost:5000

Run DVC Pipeline

bash
dvc repro           # Run full pipeline
dvc metrics show    # View latest metrics
dvc dag             # Visualize pipeline DAG

๐Ÿงช Testing

bash
pytest tests/ -v

๐Ÿ”„ CI/CD Pipeline

CI (on every push/PR)

  1. 1.Lint โ€” flake8 syntax & style checks
  2. 2.Test โ€” pytest unit tests
  3. 3.Train โ€” Full preprocessing โ†’ training โ†’ evaluation
  4. 4.Verify โ€” Model and metrics artifacts exist

GitHub Secrets Required

  • โ€”HF_USERNAME โ€” Hugging Face username
  • โ€”HF_TOKEN โ€” Hugging Face Write Token

๐Ÿ“Š App Features

  • โ€”๐ŸŒพ Crop Prediction โ€” ML-based crop recommendation from soil NPK values
  • โ€”๐Ÿงช NPK Additions โ€” Calculate nutrient amendments for target crops
  • โ€”๐Ÿ”„ Crop Rotation Advisor โ€” Science-based next-crop suggestions
  • โ€”๐Ÿ’š Soil Health Score โ€” Composite 0-100 health rating with radar chart
  • โ€”๐Ÿ“… Seasonal Calendar โ€” Indian Kharif/Rabi/Zaid crop calendar
  • โ€”๐Ÿ“ˆ NPK History โ€” Track soil readings over time

๐Ÿ“‹ Model Details

ParameterValue
AlgorithmRandom Forest Classifier
FeaturesN, P, K (mg/kg)
CropsRice, Wheat, Corn, Barley, Soybean, Cotton, Sugarcane, Tomato, Potato, Onion
Configparams.yaml

Built with โค๏ธ using Streamlit, scikit-learn, MLflow, and DVC