Spaces:
Runtime error
Runtime error
Download src/document_processing/loader.py from hello-yaaash25/zenith: direct link, hf CLI and curl.
- Browser
- Download file 984 Bytes
-
https://huggingface.co/spaces/hello-yaaash25/zenith/resolve/main/src/document_processing/loader.py
- Command line
-
hf download hf://spaces/hello-yaaash25/zenith/src/document_processing/loader.py
-
curl -L -o loader.py https://huggingface.co/spaces/hello-yaaash25/zenith/resolve/main/src/document_processing/loader.py
984 Bytes
| from typing import List | |
| import os | |
| class DocumentLoader: | |
| def __init__(self, file_paths: List[str]): | |
| self.file_paths = file_paths | |
| def load_documents(self) -> List[str]: | |
| documents = [] | |
| for file_path in self.file_paths: | |
| if os.path.exists(file_path): | |
| with open(file_path, 'r', encoding='utf-8') as file: | |
| documents.append(file.read()) | |
| else: | |
| raise FileNotFoundError(f"File not found: {file_path}") | |
| return documents | |
| def load_from_directory(self, directory_path: str) -> List[str]: | |
| documents = [] | |
| for filename in os.listdir(directory_path): | |
| file_path = os.path.join(directory_path, filename) | |
| if os.path.isfile(file_path): | |
| documents.extend(self.load_documents([file_path])) | |
| return documents | |
| def load_pdf(self, pdf_path: str) -> str: | |
| raise NotImplementedError("PDF loading not implemented yet.") |