Complete instructions for running the Sentiment Classification MLOps pipeline locally or deploying to AWS.
- Python 3.10+
- Git
- Docker (for containerization)
- AWS Account (for cloud deployment)
- DagShub Account (for MLOps tracking)
git clone https://github.com/CodeBy-HP/Sentiment-Classification.git
cd Sentiment-Classificationpython -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activatepip install -r requirements.txtpython -c "import nltk; nltk.download('stopwords'); nltk.download('wordnet')"Create a .env file in the root directory:
# MLflow & DagShub
MLFLOW_TRACKING_URI=https://dagshub.com/your-username/Sentiment-Classification.mlflow
MLFLOW_TRACKING_USERNAME=your-dagshub-username
MLFLOW_TRACKING_PASSWORD=your-dagshub-token
# AWS (optional for S3)
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
AWS_DEFAULT_REGION=us-east-1dvc pull # Pull data from remote storagedvc reproThis runs all stages:
- Data ingestion
- Preprocessing
- Feature engineering
- Model training
- Evaluation
- Model registration
dvc repro data_ingestion
dvc repro feature_engineering
# ... etcdvc dagmlflow uiVisit: http://localhost:5000
Visit your DagShub repository → MLflow tab to see:
- All experiments
- Model metrics
- Registered models
- Model versions
pytest tests/# Test model
pytest tests/test_model.py
# Test FastAPI app
pytest tests/test_fastapi_app.pypytest tests/ --cov=sentiment_classificationcd fastapi_app
uvicorn app:app --reload --host 0.0.0.0 --port 8000- Web UI:
http://localhost:8000 - API Docs:
http://localhost:8000/docs - Health Check:
http://localhost:8000/health
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "This movie was absolutely amazing!"}'docker build -t sentiment-classification:latest .docker run -d \
--name sentiment-app \
-p 8000:8000 \
-v $(pwd)/models:/app/models \
sentiment-classification:latestcurl http://localhost:8000/healthdocker logs -f sentiment-appdocker stop sentiment-app
docker rm sentiment-app- AWS CLI configured (
aws configure) - ECR repository created
- EC2 instance running (Ubuntu recommended)
# Authenticate Docker to ECR
aws ecr get-login-password --region us-east-1 | \
docker login --username AWS --password-stdin <aws-account-id>.dkr.ecr.us-east-1.amazonaws.com
# Tag image
docker tag sentiment-classification:latest \
<aws-account-id>.dkr.ecr.us-east-1.amazonaws.com/sentiment-classification:latest
# Push to ECR
docker push <aws-account-id>.dkr.ecr.us-east-1.amazonaws.com/sentiment-classification:latestSSH into your EC2 instance:
ssh -i your-key.pem ubuntu@your-ec2-ipInstall Docker on EC2:
sudo apt update
sudo apt install docker.io -y
sudo systemctl start docker
sudo usermod -aG docker ubuntuPull and run container:
# Login to ECR
aws ecr get-login-password --region us-east-1 | \
sudo docker login --username AWS --password-stdin <aws-account-id>.dkr.ecr.us-east-1.amazonaws.com
# Pull image
sudo docker pull <aws-account-id>.dkr.ecr.us-east-1.amazonaws.com/sentiment-classification:latest
# Run container
sudo docker run -d \
--name sentiment-app \
-p 80:8000 \
--restart unless-stopped \
<aws-account-id>.dkr.ecr.us-east-1.amazonaws.com/sentiment-classification:latest- Allow inbound traffic on port 80 (HTTP)
- Allow inbound traffic on port 8000 (if testing directly)
Visit: http://your-ec2-public-ip
Go to your repo → Settings → Secrets and add:
CAPSTONE_TEST
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
AWS_ACCOUNT_ID
ECR_REPOSITORY
On your EC2 instance:
# Download runner
mkdir actions-runner && cd actions-runner
curl -o actions-runner-linux-x64-2.311.0.tar.gz -L \
https://github.com/actions/runner/releases/download/v2.311.0/actions-runner-linux-x64-2.311.0.tar.gz
tar xzf ./actions-runner-linux-x64-2.311.0.tar.gz
# Configure
./config.sh --url https://github.com/your-username/Sentiment-Classification --token YOUR_TOKEN
# Run as service
sudo ./svc.sh install
sudo ./svc.sh startPush code to main branch:
git add .
git commit -m "Deploy new model"
git push origin mainGitHub Actions will:
- Run DVC pipeline
- Test model quality
- Promote if better
- Test API
- Build Docker image
- Push to ECR
- Deploy to EC2
docker logs -f sentiment-appcurl http://localhost:8000/healthCheck DagShub for real-time metrics and experiment tracking.
Happy Experimenting! 🚀