I have a team of annotators who are currently annotating using spans.manual into a DB.
I know I can do "prodigy db-out" on the command line to view the current "accept" annotations, but I want to display a webpage of the annotations with "accept" in the current db they are using and I don't want this page to do any annotation task.
I have the following code, but am having a hard time getting the html to render
since I'm not sure what to actually return at the end.
also just for more context, the print statement "print(html_block)" gives me the html I'd like to display so the issue I think is just in the final return statement.
Hi! So if I understand your use case correctly, you just want Prodigy to display one single page which includes your accepted annotations, right?
What's currently missing from your recipe is the stream, i.e. the examples to display in the UI. If you just want to display a single example with your HTML, you could do this:
stream = [{"html": html_block}]
And then return the stream in your recipe components:
return {
"view_id": "html",
"stream": stream,
# etc.
}
Hi Ines,
Thanks for the help!
I've changed the code to look like this, but am getting an error when running it ( the html_block prints what I want so the error is raised from the return statement ). Any thoughts?
import prodigy
from prodigy.components.db import connect
import sys
@prodigy.recipe('view_all')
def view_all(dataset):
db = connect()
examples = db.get_dataset(dataset)
num_exs = len(examples) #number rows in annotated dataset
html_block = "<h1>FOUND "+ str(num_exs) +" PARAGRAPHS ANNOTATED</h1><br>"
html_block += "<table><tr><th>DOC</th><th>PAGE</th><th>Annotator</th><th>TIMESTAMP</th></tr>"
found = 0
for e in examples:
if e['answer'] == 'accept':
found += 1
html_block += "<tr> <td>"+e["meta"]["doc"]+"</td> <td>"+ str(e["meta"]["page"]) +"</td> <td>"+e["_annotator_id"]+"</td><td>"+str(e["_timestamp"])+"</td>"
html_block += "<td>TODO TOKENS</td><td>"+e['text']+"</td> </tr>"
html_block += "</table>"
html_block += "<h1>FOUND "+str(found) +" WITH ACCEPT<h1>"
print(html_block)
stream = [{"html": html_block}]
return {
"view_id": "html",
"stream": stream,
"dataset": dataset,
"db": False
}
I'm getting the following error when running
PRODIGY_HOST=xxx PRODIGY_PORT=xxx prodigy view_all xxx -F all_annotations_recipe_clean.py
<h1>FOUND 36 PARAGRAPHS ANNOTATED</h1><br><table><tr><th>DOC</th><th>PAGE</th><th>Annotator</th><th>TIMESTAMP</th></tr><tr> <td>_S , J M s-art. 119 3° párrafo-_.pdf</td> <td>5</td> <td>azul_march24-diego</td><td>1648130914</td><td>TODO TOKENS</td><td>En efecto ... </td> </tr><tr> <td>_S , J M s_ 119 3° párrafo-_.pdf</td> <td>5</td> <td>azul_march24-diego</td><td>1648130928</td><td>TODO TOKENS</td><td>Para arribar...</td> </tr></table><h1>FOUND 5 WITH ACCEPT<h1>
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/xxx/fulbri/prdgy_env/lib/python3.6/site-packages/prodigy/__main__.py", line 61, in <module>
controller = recipe(*args, use_plac=True)
File "cython_src/prodigy/core.pyx", line 339, in prodigy.core.recipe.recipe_decorator.recipe_proxy
File "cython_src/prodigy/core.pyx", line 366, in prodigy.core._components_to_ctrl
File "cython_src/prodigy/core.pyx", line 117, in prodigy.core.Controller.__init__
AttributeError: 'bool' object has no attribute 'count_dataset'
The error goes away if I remove the "db": False part from the return statement, but then it allows people to annotate the listing ( ie, it adds the toolbar at the bottom of the screen "checkmark, x, etc "
Glad you got it working! And if you don't want to use a database or dataset, you could just set "dataset": False instead. This will have the desired effect and won't save any annotations.