Multiple images as options in choice

How to create a recipe for multiple images in choice options?(refer to attached image)

Also how to load these multiple images from the img_urls in my database?

And how can i assign image_id(from database) to option id?

Hi! The custom recipe code you need for this is actually very similar to the choice example here and this standalone example on GitHub :slightly_smiling_face:

For image-based choice annotation, the examples and options you load in could look like this:

{
    "text": "This is some text",
    "label": "HEALTHY_FOOD",
    "options": [
        {"id": 0, "image": "https://example.com/image0.jpg"},
        {"id": 1, "image": "https://example.com/image1.jpg"},
        {"id": 2, "image": "https://example.com/image2.jpg"},
        {"id": 3, "image": "https://example.com/image3.jpg"}
    ]
}

The "label" is displayed at the top of the card (the headline) and the "text" is additional (optional) input text, like a question or some other content to collect multiple-choice feedback on.

How exactly you write your function depends on how you store your data – but ultimately, you need a function that creates and yields dictionaries in the above format. Here's an example:

# Let's imagine the data you've exported from your database 
# looks like this: a list of tuples with the image options and
# each record is a dict with an ID and a URL
image_data = [
    ({"id": 123, "url": "http://x.com/1.jpg"}, {"id": 456, "url": "http://x.com/2.jpg"}),
    ({"id": 789, "url": "http://x.com/3.jpg"}, {"id": 012, "url": "http://x.com/4.jpg"}),
]

def get_stream():
    for images in image_data:
        # Create the options from the images
        options = {"id": image["id"], "image": image["url"]
                   for image in images}
        # Create the annotation task
        task = {"label": "YOUR_LABEL", "options": options}
        yield task

There is an issue i am facing with prodigy, don’t know if it’s a bug in the package.
When two or more workers(annotators) are accessing the prodigy over IP for image labeling. To some users, the screen says “No task available” even though there is lot of data left to be annotated yet(happens while refreshing the browser tab or opening again).
Work-around to this problem: restart the web server, the the images comes back again but this leads to one another issue that both the workers start getting the same images on their screen.

Please see to it, thanks already!

How many examples do you have in total? If you have several users accessing the same URL and app, it can happen that the app has already requested the next batch of data for one use Examples are loaded in batches (by default, 10) and if the queue is runnig low, the app will fetch more in the background to make sure you're never running out of tasks.

As a quick fix, try setting "batch_size": 1 in your prodigy.json or recipe config. This will only ever fetch one examples from the server and should reduce overlap when several requests are made.

In some cases, it can be better to start separate processes, one for each user, and use a custom recipe to decide which examples to send out to which user. I've outlined an approach for this in my post here:

You might also want to check out this great community add-on: