
A Python microservice for text sentiment classification, built with FastAPI and powered by Hugging Face Transformers. The service is containerized with Docker for easy deployment and tested with Postman.
- π Sentiment Classification (Positive, Negative, Neutral)
- β‘ FastAPI-powered REST API with automatic docs (
/docs
) - π€ Hugging Face Transformers for state-of-the-art NLP
- π³ Dockerized for scalable deployment
- π§ͺ Tested with Postman
- Python 3.10+
- FastAPI
- Hugging Face Transformers
- Uvicorn (ASGI server)
- Docker
git clone https://github.com/your-username/sentiment-analysis-api.git
cd sentiment-analysis-api
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload
API will be available at:
π http://127.0.0.1:8000
docker build -t sentiment-api .
docker run -d -p 8000:8000 sentiment-api
GET /health
Response:
{"status": "ok"}
POST /predict
Request Body:
{
"text": "I love using FastAPI, it's amazing!"
}
Response:
{
"label": "positive",
"score": 0.98
}
FastAPI provides interactive API docs at:
- Swagger UI β
http://127.0.0.1:8000/docs
- ReDoc β
http://127.0.0.1:8000/redoc
- Import the provided
postman_collection.json
into Postman - Test endpoints
/health
and/predict
sentiment-analysis-api/
βββ app/
β βββ main.py # FastAPI entry point
β βββ models.py # Hugging Face model loader
β βββ schemas.py # Pydantic schemas
β βββ utils.py # Helper functions
β
βββ tests/ # Unit tests
βββ Dockerfile # Docker configuration
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
- Add batch sentiment analysis endpoint
- Add support for multilingual models
- Integrate CI/CD pipeline for automated testing & deployment
- Add Kubernetes deployment files
MIT License Β© 2025 [Engr. Ipaye Babatunde]
π Would you like me to also generate the Dockerfile
+ requirements.txt
+ main.py
starter template so this README is directly usable as a working repo?