Website to crowd-annotate tweets for Humor Research. Originally created for pgHumor, and also used in the HAHA competitions. If you want to learn general information about the data and its format, see the HUMOR website.
- Backend & API: FastAPI running on Uvicorn with uvloop and httptools for async request handling; Pydantic for data validation; Jinja2 for server-side HTML rendering.
- Database Layer: MySQL 26.x with SQLAlchemy 2.0 (using async drivers:
asyncmyin production andaiosqlitefor in-memory unit tests). - Frontend: Vanilla modern JavaScript (ES6+), HTML5, and CSS3 without jQuery or Bootstrap JS dependencies.
- Tooling & Environment: Python
>=3.15managed viauv; containerized with Docker Compose; tested and linted withruff,ty, andpytest.
After cloning the repo, you can run this code in two ways: with Docker or via uv. The first one is the recommended way to get started (or to just use for the database), and the second one is for the extraction and analysis part, and for advanced usage (such as debugging with an IDE).
You need Docker and Docker Compose. To run the web server in debug mode, auto-detecting changes:
docker compose up --buildIf you're on a VPN, first exit the VPN, create the containers for the first time (so that the network is created correctly), then you can enter the VPN again.
-
Clone the repo and
cdintoweb/:git clone https://github.com/pln-fing-udelar/pghumor-clasificahumor cd web/ -
Install Python, MySQL, and SQLite3 library headers. In Ubuntu, it'd be:
sudo apt install libmysqlclient-dev libsqlite3-dev python3-dev
-
Install the dependencies using uv:
uv sync
-
Create a
.envfile with the database configuration (setting environment variable values):DB_HOST=SET_VALUE DB_USER=SET_VALUE DB_PASS=SET_VALUE DB_NAME=SET_VALUE
-
Set up a MySQL 26.10 instance. It could be the instance generated with the Docker setup (
docker compose up database). -
Run:
uv run --env-file ../.env uvicorn clasificahumor.__main__:app --host :: --port 5000 --reload
cd web/
uv run ruff check --fix
uv run ruff format
uv run ty check
uv run pytest --cov-fail-under=90You need data to mess with. There's a dump with the downloaded tweets in the HUMOR repo.
First, create a database with db/schema.sql:
mysql -u $USER -p < db/schema.sqlThe Docker image's default user is root.
The default password for the dev environment in Docker is specified in the
docker-compose.override.yml file.
To load a database dump, run in another shell:
mysql -u $USER -p pghumor < dump.sqlYou can prefix it with docker compose exec database to run it in the database Docker container.
Or you can use a local mysql:
# First check the IP address of the container.
# Note the actual Docker container name depends on the local directory name.
DB_HOST=$(docker container inspect clasificahumor-database-1 | jq -r '.[0].NetworkSettings.Networks."clasificahumor_net".IPAddress')
mycli -h "DB_HOST" -u root -p
# You can also set the password in the command like: -p $PASSWORDYou can append a database name at the end of the command (e.g., pghumor) to select it when starting the session.
myclisometimes gives Unicode issues, so if that happens, usemysqlinstead.
List the databases:
SHOW DATABASES;List pghumor database tables:
USE pghumor;
SHOW tables;Describe a particular table (e.g., tweets):
DESCRIBE tweets;Show some data from a table:
SELECT * FROM tweets LIMIT 10;To run it using the production web server, do:
docker compose -f docker-compose.yml -f docker-compose.testing.yml up -d --buildThen you can do some testing, such as running a load test:
./web/load_test.shTo back up the data in production:
docker exec clasificahumor-database-1 mysqldump -u root -p pghumor > dump.sqlTo run a SQL script in production (e.g., to restore some data):
docker exec -i clasificahumor-database-1 mysql -u root -p pghumor < dump.sqlTo open a MySQL interactive session in production:
docker exec -i clasificahumor-database-1 mysql -u root -p pghumorFor these commands, using Docker Compose directly (docker compose exec database) is also supported instead of the
Docker CLI directly (docker exec clasificahumor-database-1).
However, the extra flags needed for each of them change as the Docker Compose exec subcommand uses a pseudo TTY,
and it's interactive by default, while the Docker CLI exec subcommand doesn't.
The repo was first cloned in production in /opt/clasificahumor. The following command was run:
git config receive.denyCurrentBranch updateInsteadThe file /opt/clasificahumor/.git/hooks/post-update in production has been set with the following content to
deploy on git push:
#!/usr/bin/env bash
pushd .. > /dev/null # So it loads the .env file in the working directory.
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build
popd > /dev/nullAdd a git remote to push to production:
git remote add production $YOUR_USERNAME@clasificahumor.com:/opt/clasificahumorThen just push to production:
git push productionAfter many Docker builds in production, if there's not enough storage available, you can run:
docker system pruneFollow these steps to download new tweets and add them to the database.
Add the following to the .env file with the content (replace with the Twitter API credentials values):
CONSUMER_TOKEN=...
CONSUMER_SECRET=...
ACCESS_TOKEN=...
ACCESS_TOKEN_SECRET=...Note that normally we wouldn't need the access token and access token secret as we're not authenticating other users to this "Twitter app." However, the app access token can be used to act in the name of the Twitter app user owner (user-based authentication), and thus gain greater Twitter API rate limits than in an app-based authentication context.
cd web/
./extraction/download_hose.py > tweets1.jsonl./extraction/download_from_accounts.py > tweets2.jsonl./extraction/persist.py < tweets.jsonlSee the options available in the command with ./extraction/persist.py --help.
To compute the agreement (for example, with
this annotations_by_tweet.csv file):
cd web/
./analysis/agreement.py FILEIf you have an SSL connection error when trying to access the database, see MySQL ERROR 2026 - SSL connection error - Ubuntu 20.04.