This app implements a flexible image classification task for oTree in which participants determine whether each image was created by a human or generated by artificial intelligence (AI). Images are loaded dynamically from the _static/images folder of the oTree project. This allows researchers to easily add or remove images without modifying the Python code.
Participants see images sequentially and classify each one using on-screen buttons or keyboard shortcuts. The app records participants’ choices and the number of correct classifications.
How it works
Images are stored in two folders inside the _static/images directory:
Each folder contains images belonging to the corresponding category.
When the task starts, the browser automatically detects which images exist in these folders and builds the classification task. The order of images is then randomized for each participant.
Images are displayed one at a time until all images have been classified.
Image naming convention
Images are discovered automatically by testing sequential filenames. Files must therefore be named with consecutive numbers starting at 1.
Example:
_static/images/Human/ -> 1.jpeg ; 2.jpeg ; 3.jpeg ; 4.jpeg
_static/images/AI/ -> 1.jpeg ; 2.jpeg ; 3.jpeg
The number of images can differ between the Human and AI folders.
Important: numbering must be continuous. If a number is missing, discovery stops at that point.
The app records:
the order of images shown
the participant’s classification for each image
the number of correct responses
the total number of images completed
In practice: How to make it run?
Download classification_task.zip from this repository
Places the files in your oTree project
Add the classificationtask folder to your otree main folder
Add images folder (with subfolders AI and Human) to your _static folder
Add the following configuration to the SESSION_CONFIGS list in your settings.py file:
dict(
name='classificationtask',
display_name="Classifying images (between AI and human)",
app_sequence=['classificationtask'],
num_demo_participants=7,
)