Spaces:
Sleeping
Sleeping
File size: 510 Bytes
2068d15 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import os
from pathlib import Path
SUPPORTED_EXTENSIONS = {".txt", ".md"}
def load_documents_from_dir(directory: str) -> list[dict]:
docs = []
for file_path in Path(directory).rglob("*"):
if file_path.suffix.lower() in SUPPORTED_EXTENSIONS:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
docs.append({
"content": content,
"source": str(file_path)
})
return docs
|