https://github.com/trflorian/sentiment-analysis-viz
Real-time visualization of sentiment analysis on text input
https://github.com/trflorian/sentiment-analysis-viz
customtkinter data-science huggingface opencv-python python sentiment-analysis tokenizer transformers
Last synced: 7 months ago
JSON representation
Real-time visualization of sentiment analysis on text input
- Host: GitHub
- URL: https://github.com/trflorian/sentiment-analysis-viz
- Owner: trflorian
- License: mit
- Created: 2025-01-26T16:56:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-20T22:06:56.000Z (9 months ago)
- Last Synced: 2025-05-20T22:51:41.833Z (9 months ago)
- Topics: customtkinter, data-science, huggingface, opencv-python, python, sentiment-analysis, tokenizer, transformers
- Language: Python
- Homepage: https://towardsdatascience.com/real-time-interactive-sentiment-analysis-in-python/
- Size: 237 KB
- Stars: 18
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SENTIMENT ANALYSIS



This project showcases a real-time sentiment analysis visualization with a smiley based on a text input.
The more positive the sentiment of the input is, the happier the smiley looks and vice versa if the sentiment is really negative.
## How it works
The text input is passed to a sentiment analysis pipeline with a tokenizer and a transformer model pre-trained on twitter data, roughly 58 million tweets.
The specific model used is `cardiffnlp/twitter-roberta-base-sentiment` (https://huggingface.co/cardiffnlp/twitter-roberta-base-sentiment), which outputs three labels and a confidence score each.
The labels correspond to the classifications *negative*, *neutral* and *positive*. To calculate the final sentiment score in a range of `[-1, 1]`, I simply apply a weighted scaling based on the confidence of each label.
The negative label prediction confidence score is multiplied by -1, the neutral one by 0 and the positive score by 1.
## Procedural Smiley
Using linear color interpolation in the HSV color space and a simple parabola for the mouth of the smiley, the face is procedurally generated.

## Examples
| Positive Sentiment | Negative Sentiment |
| -------- | ------- |
|  |  |
## Quickstart
### Prerequisites
This project uses [uv](https://docs.astral.sh/uv/) as its package/project manager.
You can run `uv sync` in the cloned project folder to get all dependencies setup in a local virtual environment specific for this project.
### Run Demo
To run the project there are currently two applications available:
- An interactve web app using Marimo
- A desktop application using TKinter
#### Interactive Web App
The project includes an interactive web application built with Marimo that provides a user-friendly interface on a webpage.
```bash
uv run marimo run src/sentiment_analysis/marimo/marimo_app.py
```

#### Tkinter Desktop App
Make sure that you have all required packages installed for tkinter in order to run the standalone application.
```bash
uv run ctk_app
```
