A simple web service for sentiment analysis built with FastAPI. It currently uses a basic keyword-based approach to determine sentiment scores.
- uv installed.
- Install dependencies:
uv sync- Run the main sentiment analysis service (backend):
uv run uvicorn main:app --reload --port 8000The server will be available at http://localhost:8000. You can access the Swagger UI at http://localhost:8000/docs.
- Run the demo frontend app:
uv run uvicorn app:app --reload --port 8001The frontend UI will be available at http://localhost:8001.
This project implements different versions of sentiment analysis:
- v1: Basic keyword-based approach (hardcoded).
- v2: Uses the AFINN lexicon for sentiment scoring.
- v3 (spaCy): An advanced NLP approach using spaCy was implemented but is currently disabled to keep the Docker image size small.
If you want to use the spaCy implementation locally (v3 endpoint), you need to reinstall the dependencies:
uv add spacy spacytextblob https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whlThen uncomment the relevant lines in main.py.
docker build -t sentiment-analysis .docker run -p 8000:8000 sentiment-analysis- git repo
- uv
- sentiment analysis
- hardcoded s.a.
- Training a machine learning classifier would also be possible.
- The Python library spaCy would also be possible.
- LLM API.
- fastapi
- swagger
- docker
- test