Spaces:
Sleeping
Sleeping
Create document_loader.py
Browse files- document_loader.py +24 -0
document_loader.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
document_loader.py
|
| 3 |
+
|
| 4 |
+
Module for loading documents from PDF files using PyMuPDFLoader.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from langchain_community.document_loaders import PyMuPDFLoader
|
| 8 |
+
|
| 9 |
+
def load_document(file_path):
|
| 10 |
+
"""Loads a document from a PDF file.
|
| 11 |
+
|
| 12 |
+
Args:
|
| 13 |
+
file_path (str): Path to the PDF file.
|
| 14 |
+
|
| 15 |
+
Returns:
|
| 16 |
+
list: A list of documents if loaded successfully, else an empty list.
|
| 17 |
+
"""
|
| 18 |
+
loader = PyMuPDFLoader(file_path)
|
| 19 |
+
try:
|
| 20 |
+
documents = loader.load()
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"Error loading document: {e}")
|
| 23 |
+
documents = []
|
| 24 |
+
return documents
|