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.
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.
Using linear color interpolation in the HSV color space and a simple parabola for the mouth of the smiley, the face is procedurally generated.
Positive Sentiment | Negative Sentiment |
---|---|
![]() |
![]() |
This project uses 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.
To run the project there are currently two applications available:
- An interactve web app using Marimo
- A desktop application using TKinter
The project includes an interactive web application built with Marimo that provides a user-friendly interface on a webpage.
uv run marimo run src/sentiment_analysis/marimo/marimo_app.py
Make sure that you have all required packages installed for tkinter in order to run the standalone application.
uv run ctk_app