Loading PDF, Docx, CSV
(
file: str,
filetype: str = '.pdf'
)
| 34 | |
| 35 | @staticmethod |
| 36 | def load_documents( |
| 37 | file: str, |
| 38 | filetype: str = '.pdf' |
| 39 | ) -> list[Document] | list[Any]: |
| 40 | #) -> Union[CSVLoader, Docx2txtLoader, PyMuPDFLoader, TextLoader]: |
| 41 | """Loading PDF, Docx, CSV""" |
| 42 | try: |
| 43 | if filetype == '.pdf': |
| 44 | loader = PyMuPDFLoader(file) |
| 45 | elif filetype == '.docx': |
| 46 | loader = Docx2txtLoader(file) |
| 47 | elif filetype == '.csv': |
| 48 | loader = CSVLoader(file, encoding='utf-8') |
| 49 | elif filetype == '.txt': |
| 50 | loader = TextLoader(file, encoding='utf-8') |
| 51 | |
| 52 | return loader.load() |
| 53 | |
| 54 | except Exception as e: |
| 55 | print(f'\033[31m{e}') |
| 56 | return [] |
| 57 | |
| 58 | @staticmethod |
| 59 | def split_documents( |
no outgoing calls
no test coverage detected