Using dataset uploaded from python for annotations


I uploaded a dataset of images by the code below. The dataset exist in the database and files are inserted.
now I want to annotate the images in the dataset for annotations.

In my terminal I run: prodigy image.manual ImageTest_2 --label DOG,CAT
Unfortunately, I receive the message Oops, something went wrong :( when I go into the interface, in the browser.

from prodigy.components.db import connect
import base64
import os
from prodigy import set_hashes

def extract_pic(path):
    with open(path, 'rb') as f:
        img =
    encrypted = base64.encodebytes(img).decode("utf-8")
    d = {'image': encrypted}
    pic_json = set_hashes(d)
    return pic_json

def main(dataset_name):
    pic_dir = "../../Downloads/images"
    file_names = os.listdir(pic_dir)
    paths = map(lambda f: os.path.join(pic_dir, f), file_names)
    db = connect()
    data_json = list(map(lambda p: extract_pic(p), paths))
    a = db.add_dataset("ImageTest_2")  # create a new dataset
    b = db.add_examples(data_json, ["ImageTest_2"])  # add examples to the dataset
    assert 'ImageTest_2' in db
    dataset = db.get_dataset('ImageTest_2')  # retrieve a dataset

if __name__ == '__main__':
    main('python upload')

The error message from when starting prodigy from the terminal:

Task queue depth is 1
Exception when serving /get_session_questions
Traceback (most recent call last):
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/waitress/", line 336, in service
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/waitress/", line 175, in service
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/waitress/", line 452, in execute
    app_iter =, start_response)
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/hug/", line 451, in api_auto_instantiate
    return module.__hug_wsgi__(*args, **kwargs)
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/falcon/", line 244, in __call__
    responder(req, resp, **params)
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/hug/", line 789, in __call__
    raise exception
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/hug/", line 762, in __call__
    self.render_content(self.call_function(input_parameters), context, request, response, **kwargs)
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/hug/", line 698, in call_function
    return self.interface(**parameters)
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/hug/", line 100, in __call__
    return __hug_internal_self._function(*args, **kwargs)
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/prodigy/_api/", line 228, in get_session_questions
    tasks = controller.get_questions(session_id=session_id)
  File "cython_src/prodigy/core.pyx", line 130, in prodigy.core.Controller.get_questions
  File "cython_src/prodigy/components/feeds.pyx", line 58, in prodigy.components.feeds.SharedFeed.get_questions
  File "cython_src/prodigy/components/feeds.pyx", line 63, in prodigy.components.feeds.SharedFeed.get_next_batch
  File "cython_src/prodigy/components/feeds.pyx", line 140, in prodigy.components.feeds.SessionFeed.get_session_stream
  File "/home/rosa/miniconda3/lib/python3.7/site-packages/toolz/", line 368, in first
    return next(iter(seq))
  File "cython_src/prodigy/components/preprocess.pyx", line 190, in fetch_images
  File "cython_src/prodigy/components/filters.pyx", line 16, in filter_empty
  File "cython_src/prodigy/components/loaders.pyx", line 219, in Images
  File "/home/rosa/miniconda3/lib/python3.7/", line 1003, in __new__
    self = cls._from_parts(args, init=False)
  File "/home/rosa/miniconda3/lib/python3.7/", line 658, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/home/rosa/miniconda3/lib/python3.7/", line 642, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper

Hi! I think this is what I was referring to in the other thread:

If you just want to label images, you don’t need to add them to a dataset first. Datasets are where Prodigy saves annotations. If you just want to label images, all you need to do is pass the image.manual recipe the path to your images directory, and Prodigy will take care of the rest:

prodigy image.manual your_dataset /path/to/images --label DOG,CAT

As you label the images, they’ll then be saved to the dataset your_dataset. (The error you saw is happening because you’re not providing it with an input source – just a dataset to save the annotations to.)