Spaces:
Sleeping
Sleeping
Download src/loader.py from ABDRauf/dynamic-rag-fastapi: direct link, hf CLI and curl.
- Browser
- Download file 767 Bytes
-
https://huggingface.co/spaces/ABDRauf/dynamic-rag-fastapi/resolve/main/src/loader.py
- Command line
-
hf download hf://spaces/ABDRauf/dynamic-rag-fastapi/src/loader.py
-
curl -L -o loader.py https://huggingface.co/spaces/ABDRauf/dynamic-rag-fastapi/resolve/main/src/loader.py
767 Bytes
| 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 |