Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions prodigy_pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def _validate_ocr_example(stream):
dataset=("Dataset to save answers to", "positional", None, str),
source=("Source with PDF Annotations", "positional", None, str),
labels=("Labels to consider", "option", "l", split_string),
lang=("Language for OCR", "option", "la", str),
scale=("Zoom scale. Increase above 3 to upscale the image for OCR.", "option", "s", int),
remove_base64=("Remove base64-encoded image data", "flag", "R", bool),
fold_dashes=("Removes dashes at the end of a textline and folds them with the next term.", "flag", "f", bool),
Expand All @@ -182,6 +183,7 @@ def pdf_ocr_correct(
dataset: str,
source: str,
labels: str,
lang: str = "eng",
scale: int = 3,
remove_base64: bool = False,
fold_dashes: bool = False,
Expand All @@ -190,7 +192,7 @@ def pdf_ocr_correct(
"""Applies OCR to annotated segments and gives a textbox for corrections."""
stream = get_stream(source)

def new_stream(stream):
def new_stream(stream, lang):
for ex in stream:
useful_spans = [
span for span in ex.get("spans", []) if span["label"] in labels
Expand All @@ -205,7 +207,7 @@ def new_stream(stream):
pil_page, span=annot, scale=scale
)
annot["image"] = img_str
annot["text"] = pytesseract.image_to_string(cropped)
annot["text"] = pytesseract.image_to_string(cropped, lang=lang)
if fold_dashes:
annot["text"] = fold_ocr_dashes(annot["text"])
annot["transcription"] = annot["text"]
Expand Down Expand Up @@ -233,7 +235,7 @@ def before_db(examples):

blocks = [{"view_id": "classification"}, {"view_id": "text_input"}]
stream.apply(_validate_ocr_example)
stream.apply(new_stream)
stream.apply(new_stream, lang)

return {
"dataset": dataset,
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
version = 0.4.2
version = 0.4.3
description = Recipes for PDF annotation
url = https://github.com/explosion/prodigy-pdf
author = Explosion
Expand Down