PPTXToDocument

PPTXToDocument

PPTX 파일을 문서로 변환하는 컴포넌트예요.

출처: 문서

본문

항목 내용
파이프라인에서 가장 흔한 위치 PreProcessors 앞, 또는 인덱싱 파이프라인의 맨 처음
필수 run 변수 sources: PPTX 파일 경로 또는 ByteStream 객체
출력 변수 documents: 문서 목록
API reference Converters
GitHub 링크 pptx.py
패키지 이름 haystack-ai

개요

PPTXToDocument 컴포넌트는 PPTX 파일을 문서로 변환해요. 파일 경로나 ByteStream 객체 목록을 입력으로 받아 변환 결과를 문서 목록으로 출력하죠. 선택적으로 meta 입력 파라미터로 문서에 메타데이터를 붙일 수 있어요.

사용법

먼저 이 컨버터를 사용하려면 python-pptx 패키지를 설치해야 해요:

pip install python-pptx

단독으로 사용하기

from haystack.components.converters import PPTXToDocument

converter = PPTXToDocument()
results = converter.run(
    sources=["sample.pptx"],
    meta={"date_added": datetime.now().isoformat()},
)

documents = results["documents"]
print(documents[0].content)
# 'This is the text from the PPTX file.'

파이프라인에서 사용하기

from haystack import Pipeline
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.converters import PPTXToDocument
from haystack.components.preprocessors import DocumentCleaner
from haystack.components.preprocessors import DocumentSplitter
from haystack.components.writers import DocumentWriter

document_store = InMemoryDocumentStore()
pipeline = Pipeline()

pipeline.add_component("converter", PPTXToDocument())
pipeline.add_component("cleaner", DocumentCleaner())
pipeline.add_component(
    "splitter",
    DocumentSplitter(split_by="sentence", split_length=5),
)
pipeline.add_component("writer", DocumentWriter(document_store=document_store))

pipeline.connect("converter", "cleaner")
pipeline.connect("cleaner", "splitter")
pipeline.connect("splitter", "writer")

pipeline.run({"converter": {"sources": file_names}})

더 알아보기 (Learn more)