This repository contains a FastAPI application for sentiment analysis using the Hugging Face Transformers library. The application is designed to be run as a standalone service and can be deployed using Docker.
- Docker installed on your machine
- Basic knowledge of Python and Docker
git clone https://github.com/yourusername/sentiment-analysis-simple.git
cd sentiment-analysis-simple
Note: Add model in the model directory
Build the Docker image using the following command:
docker build -t sentiment-analysis-simple .
Run the Docker container using the following command:
docker run -d -p 8000:8000 sentiment-analysis-simple
The API will be accessible at http://localhost:8000
. You can use tools like curl
or Postman to interact with the API.
To predict the sentiment of a sentence, send a POST request to the /predict
endpoint with a JSON payload containing the sentence.
curl -X POST "http://localhost:8000/predict" -H "Content-Type: application/json" -d '{"sentence": "I love this product!"}'
The API will return a JSON response with the sentiment analysis result.
{
"request_id": "some-unique-id",
"sentiment": [
{
"label": "POSITIVE",
"score": 0.9998
}
]
}
app.py
: Contains the FastAPI application and sentiment analysis logic.Dockerfile
: Dockerfile to build the Docker image.models/
: Directory containing the pre-trained model weights.requirements.txt
: List of Python dependencies.
You now have a fully functional sentiment analysis API running in a Docker container. You can extend this application by adding more features or improving the model.
For any questions or issues, please open an issue in the repository.