A production-ready sentiment analysis API built with FastAPI, scikit-learn, and Docker.
This API analyzes the sentiment of a given text (positive or negative) using a Machine Learning model.
The goal of this project is to demonstrate:
- Building REST APIs with FastAPI
- Integrating ML models into production systems
- Writing clean, maintainable project structures
- Testing and validation
- Containerization with Docker
- Python
- FastAPI
- scikit-learn
- Docker
- Pytest
- ml-api-sentiment/
-
app/
- main.py # API endpoints
- model/ # ML model
- schemas/ # Request validation
- services/ # Business logic
- utils/ # Logging utilities
-
tests/ # Unit tests
-
Dockerfile
-
requirements.txt
-
README.md
-
pip install -r requirements.txtuvicorn app.main:app --reloadBuild the image
docker build -t sentiment-api .Run the container
docker run -p 8010:8010 sentiment-apiThis project is deployed using Render. You can find a live demo in: https://sentiment-api-0zg1.onrender.com/docs
Open:
- Health Check
GET /healthResponse:
{
"status": "healthy"
}- Predict Sentiment
POST /predictRequest:
{
"text": "I love this product"
}Response:
{
"sentiment": "positive",
"confidence": 0.87
}Run tests with:
pytest- REST API built with FastAPI
- ML model integration
- Input validation with Pydantic
- Logging of requests and predictions
- Error handling
- Rate limiting
- API versioning
- Unit testing
- Dockerized for deployment
- Cloud deployment (Render)
- Replace dummy model with a real trained dataset
- Add authentication (API keys / JWT)
- Monitoring (Prometheus / Grafana)
- CI/CD pipeline
Built as part of a Machine Learning / AI Engineering portfolio.
This project demonstrates the ability to:
- Bring ML models into production
- Build scalable backend systems
- Combine ML + backend engineering