krishna0506/Document_Intelligence
0
1import os2from pathlib import Path3 4def load_documents(folder_path: str):5 documents = []6 7 folder = Path(folder_path)8 9 # check if folder exists10 if not folder.exists():11 print(f"Data folder not found: {folder}")12 return documents13 14 # loop through files inside data folder15 for file in folder.iterdir():16 17 # skip directories18 if file.is_file():19 try:20 with open(file, "r", encoding="utf-8") as f:21 documents.append({22 "text": f.read(), # document content23 "source": file.name # filename24 })25 except Exception as e:26 print(f"Error reading {file.name}: {e}")27 28 return documents