Hi @ines, hope I everything is doing well. I was wondering if I can set an UI alert when the number of annotations of each given dataset_id reaches a set amount. I have been looking at the custom interfaces, and I'm a bit confused on how I can apply a Custom JavaScript to my custom recipe.
Here is my custom recipe. I will have this also linked to the AFK feature to save time stamp once this alert also pops up.
def condition(stats):
for user in stats:
if user[1] == n_examples:
# custom javascript alert : "You have reached set number of annotations, please exit"
def add_label_options_to_stream(stream, labels,annotations):
options = [{"id": label, "text": label} for label in labels]
for task in stream:
task["options"] = options
yield task
def add_labels_to_stream(stream, labels):
for task in stream:
task["label"] = label[0]
yield task
@prodigy.recipe(
"title_classification",
dataset=("The dataset to use", "positional", None, str),
source=("The source data as a JSONL file", "positional", None, str),
label=("One or more comma-separated labels", "option", "l", split_string),
n_examples = ("Number of examples to randomly review, -1 for all", "option", "n", int),
exclusive=("Treat classes as mutually exclusive", "flag", "E", bool),
exclude=("Names of datasets to exclude", "option", "e", split_string),
)
def title_classification(
dataset: str,
source: str,
label: Optional[List[str]] = None,
n_examples : int,
exclusive: bool = False,
exclude: Optional[List[str]] = None,
):
db = connect()
stats = []
# I will have to add a while loop to update stats for condition function
for dataset_id in db.sessions:
annotations = db.get_dataset(dataset_id)
stats.append([str(dataset_id), len(annotations)])
stream = JSONL(source)
print(stream)
#Add labels to each task in stream
has_options = len(label) > 1
if has_options:
stream = add_label_options_to_stream(stream, label)
else:
stream = add_labels_to_stream(stream, label)```