Microsoft PowerPoint
Microsoft PowerPoint is a presentation program by Microsoft.
这涵盖了如何将 Microsoft PowerPoint 个文档加载为我们可在下游使用的文档格式。
请参阅本指南,了解在本地设置 Unstructured 的更多说明,包括设置所需的系统依赖项。
# Install packages
%pip install unstructured
%pip install python-magic
%pip install python-pptx
from langchain_community.document_loaders import UnstructuredPowerPointLoader
loader = UnstructuredPowerPointLoader("./example_data/fake-power-point.pptx")
data = loader.load()
data
[Document(page_content='Adding a Bullet Slide\n\nFind the bullet slide layout\n\nUse _TextFrame.text for first bullet\n\nUse _TextFrame.add_paragraph() for subsequent bullets\n\nHere is a lot of text!\n\nHere is some text in a text box!', metadata={'source': './example_data/fake-power-point.pptx'})]
保留元素
在底层,Unstructured 为不同的文本块创建不同的“元素”。默认情况下我们会将它们合并,但您可以通过指定 mode="elements" 轻松保留这种分离。
loader = UnstructuredPowerPointLoader(
"./example_data/fake-power-point.pptx", mode="elements"
)
data = loader.load()
data[0]
Document(page_content='Adding a Bullet Slide', metadata={'source': './example_data/fake-power-point.pptx', 'category_depth': 0, 'file_directory': './example_data', 'filename': 'fake-power-point.pptx', 'last_modified': '2023-12-19T13:42:18', 'page_number': 1, 'languages': ['eng'], 'filetype': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'category': 'Title'})
使用 Azure AI 文档智能
Azure AI Document Intelligence (formerly known as
Azure Form Recognizer) is machine-learning based service that extracts texts (including handwriting), tables, document structures (e.g., titles, section headings, etc.) and key-value-pairs from digital or scanned PDFs, images, Office and HTML files.Document Intelligence supports
JPEG/JPG,PNG,BMP,TIFF,HEIF,DOCX,XLSX,PPTXandHTML.
当前使用Document Intelligence的加载器实现可以按页整合内容,并将其转换为 LangChain 文档。默认输出格式为 Markdown,可轻松与MarkdownHeaderTextSplitter链接以实现语义文档分块。您也可以使用mode="single"或mode="page"返回单页纯文本,或返回按页分割的文档。
前置条件
在以下三个预览区域之一的 Azure AI 文档智能资源:美国东部、美国西部2、欧洲西部 - 如果您还没有,请按照此文档创建一个。您将向加载器传递 <endpoint> 和 <key> 作为参数。
%pip install --upgrade --quiet langchain langchain-community azure-ai-documentintelligence
from langchain_community.document_loaders import AzureAIDocumentIntelligenceLoader
file_path = "<filepath>"
endpoint = "<endpoint>"
key = "<key>"
loader = AzureAIDocumentIntelligenceLoader(
api_endpoint=endpoint, api_key=key, file_path=file_path, api_model="prebuilt-layout"
)
documents = loader.load()