Create data/document_loader.py
Browse files- data/document_loader.py +24 -0
data/document_loader.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# document_loader.py
|
| 2 |
+
import os
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
+
class DocumentLoader:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
self.uploaded_file = None
|
| 8 |
+
|
| 9 |
+
def load_file(self, file_path: str) -> Optional[str]:
|
| 10 |
+
"""
|
| 11 |
+
Load the uploaded PDF file and validate it
|
| 12 |
+
Returns the file path if valid, None otherwise
|
| 13 |
+
"""
|
| 14 |
+
if not file_path:
|
| 15 |
+
return None
|
| 16 |
+
|
| 17 |
+
if not file_path.lower().endswith('.pdf'):
|
| 18 |
+
raise ValueError("Only PDF files are supported")
|
| 19 |
+
|
| 20 |
+
if not os.path.exists(file_path):
|
| 21 |
+
raise FileNotFoundError("File does not exist")
|
| 22 |
+
|
| 23 |
+
self.uploaded_file = file_path
|
| 24 |
+
return file_path
|