This project containerizes a FastAPI application with BERT (DistilBERT) model inference using Docker. The application provides sentiment analysis capabilities through REST API endpoints.
/
├── Dockerfile - Docker configuration to build the container image
├── main.py - FastAPI application with BERT sentiment classification
├── requirements.txt - Python dependencies
└── README.md - This file
- Hello World Endpoint: Simple GET endpoint at
/that returns a greeting message - BERT Sentiment Classification: POST endpoint at
/classifythat analyzes text sentiment - Health Check: GET endpoint at
/healthfor monitoring container status - Exposed Port: Port 8000 is exposed for API access
- Pre-loaded Model: BERT model is downloaded during image build for faster container startup
docker build -t fastapi-bert:latest .docker run -d -p 8000:8000 --name fastapi-bert-app fastapi-bert:latestcurl http://localhost:8000/Response:
{"message":"Hello World! FastAPI BERT Inference Server"}curl http://localhost:8000/healthResponse:
{"status":"healthy"}curl -X POST http://localhost:8000/classify \
-H "Content-Type: application/json" \
-d '{"text":"This is an amazing product, I love it!"}'Response:
{
"text":"This is an amazing product, I love it!",
"classification":"POSITIVE",
"confidence":0.9998859167098999
}- Framework: FastAPI
- Server: Uvicorn
- ML Model: DistilBERT (HuggingFace Transformers)
- Base Image: Python 3.11 (slim)
- Containerization: Docker
- Model Name: distilbert-base-uncased-finetuned-sst-2-english
- Task: Sentiment Analysis (Binary Classification - POSITIVE/NEGATIVE)
- Framework: PyTorch via HuggingFace Transformers