A FastAPI application that provides multilingual sentiment analysis across 23 languages using a fine-tuned DistilBERT model. This project is designed for educational purposes to demonstrate Docker containerization and ML model deployment.
This application uses the Multilingual Sentiment Analysis Model from Hugging Face.
distilbert/distilbert-base-multilingual-casedVery Negative, Negative, Neutral, Positive, Very Positive (5 classes)@misc{tabularisai_2025,
author = { tabularisai and Samuel Gyamfi and Vadim Borisov and Richard H. Schreiber },
title = { multilingual-sentiment-analysis (Revision 69afb83) },
year = 2025,
url = { https://huggingface.co/tabularisai/multilingual-sentiment-analysis },
doi = { 10.57967/hf/5968 },
publisher = { Hugging Face }
}
License: CC-BY-NC-4.0 - For commercial use, contact [email protected]. See the model page for full license details.
Clone or download this repository
git clone <repository-url>
cd deploying_ml_model
Start the application
docker compose up
Access the API
http://localhost:8000http://localhost:8000/docshttp://localhost:8000/healthGET /
Returns API information and available endpoints.
GET /health
Returns the health status of the API and model loading status.
POST /predict
Request Body:
{
"text": "Tesla stock drops after disappointing delivery numbers."
}
Response:
{
"text": "Tesla stock drops after disappointing delivery numbers.",
"sentiment": "Negative",
"confidence": 0.95
}
Single prediction:
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "Tesla stock drops after disappointing delivery numbers."}'
import requests
# Single prediction
response = requests.post(
"http://localhost:8000/predict",
json={"text": "Tesla stock drops after disappointing delivery numbers."}
)
print(response.json())
docker build -t sentiment-api .
docker run -p 8000:8000 sentiment-api
# Start the service
docker compose up
# Start in detached mode
docker compose up -d
# Stop the service
docker compose down
# View logs
docker compose logs
# Rebuild and start
docker compose up --build
.
├── src/
│ └── app.py # FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
└── README.md # This file
This project is designed for teaching data science students about:
Students will learn:
Install dependencies:
pip install -r requirements.txt
Run the application:
uvicorn src.app:app --host 0.0.0.0 --port 8000 --reload
src/app.py to add new endpointsrequirements.txt for additional dependenciesDockerfile for specific system requirementsdocker-compose.yml for different deployment scenariosThis is an educational project. Feel free to fork and modify for your own teaching needs.
This project uses the CC-BY-NC-4.0 licensed multilingual sentiment model from tabularisai/multilingual-sentiment-analysis on Hugging Face. For commercial use, please contact [email protected].
A FastAPI application that provides multilingual sentiment analysis across 23 languages using a fine-tuned DistilBERT model. This project is designed for educational purposes to demonstrate Docker containerization and ML model deployment.
This application uses the Multilingual Sentiment Analysis Model from Hugging Face.
distilbert/distilbert-base-multilingual-casedVery Negative, Negative, Neutral, Positive, Very Positive (5 classes)@misc{tabularisai_2025,
author = { tabularisai and Samuel Gyamfi and Vadim Borisov and Richard H. Schreiber },
title = { multilingual-sentiment-analysis (Revision 69afb83) },
year = 2025,
url = { https://huggingface.co/tabularisai/multilingual-sentiment-analysis },
doi = { 10.57967/hf/5968 },
publisher = { Hugging Face }
}
License: CC-BY-NC-4.0 - For commercial use, contact [email protected]. See the model page for full license details.
Clone or download this repository
git clone <repository-url>
cd deploying_ml_model
Start the application
docker compose up
Access the API
http://localhost:8000http://localhost:8000/docshttp://localhost:8000/healthGET /
Returns API information and available endpoints.
GET /health
Returns the health status of the API and model loading status.
POST /predict
Request Body:
{
"text": "Tesla stock drops after disappointing delivery numbers."
}
Response:
{
"text": "Tesla stock drops after disappointing delivery numbers.",
"sentiment": "Negative",
"confidence": 0.95
}
Single prediction:
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "Tesla stock drops after disappointing delivery numbers."}'
import requests
# Single prediction
response = requests.post(
"http://localhost:8000/predict",
json={"text": "Tesla stock drops after disappointing delivery numbers."}
)
print(response.json())
docker build -t sentiment-api .
docker run -p 8000:8000 sentiment-api
# Start the service
docker compose up
# Start in detached mode
docker compose up -d
# Stop the service
docker compose down
# View logs
docker compose logs
# Rebuild and start
docker compose up --build
.
├── src/
│ └── app.py # FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
└── README.md # This file
This project is designed for teaching data science students about:
Students will learn:
Install dependencies:
pip install -r requirements.txt
Run the application:
uvicorn src.app:app --host 0.0.0.0 --port 8000 --reload
src/app.py to add new endpointsrequirements.txt for additional dependenciesDockerfile for specific system requirementsdocker-compose.yml for different deployment scenariosThis is an educational project. Feel free to fork and modify for your own teaching needs.
This project uses the CC-BY-NC-4.0 licensed multilingual sentiment model from tabularisai/multilingual-sentiment-analysis on Hugging Face. For commercial use, please contact [email protected].