Hi,
I'm getting an error when I try to run custom recipes. Here are a few examples:
Sample Recipes Causing Error
from typing import Dict, Generator
import prodigy
from prodigy.components.loaders import JSONL
from annotator.recipes.utils import VALIDATION
UNLIMITED_ROWS = [
{"view_id": "html", "html_template":
"<div style=\"padding: 0 10px; border: 1px solid #ddd; border-radius: 4px; text-align: left;\">" +
"<label style=\"font-size: 14px; opacity: 0.90; margin-bottom: 10px;\">intent</label>" +
"<div style=\"max-height: 300px; overflow-y: scroll; margin-bottom: 10px;\">{{final_intent_v3}}" +
"<br>" +
"<br>" +
"<label style=\"font-size: 14px; opacity: 0.90; margin-bottom: 10px;\">utterance</label>" +
"<div style=\"max-height: 300px; overflow-y: scroll; margin-bottom: 10px;\">{{utterance}}" +
"</div>"
},
{"view_id": "choice"},
{"view_id": "html", "html_template": "<div style='float:left;'>" +
"<input name='stt_error' id='stt_error' type='checkbox' value='STT Error' style='margin-right:10px;' data-id='{{utterance}}' onchange='updateSttError()'" +
"<label onclick='update()'>STT Error</label>"
},
{"view_id": "text_input", "field_label": "notes"}
]
def add_options(
stream, label_field="", choices=VALIDATION
) -> Generator[Dict, None, None]:
"""
Convert each line in the ``stream`` to a ``task`` with a text and an
options field
:param stream: the input stream
:param label_field: key; defaults to "label"
:param choices: the different choices
:yield: a task Dict with text and options
"""
for line in stream:
options = [word for word in choices]
task = {
"final_intent_v3": line["final_intent_v3"],
"utterance": line["utterance"],
"stt_error": False,
"options": [
{"id": o, "deployment": o, "prompt": o,
"text": o} for o in options
]
}
yield task
@prodigy.recipe(
"intent-validation",
dataset=("The dataset to save to", "positional", None, str),
file_path=("Path to texts", "positional", None, str)
)
def custom_labels(dataset, file_path):
"""
Annotate the text with labels from the list from the ``label_field`` in
the input file. Augmented with choices from ``choice_field``.
"""
blocks = UNLIMITED_ROWS
stream = JSONL(file_path)
stream = add_options(stream) # add options to each task
javascript = """
// Set stt_error to false by default
prodigy.update({ stt_error: false });
function updateSttError() {
prodigy.update({ stt_error: document.getElementById('stt_error').checked });
}
document.addEventListener('prodigyanswer', (event) => {
// Reset stt_error to false
prodigy.update({ stt_error: false });
document.getElementById('stt_error').checked = false;
});
"""
return {
"dataset": dataset,
"view_id": "blocks",
"stream": list(stream),
"config": {
"blocks": blocks,
"javascript": javascript
}
}
Errors
✘ Couldn't load Python code:
/Users/cheyannebaird/posh/annotation-service/src/annotator/recipes/intent_validation.py
issubclass() arg 1 must be a class
✘ Couldn't load Python code:
/Users/cheyannebaird/posh/annotation-service/src/annotator/recipes/eup_corpus_validation.py
issubclass() arg 1 must be a class