Fix problem with json encoding

pull/47/head
Benjamin Rosemann 4 years ago
parent 9e64c4f0d0
commit 85b784f9a1

@ -1,3 +1,4 @@
import json
import os import os
import click import click
@ -55,7 +56,10 @@ def gen_diff_report(gt_in, ocr_in, css_prefix, joiner, none, matches=None):
pos = 0 pos = 0
for ocr_line in ocr_lines_sorted: for ocr_line in ocr_lines_sorted:
if ocr_line.line not in ocr_line_region_id.keys(): if ocr_line.line not in ocr_line_region_id.keys():
ocr_line_region_id[ocr_line.line] = ocr_in.segment_id_for_pos(pos) try:
ocr_line_region_id[ocr_line.line] = ocr_in.segment_id_for_pos(pos)
except AssertionError:
pass
pos += ocr_line.length pos += ocr_line.length
ocr_ids = {None: None} ocr_ids = {None: None}
@ -159,6 +163,7 @@ def process(gt, ocr, report_prefix, *, metrics="cer,wer", textequiv_level="regio
) )
) )
env.filters["json_float"] = json_float env.filters["json_float"] = json_float
env.filters["json_dumps"] = json.dumps
for report_suffix in (".html", ".json"): for report_suffix in (".html", ".json"):
template_fn = "report" + report_suffix + ".j2" template_fn = "report" + report_suffix + ".j2"

@ -6,6 +6,6 @@
{% if n_characters is not none %}"n_characters": {{ n_characters }},{% endif %} {% if n_characters is not none %}"n_characters": {{ n_characters }},{% endif %}
{% if n_words is not none %}"n_words": {{ n_words }},{% endif %} {% if n_words is not none %}"n_words": {{ n_words }},{% endif %}
{% endif %} {% endif %}
"gt": "{{ gt }}", "gt": {{ gt|json_dumps }},
"ocr": "{{ ocr }}" "ocr": {{ ocr|json_dumps }}
} }

Loading…
Cancel
Save