Skip to content

Akkhan88/sentiment-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sentiment Analysis API

A FastAPI service that classifies text sentiment with Hugging Face transformers.

Overview

  • Single-text and batch prediction endpoints
  • Startup model loading with a health endpoint
  • Dockerfile included for containerized runs

The current app uses cardiffnlp/twitter-roberta-base-sentiment-latest through the Hugging Face pipeline API.

Stack

  • Python
  • FastAPI
  • Hugging Face Transformers
  • PyTorch
  • Uvicorn
  • Docker

API Endpoints

Method Route Purpose
POST /predict Predict sentiment for one text
POST /predict/batch Predict sentiment for up to 32 texts
GET /health Check service and model readiness

Quick Start

Local

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app:app --reload --port 8000

Open http://localhost:8000/docs for the interactive API docs.

Docker

docker build -t sentiment-api .
docker run -p 8000:8000 sentiment-api

Example Request

curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "This movie was absolutely fantastic!"}'

Example response:

{
  "text": "This movie was absolutely fantastic!",
  "label": "positive",
  "score": 0.9998,
  "model": "cardiffnlp/twitter-roberta-base-sentiment-latest"
}

Project Files

sentiment-api/
├── app.py
├── requirements.txt
├── Dockerfile
├── .dockerignore
└── README.md

Notes

  • The first startup downloads the model and can take longer than later runs.
  • The app is configured for CPU by default. Change device=-1 to device=0 in app.py if you want GPU inference.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors