Skip to content

Commit ea5c154

Browse files
authored
✨ add OCR output in CLI (#144)
1 parent 38c4da2 commit ea5c154

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

docs/guide/python-cli.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ python3 -m mindee invoice parse /path/to/invoice.pdf
4444
python3 -m mindee custom -u pikachu -k xxxxxxx pokemon_card /path/to/card.jpg
4545
```
4646

47-
### You can get the full parsed output as well
47+
### Printing the raw parsed data instead of the summary
4848

4949
```shell
5050
python3 -m mindee invoice parse -o parsed /path/to/invoice.pdf
5151
```
5252

53+
### Extracting all the words using OCR
54+
55+
```shell
56+
python3 -m mindee invoice parse -t /path/to/invoice.pdf
57+
```
58+
5359
### In the Git repo, there's a helper script for it
5460

5561
```shell

mindee/cli.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def process_parse(args: Namespace, client: Client, doc_class) -> None:
140140
parsed_data = input_doc.parse(
141141
doc_class, include_words=args.include_words, page_options=page_options
142142
)
143-
display_doc(args.output_type, parsed_data)
143+
display_doc(args.output_type, args.include_words, parsed_data)
144144

145145

146146
def process_parse_queued(args: Namespace, client: Client, doc_class) -> None:
@@ -158,20 +158,25 @@ def process_parse_queued(args: Namespace, client: Client, doc_class) -> None:
158158
document_class=doc_class, queue_id=args.queue_id
159159
)
160160
if parsed_data.job.status == "completed" and parsed_data.document is not None:
161-
display_doc(args.output_type, parsed_data.document)
161+
display_doc(args.output_type, args.include_words, parsed_data.document)
162162
else:
163163
print(parsed_data.job)
164164

165165

166-
def display_doc(output_type: str, document_response: PredictResponse):
166+
def display_doc(output_type: str, include_words: bool, response: PredictResponse):
167167
"""Display the parsed document."""
168168
if output_type == "raw":
169-
print(json.dumps(document_response.http_response, indent=2))
169+
print(json.dumps(response.http_response, indent=2))
170170
elif output_type == "parsed":
171-
doc = document_response.document
172-
print(json.dumps(doc, indent=2, default=serialize_for_json))
171+
if include_words:
172+
print(json.dumps(response.ocr, indent=2, default=serialize_for_json))
173+
print(json.dumps(response.document, indent=2, default=serialize_for_json))
173174
else:
174-
print(document_response.document)
175+
if include_words:
176+
print("OCR Begin >>>>>>>>>>\n")
177+
print(response.ocr)
178+
print("<<<<<<<<<< OCR End\n")
179+
print(response.document)
175180

176181

177182
def process_parse_enqueue(args: Namespace, client: Client, doc_class) -> None:

0 commit comments

Comments
 (0)