Spaces:
Sleeping
Sleeping
File size: 767 Bytes
305ef4d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from langchain_community.document_loaders import PyPDFLoader
from src.logger import logger
def load_pdf(file_path: str):
"""
Loads a PDF file from the given path and returns a list of LangChain Document objects.
"""
logger.info(f"Attempting to load PDF from: {file_path}")
try:
# Initialize the loader
loader = PyPDFLoader(file_path)
# Load the document
docs = loader.load()
logger.info(f"Successfully loaded {len(docs)} pages from the PDF.")
# Return the docs so the splitter can use them
return docs
except Exception as e:
logger.error(f"PDF Loader failed to read {file_path}: {str(e)}", exc_info=True)
raise e |