CoolFace
Apppublic

krishna0506/Document_Intelligence

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
ingest.py28 linesDownload Raw Back to root
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