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
增加生成多模态markdown逻辑
赵小蒙ec1a6ef7167d
diff --git a/magic_pdf/dict2md/ocr_mkcontent.py b/magic_pdf/dict2md/ocr_mkcontent.pyindex 65aaeec4..e6548ff9 100644--- a/magic_pdf/dict2md/ocr_mkcontent.py+++ b/magic_pdf/dict2md/ocr_mkcontent.py@@ -21,3 +21,31 @@ def mk_nlp_markdown(pdf_info_dict: dict):# 在行末添加两个空格以强制换行markdown.append(line_text.strip() + ' ')return '\n'.join(markdown)++def mk_mm_markdown(pdf_info_dict: dict):++ markdown = []++ for _, page_info in pdf_info_dict.items():+ blocks = page_info.get("preproc_blocks")+ if not blocks:+ continue+ for block in blocks:+ for line in block['lines']:+ line_text = ''+ for span in line['spans']:+ if not span.get('content'):+ if not span.get('image_path'):+ continue+ else:+ content = f""+ else:+ content = span['content'].replace('$', '\$') # 转义$+ if span['type'] == 'inline_equation':+ content = f"${content}$"+ elif span['type'] == 'displayed_equation':+ content = f"$$\n{content}\n$$"+ line_text += content + ' '+ # 在行末添加两个空格以强制换行+ markdown.append(line_text.strip() + ' ')+ return '\n'.join(markdown)diff --git a/magic_pdf/pre_proc/ocr_cut_image.py b/magic_pdf/pre_proc/ocr_cut_image.pyindex b6c3bdca..43f207f0 100644--- a/magic_pdf/pre_proc/ocr_cut_image.py+++ b/magic_pdf/pre_proc/ocr_cut_image.py@@ -12,8 +12,8 @@ def cut_image_and_table(spans, page, page_id, book_name, save_path):for span in spans:span_type = span['type']if span_type == 'image':- span['image_path'] = cut_image(span['bbox'], page_id, page, img_save_path('image'))+ span['image_path'] = cut_image(span['bbox'], page_id, page, img_save_path('images'))elif span_type == 'table':- span['image_path'] = cut_image(span['bbox'], page_id, page, img_save_path('table'))+ span['image_path'] = cut_image(span['bbox'], page_id, page, img_save_path('tables'))return spans