AI-powered ingredient health analyzer built with Flask, scikit-learn, and a production-oriented project layout.
Live app: https://nutrigaurd.onrender.com
- Ingredient analysis using TF-IDF + Random Forest regression
- Web UI for instant health score prediction
- Service-oriented backend structure (app factory + route layer + predictor service)
- Separate frontend asset/template directory for maintainability
- Reusable model artifacts via joblib
Machine-learning-P1/
├── backend/
│ ├── __init__.py # Flask app factory
│ ├── config.py # Runtime and path settings
│ ├── routes.py # HTTP routes (/ and /predict)
│ ├── models/ # Trained ML artifacts
│ │ ├── random_forest_model.pkl
│ │ └── tfidf_vectorizer.pkl
│ └── services/
│ └── predictor.py # ML inference service
├── frontend/
│ ├── templates/
│ │ └── index.html # Main UI template
│ └── static/
│ ├── css/
│ │ └── style.css # UI styles
│ └── js/
│ └── script.js # Client-side logic
├── scripts/
│ ├── train_model.py # Train model and save artifacts
│ └── predict_sample.py # CLI sample prediction
├── config/
│ ├── deployment/
│ │ ├── Procfile # Canonical deploy process file
│ │ └── runtime.txt # Canonical Python runtime version
│ ├── docs/
│ │ └── DEPLOYMENT.md # Deployment guide
│ └── requirements/
│ └── base.txt # Canonical Python dependencies
├── run.py # WSGI entrypoint for deployment
├── app.py # Backward-compatible local runner
├── requirements.txt # Root compatibility file (includes config/requirements/base.txt)
├── Procfile # Root compatibility file
└── runtime.txt # Root compatibility file
- Install dependencies:
pip install -r requirements.txt- Run the web app:
python run.py- Open:
http://localhost:5000
Train with default dataset/output paths:
python scripts/train_model.pyOptional custom paths:
python scripts/train_model.py --data path/to/cleaned_ingredients_dataset.csv --model-output random_forest_model.pkl --vectorizer-output tfidf_vectorizer.pklExample with backend output location:
python scripts/train_model.py --model-output backend/models/random_forest_model.pkl --vectorizer-output backend/models/tfidf_vectorizer.pklpython scripts/predict_sample.py --ingredients "oats, almonds, honey"The app is deployment-ready with Gunicorn:
web: gunicorn run:app
Note: canonical config copies live under config/, while root files are retained for platform compatibility.
MIT License