-
-
Save kevinmelodi/7a0b855b0140c904677c801c9a7c029e to your computer and use it in GitHub Desktop.
prodigy custom labeling interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from prodigy.components.filters import filter_duplicates | |
from prodigy.components.stream import get_stream | |
from prodigy import recipe | |
from prodigy import set_hashes | |
@recipe( | |
"custom-text-classification", | |
dataset=("The dataset to save to", "positional", None, str), | |
source=("Path to the source data as JSONL", "positional", None, str), | |
) | |
def custom_text_classification(dataset: str, source: str): | |
# Load your source data | |
stream = get_stream(source, dedup=True, rehash=True) | |
stream = (set_hashes(eg, input_keys=("id",), task_keys=("label",), ignore=("span","text", "input", "html", "image"), overwrite = True) for eg in stream) | |
stream = filter_duplicates(stream, by_input=True, by_task=True) | |
# Define the annotation blocks | |
blocks = [ | |
{ | |
"view_id": "html", | |
"html_template": """ | |
<div class='custom-container' style="display: flex; font-size: 15px"> | |
<div style="flex: 1;"> | |
<img src="{{meta.signed_image_url}}" alt="Page Image" style="width: 100%; height: auto;"> | |
</div> | |
<div style="flex: 1; padding-left: 10px;"> | |
<h3>{{meta.source}}</h3> | |
<p>{{meta.preamble}}</p> | |
<p style="background: #c8eec88a;">{{text}}</p> | |
<p style="font-size;12px; text-align: right;">Page: {{meta.page}}</p> | |
</div> | |
</div> | |
""" | |
}, | |
{ | |
"view_id": "choice", | |
"options": [ | |
{"id": "Product", "text": "Product"}, | |
{"id": "Company", "text": "Company"}, | |
{"id": "Market", "text": "Market"}, | |
{"id": "Project", "text": "Project"}, | |
{"id": "Grant", "text": "Grant"} | |
] | |
} | |
] | |
return { | |
"dataset": dataset, | |
"stream": stream, | |
"view_id": "blocks", | |
"config": { | |
"blocks": blocks, | |
"global_css": "/*.prodigy-meta {display: none} */ .prodigy-container {max-width: 100%}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment