917eedffcf
Main / Python 3.11 - Docs (push) Waiting to run
Main / Python 3.11 - Build (push) Waiting to run
Main / Python 3.11 - Lint (push) Waiting to run
Main / Python 3.11 - Style (push) Waiting to run
Main / Python 3.11 - Test (push) Waiting to run
Main / GPU CI (push) Blocked by required conditions
Main / Release (push) Blocked by required conditions
Main / Build and Push Docker Images (push) Blocked by required conditions
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
from threading import Lock
|
|
|
|
from paddleocr import PPStructureV3
|
|
|
|
# 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",
|
|
# and using the PP-StructureV3 pipeline to create markdown
|
|
paddle_pipeline = None
|
|
paddle_pipeline_lock = Lock()
|
|
|
|
|
|
def run_paddlepaddle(pdf_path: str, page_num: int = 1, **kwargs) -> str:
|
|
global paddle_pipeline
|
|
|
|
with paddle_pipeline_lock:
|
|
if paddle_pipeline is None:
|
|
paddle_pipeline = PPStructureV3(
|
|
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
|
|
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)
|
|
result = ""
|
|
for cur_page_0_indexed, res in enumerate(output):
|
|
if cur_page_0_indexed == page_num - 1:
|
|
result = res.markdown["markdown_texts"]
|
|
|
|
return result
|