Containerized microservice providing SMS spam classification using machine learning.
Team: doda2025-team24
Repository: https://github.com/doda2025-team24/model-service
- Runtime: Python 3.12.9
- Web Framework: Flask with Swagger UI
- Machine Learning: scikit-learn, NLTK, Decision Tree classifier
- Containerization: Docker (supports amd64 and arm64)
Model files are downloaded at runtime from GitHub Releases rather than being embedded in the Docker image. This design allows for model updates without requiring container rebuilds. Models can also be provided via volume mounts for faster initialization.
Pull the container image and start the service:
Windows PowerShell:
docker pull ghcr.io/doda2025-team24/model-service:latest
docker run -d -p 8081:8081 `
-e GITHUB_REPO=doda2025-team24/model-service `
--name model-service `
ghcr.io/doda2025-team24/model-service:latest
# Allow 30-60 seconds for model download, then verify
Invoke-RestMethod http://localhost:8081/healthLinux/Mac:
docker pull ghcr.io/doda2025-team24/model-service:latest
docker run -d -p 8081:8081 \
-e GITHUB_REPO=doda2025-team24/model-service \
--name model-service \
ghcr.io/doda2025-team24/model-service:latest
curl http://localhost:8081/healthFor faster startup when model files are available locally:
# Windows
docker run -d -p 8081:8081 -v ${PWD}/output:/app/models --name model-service ghcr.io/doda2025-team24/model-service:latest
# Linux/Mac
docker run -d -p 8081:8081 -v ./output:/app/models --name model-service ghcr.io/doda2025-team24/model-service:latestCreate a persistent volume to avoid re-downloading models:
docker volume create model-cache
docker run -d -p 8081:8081 -v model-cache:/app/models -e GITHUB_REPO=doda2025-team24/model-service --name model-service ghcr.io/doda2025-team24/model-service:latest# Windows
Invoke-RestMethod http://localhost:8081/health
# Linux/Mac
curl http://localhost:8081/healthWindows PowerShell:
$body = @{ sms = " Did you hear about the new \"Divorce Barbie\"? It comes with all of Ken's stuff!" } | ConvertTo-Json
Invoke-RestMethod -Uri http://localhost:8081/predict -Method POST -ContentType "application/json" -Body $bodyLinux/Mac:
curl -X POST http://localhost:8081/predict \
-H "Content-Type: application/json" \
-d '{"sms": " Did you hear about the new \"Divorce Barbie\"? It comes with all of Ken's stuff!" }'Expected Response:
{
"result": "spam",
"classifier": "decision tree",
"confidence": 0.92,
"sms": "WIN FREE PRIZE NOW!"
}Interactive API documentation is available at: http://localhost:8081/apidocs
| Environment Variable | Default Value | Description |
|---|---|---|
| MODEL_SERVICE_PORT | 8081 | Port number for the service |
| MODEL_DIR | /model-service/output | Directory where models are stored |
| MODEL_VERSION | latest | Version tag from GitHub releases |
| GITHUB_REPO | doda2025-team24/model-service | Repository for model downloads |
Configuration Examples:
# Custom port configuration
docker run -d -p 9000:9000 -e MODEL_SERVICE_PORT=9000 -e GITHUB_REPO=doda2025-team24/model-service --name model-service ghcr.io/doda2025-team24/model-service:latest
# Specific model version
docker run -d -p 8081:8081 -e MODEL_VERSION=v1.0.0 -e GITHUB_REPO=doda2025-team24/model-service --name model-service ghcr.io/doda2025-team24/model-service:latestModels are trained through automated GitHub Actions workflows:
- Navigate to: https://github.com/doda2025-team24/model-service/actions
- Execute the "Train, Build and Release (Automated)" workflow
- Provide a version identifier (example: v1.0.0) and release notes
- The workflow trains the model and publishes it as a GitHub release
- Deploy the new model version using:
docker run -e MODEL_VERSION=v1.0.0 ...
View all available model releases at: https://github.com/doda2025-team24/model-service/releases
Building and running locally:
# Build local image
docker build -t model-service:local .
# Run with local model files
docker run -d -p 8081:8081 -v ${PWD}/output:/app/models --name test model-service:local
# Test the service
Invoke-RestMethod http://localhost:8081/health
# Cleanup
docker stop test && docker rm test# View container logs
docker logs -f model-service
# Stop the service
docker stop model-service
# Remove the container
docker rm model-service
# Stop and remove in one command
docker rm -f model-serviceContainer fails to start:
docker logs model-service # Examine error messages