cc-rag / backend /app /document_loader.py
matsuap's picture
feat: implement CC-RAG prototype with Neo4j, FastAPI, React
e675bdb
Raw
History Blame Contribute Delete
358 Bytes
import io
from pathlib import Path
from pypdf import PdfReader
def load_text(filename: str, content: bytes) -> str:
ext = Path(filename).suffix.lower()
if ext == ".pdf":
reader = PdfReader(io.BytesIO(content))
return "\n".join(page.extract_text() or "" for page in reader.pages)
return content.decode("utf-8", errors="replace")