Demonstrating ML pipelines and model deployment.
- ✅ ML Pipeline: Data preprocessing, model training, evaluation, serialization
- ✅ Model Deployment: FastAPI REST API for real-time inference
- ✅ Interactive UI: Streamlit app with real-time sentiment analysis
- ✅ Monitoring: Health checks, metrics logging, version tracking
cd ml-pipeline-demo
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtcd src
python pipeline.pycd src
streamlit run app.pyOpens at http://localhost:8501 with:
- 🎯 Beautiful gradient UI
- 📊 Real-time sentiment analysis
- 📈 Analysis history tracking
- 🎲 Quick example buttons
Output:
ML Pipeline Demo: Sentiment Classification
==========================================
Loaded 200 samples
Training Metrics:
Accuracy: 0.9750
Precision: 0.9756
Recall: 0.9750
F1 Score: 0.9750
Model saved to: models/v1
python server.pyServer runs at http://localhost:8000
# Health check
curl http://localhost:8000/api/v1/health
# Make prediction
curl -X POST http://localhost:8000/api/v1/predict \
-H "Content-Type: application/json" \
-d '{"texts": ["This product is amazing!", "Terrible experience."]}'ml-pipeline-demo/
├── src/
│ ├── app.py # Streamlit UI (recommended)
│ ├── pipeline.py # ML pipeline (preprocessing, training, evaluation)
│ └── server.py # FastAPI model deployment server
├── models/ # Trained model artifacts (auto-generated)
└── requirements.txt
# TF-IDF vectorization with n-grams
vectorizer = TfidfVectorizer(
max_features=5000,
ngram_range=(1, 2),
stop_words='english'
)# Logistic Regression with balanced classes
model = LogisticRegression(
C=1.0,
max_iter=1000,
class_weight='balanced'
)- Accuracy, Precision, Recall, F1 Score
- Classification report with per-class metrics
model.joblib: Trained classifiervectorizer.joblib: Fitted TF-IDF vectorizermetadata.json: Training metrics and hyperparameters
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | API info |
/api/v1/health |
GET | Health check with model metrics |
/api/v1/predict |
POST | Single/batch predictions |
/docs |
GET | Interactive API documentation |
| Skill | Implementation |
|---|---|
| ML Pipelines | pipeline.py - preprocessing, training, evaluation |
| Model Deployment | server.py - FastAPI REST API with health checks |
| Model Monitoring | Metrics logging, version tracking |
| Interactive UI | app.py - Streamlit with session state |
| Python Best Practices | Type hints, docstrings, modular design |
MIT
