Skip to content

πŸβš‘πŸ“ŠπŸ³ A simple Python microservice that performs sentiment analysis using Hugging Face Transformers. Built with FastAPI and containerized with Docker for easy deployment

Notifications You must be signed in to change notification settings

engripaye/python-sentiment-analysis-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


🐍 Sentiment Analysis API

API Architecture with Python, FastAPI, Docker

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.


πŸš€ Features

  • πŸ”Ž 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

πŸ› οΈ Tech Stack

  • Python 3.10+
  • FastAPI
  • Hugging Face Transformers
  • Uvicorn (ASGI server)
  • Docker

πŸ“¦ Installation & Setup

1️⃣ Clone Repository

git clone https://github.com/your-username/sentiment-analysis-api.git
cd sentiment-analysis-api

2️⃣ Create Virtual Environment

python -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate

3️⃣ Install Dependencies

pip install -r requirements.txt

4️⃣ Run Locally

uvicorn app.main:app --reload

API will be available at: πŸ‘‰ http://127.0.0.1:8000


🐳 Docker Deployment

Build Image

docker build -t sentiment-api .

Run Container

docker run -d -p 8000:8000 sentiment-api

πŸ“‘ API Endpoints

πŸ”Ή Health Check

GET /health

Response:

{"status": "ok"}

πŸ”Ή Sentiment Analysis

POST /predict

Request Body:

{
  "text": "I love using FastAPI, it's amazing!"
}

Response:

{
  "label": "positive",
  "score": 0.98
}

πŸ“– API Docs

FastAPI provides interactive API docs at:

  • Swagger UI β†’ http://127.0.0.1:8000/docs
  • ReDoc β†’ http://127.0.0.1:8000/redoc

πŸ§ͺ Testing with Postman

  • Import the provided postman_collection.json into Postman
  • Test endpoints /health and /predict

πŸ“‚ Project Structure

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

πŸš€ Future Improvements

  • Add batch sentiment analysis endpoint
  • Add support for multilingual models
  • Integrate CI/CD pipeline for automated testing & deployment
  • Add Kubernetes deployment files

πŸ“œ License

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?

About

πŸβš‘πŸ“ŠπŸ³ A simple Python microservice that performs sentiment analysis using Hugging Face Transformers. Built with FastAPI and containerized with Docker for easy deployment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published