textcat.manual recipe, render data as html

I'm trying to render the content of the jsonl as HTML for the textcat.manual with this simple recipe

import prodigy
from prodigy.components.loaders import JSONL
from prodigy.components.filters import filter_duplicates

@prodigy.recipe("customrecipe")
def apiresponses(dataset, source):
    def get_stream():
       stream = JSONL(source)
       stream = add_options(stream)  # add options to each task

       return {
          'view_id': 'html',
          "dataset": dataset,   # save annotations in this dataset
          "view_id": "choice",  # use the choice interface
          "stream": stream,
       }

   def add_options(stream):
       options = [
          {"id": 0, "text": "Valid"},
          {"id": 1, "text": "Invalid"}
        ]

    for task in stream:
      task["options"] = options
      yield task

Then I call the recipe as prodigy customrecipe custom_test ./results.jsonl -F customrecipe.py

When I use this the server do not starts, and Im not sure the content will be rendered as html

Hi! The choice interface lets you render HTML content – just provide a key "html" in your data.

It looks like your recipe function isn't set up correctly, though – the recipe itself should return a dictionary of components, but in your code, it's returned by the get_stream function. So the recipe ends up doing nothing and Prodigy doesn't know how to start anything. See here for an example of how a recipe function should be structured: https://prodi.gy/docs/custom-recipes#writing

So you probably want to do something like this:

 def add_options(stream):
    options = [
        {"id": 0, "text": "Valid"},
        {"id": 1, "text": "Invalid"}
    ]
    for task in stream:
        task["options"] = options
        yield task

@prodigy.recipe("customrecipe")
def apiresponses(dataset, source):
    stream = JSONL(source)
    stream = add_options(stream)  # add options to each task

    return {
       "dataset": dataset,   # save annotations in this dataset
       "view_id": "choice",  # use the choice interface
       "stream": stream,
    }
1 Like

Worked thx !