mirror of
https://github.com/allenai/olmocr.git
synced 2025-10-10 07:42:13 +00:00
Fixing paddle ocr to run fast
This commit is contained in:
parent
8f75ea062e
commit
cedd4a80cf
@ -1,8 +1,4 @@
|
|||||||
import json
|
from threading import Lock
|
||||||
import os
|
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
from openai import OpenAI
|
|
||||||
|
|
||||||
from paddleocr import PPStructureV3
|
from paddleocr import PPStructureV3
|
||||||
|
|
||||||
@ -10,24 +6,29 @@ from paddleocr import PPStructureV3
|
|||||||
# Run's paddle paddle as in the docs here: https://huggingface.co/PaddlePaddle/PP-OCRv5_server_det
|
# Run's paddle paddle as in the docs here: https://huggingface.co/PaddlePaddle/PP-OCRv5_server_det
|
||||||
# text_detection_model_name="PP-OCRv5_server_det",
|
# text_detection_model_name="PP-OCRv5_server_det",
|
||||||
# and using the PP-StructureV3 pipeline to create markdown
|
# and using the PP-StructureV3 pipeline to create markdown
|
||||||
|
paddle_pipeline = None
|
||||||
|
paddle_pipeline_lock = Lock()
|
||||||
|
|
||||||
def run_paddlepaddle(
|
def run_paddlepaddle(
|
||||||
pdf_path: str,
|
pdf_path: str,
|
||||||
page_num: int = 1,
|
page_num: int = 1,
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> str:
|
) -> str:
|
||||||
pipeline = PPStructureV3(
|
global paddle_pipeline
|
||||||
text_detection_model_name="PP-OCRv5_server_det",
|
|
||||||
use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
|
with paddle_pipeline_lock:
|
||||||
use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
|
if paddle_pipeline is None:
|
||||||
use_textline_orientation=False, # Use use_textline_orientation to enable/disable textline orientation classification model
|
paddle_pipeline = PPStructureV3(
|
||||||
device="gpu:0", # Use device to specify GPU for model inference
|
text_detection_model_name="PP-OCRv5_server_det",
|
||||||
)
|
use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
|
||||||
output = pipeline.predict(pdf_path)
|
use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
|
||||||
|
use_textline_orientation=False, # Use use_textline_orientation to enable/disable textline orientation classification model
|
||||||
|
device="gpu:0", # Use device to specify GPU for model inference
|
||||||
|
)
|
||||||
|
|
||||||
|
output = paddle_pipeline.predict(pdf_path)
|
||||||
for cur_page_0_indexed, res in enumerate(output):
|
for cur_page_0_indexed, res in enumerate(output):
|
||||||
if cur_page_0_indexed == page_num - 1:
|
if cur_page_0_indexed == page_num - 1:
|
||||||
print(res.markdown)
|
return res.markdown["markdown_texts"]
|
||||||
return res.markdown
|
|
||||||
|
|
||||||
raise ValueError(f"Did not get markdown for page {page_num}")
|
raise ValueError(f"Did not get markdown for page {page_num}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user