ZeniTsuIsSimP/npk-crop-recommendation
0
๐พ NPK Crop Intelligence โ MLOps Edition
 
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
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
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
# Step-by-step
python -m src.data_preprocessing
python -m src.train
python -m src.evaluate
# Or use DVC
dvc repro3. Launch the App
streamlit run app/npk_crop_recommendation_app.py4. Run with Docker
docker-compose up --build
# Visit http://localhost:8501๐ฌ MLOps Stack
View MLflow Experiments
mlflow ui
# Visit http://localhost:5000Run DVC Pipeline
dvc repro # Run full pipeline
dvc metrics show # View latest metrics
dvc dag # Visualize pipeline DAG๐งช Testing
pytest tests/ -v๐ CI/CD Pipeline
CI (on every push/PR)
- Lint โ
flake8syntax & style checks - Test โ
pytestunit tests - Train โ Full preprocessing โ training โ evaluation
- Verify โ Model and metrics artifacts exist
GitHub Secrets Required
HF_USERNAMEโ Hugging Face usernameHF_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
Built with โค๏ธ using Streamlit, scikit-learn, MLflow, and DVC
