This project demonstrates how to wrap a machine learning model in a FastAPI web application and Dockerize it for easy deployment. The application performs sentiment analysis using Hugging Face's transformers library, allowing users to analyze text via a simple API call.
The goal of this project is to learn how to:
- Build a basic API using FastAPI.
- Integrate a pre-trained machine learning model for sentiment analysis.
- Dockerize the application for deployment in a containerized environment.
-
Build the Docker image:
docker build -t fastapi-sentiment . -
Run the Docker container:
docker run -d -p 8000:8000 fastapi-sentiment
-
Test the API:
Open a browser or use a tool like
curlor Postman to access:http://127.0.0.1:8000/analyze?input_string=I+love+this+appYou will receive a JSON response with the sentiment and score.
- Docker: Containerized the FastAPI app for easy and scalable deployment.
- FastAPI: Created a simple web API for machine learning model inference.
- Hugging Face
transformers: Integrated pre-trained NLP models for real-time inference.