使用非结构化PDF文件分区时出错

问题描述 投票:0回答:1

我正在尝试使用 Python 中的 unstructedunstructed[pdf] 库对 .pdf 文件进行分区,但我遇到了一个似乎无法解决的错误。 pdf 文件包含文本、表格、图像...

以下是我正在做的事情的简要概述:

from unstructured.partition.pdf import partition_pdf

path = '/content/'
file_name = 'ABCABC.pdf'

raw_pdf_elements = partition_pdf(
    filename=path + file_name,
    extract_images_in_pdf=True,
    infer_table_structure=True,
    chunking_strategy="by_title",
    max_characters=4000,
    new_after_n_chars=3800,
    combine_text_under_n_chars=2000,
    image_output_dir_path=path
)

错误消息: 当我运行代码时,出现以下错误:

NameError: name 'sort_page_elements' is not defined

环境:

  • 蟒蛇:3.9.19
  • 非结构化:0.15.1(我也尝试过 0.7.12 和 0.12.2)
  • 操作系统:Ubuntu 20.04

问题:

什么可能导致此 NameError,以及如何解决它?任何帮助将不胜感激!

更新

我尝试过解决方案@Oluwafemi Sule,但它不起作用,我的环境同时有 numpy 和 opencv-python

  • numpy:1.26.4
  • opencv-python (cv2):4.10.0.84
python python-3.x large-language-model rag
1个回答
1
投票

您有一个

NameError
,因为
partition_pdf
调用 document_to_element_list 函数,并且它调用
sort_page_elements

sort_page_elements
仅当 numpy 和 cv2 库可用时才会导入到模块中。

您应该安装numpycv2

© www.soinside.com 2019 - 2024. All rights reserved.