Spaces:
Runtime error
Runtime error
Download src/parser.py from ANAMARIAMAGALHAES/compliance: direct link, hf CLI and curl.
- Browser
- Download file 723 Bytes
-
https://huggingface.co/spaces/ANAMARIAMAGALHAES/compliance/resolve/main/src/parser.py
- Command line
-
hf download hf://spaces/ANAMARIAMAGALHAES/compliance/src/parser.py
-
curl -L -o parser.py https://huggingface.co/spaces/ANAMARIAMAGALHAES/compliance/resolve/main/src/parser.py
723 Bytes
| from langchain_community.document_loaders import ( | |
| PyPDFLoader, | |
| TextLoader, | |
| CSVLoader, | |
| UnstructuredHTMLLoader | |
| ) | |
| from pathlib import Path | |
| def load_documents(directory): | |
| docs = [] | |
| path = Path(directory) | |
| for file in path.rglob("*"): | |
| if file.suffix.lower() == ".pdf": | |
| docs.extend(PyPDFLoader(str(file)).load()) | |
| elif file.suffix.lower() == ".txt": | |
| docs.extend(TextLoader(str(file)).load()) | |
| elif file.suffix.lower() == ".csv": | |
| docs.extend(CSVLoader(file_path=str(file), encoding='utf-8').load()) | |
| elif file.suffix.lower() in [".html", ".htm"]: | |
| docs.extend(UnstructuredHTMLLoader(str(file)).load()) | |
| return docs | |