Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
将ocr_parse逻辑切换到v2,并解决几个parse过程中的error
赵小蒙dcf6e7127ad1
diff --git a/magic_pdf/parse_by_ocr_v2.py b/magic_pdf/pdf_parse_by_ocr_v2.pysimilarity index 100%rename from magic_pdf/parse_by_ocr_v2.pyrename to magic_pdf/pdf_parse_by_ocr_v2.pydiff --git a/magic_pdf/pre_proc/ocr_dict_merge.py b/magic_pdf/pre_proc/ocr_dict_merge.pyindex c0b143ba..05bc6f44 100644--- a/magic_pdf/pre_proc/ocr_dict_merge.py+++ b/magic_pdf/pre_proc/ocr_dict_merge.py@@ -252,7 +252,7 @@ def fix_image_block(block, img_blocks):break# 根据list长度,判断img_block中是否有img_caption- if len(img_block['img_caption_bbox']) > 0:+ if img_block['img_caption_bbox'] is not None:img_caption_block, img_caption_spans = merge_spans_to_block(block['spans'], img_block['img_caption_bbox'], BlockType.ImageCaption)@@ -280,7 +280,7 @@ def fix_table_block(block, table_blocks):break# 根据list长度,判断table_block中是否有caption- if len(table_block['table_caption_bbox']) > 0:+ if table_block['table_caption_bbox'] is not None:table_caption_block, table_caption_spans = merge_spans_to_block(block['spans'], table_block['table_caption_bbox'], BlockType.TableCaption)@@ -293,7 +293,7 @@ def fix_table_block(block, table_blocks):block['spans'].remove(span)# 根据list长度,判断table_block中是否有table_note- if len(table_block['table_footnote_bbox']) > 0:+ if table_block['table_footnote_bbox'] is not None:table_footnote_block, table_footnote_spans = merge_spans_to_block(block['spans'], table_block['table_footnote_bbox'], BlockType.TableFootnote)diff --git a/magic_pdf/pre_proc/ocr_span_list_modify.py b/magic_pdf/pre_proc/ocr_span_list_modify.pyindex f231136d..ff358930 100644--- a/magic_pdf/pre_proc/ocr_span_list_modify.py+++ b/magic_pdf/pre_proc/ocr_span_list_modify.py@@ -222,10 +222,10 @@ def get_qa_need_list_v2(blocks):interline_equations = []for block in blocks:- if block["type"] == BlockType.Image:+ if block["block_type"] == BlockType.Image:images.append(block)- elif block["type"] == BlockType.Table:+ elif block["block_type"] == BlockType.Table:tables.append(block)- elif block["type"] == BlockType.InterlineEquation:+ elif block["block_type"] == BlockType.InterlineEquation:interline_equations.append(block)return images, tables, interline_equationsdiff --git a/magic_pdf/user_api.py b/magic_pdf/user_api.pyindex 04ece100..9850d479 100644--- a/magic_pdf/user_api.py+++ b/magic_pdf/user_api.py@@ -15,7 +15,7 @@from loguru import loggerfrom magic_pdf.rw import AbsReaderWriter-from magic_pdf.pdf_parse_by_ocr import parse_pdf_by_ocr+from magic_pdf.pdf_parse_by_ocr_v2 import parse_pdf_by_ocrfrom magic_pdf.pdf_parse_by_txt import parse_pdf_by_txt