Spaces:
Runtime error
Runtime error
Download script/extraction.py from whosouravsharma/paper-qa-rag: direct link, hf CLI and curl.
- Browser
- Download file 739 Bytes
-
https://huggingface.co/spaces/whosouravsharma/paper-qa-rag/resolve/main/script/extraction.py
- Command line
-
hf download hf://spaces/whosouravsharma/paper-qa-rag/script/extraction.py
-
curl -L -o extraction.py https://huggingface.co/spaces/whosouravsharma/paper-qa-rag/resolve/main/script/extraction.py
739 Bytes
| from langchain_community.document_loaders import PyPDFLoader | |
| from langchain_core.documents import Document | |
| from script.errors import IngestionError | |
| MIN_TEXT_LENGTH = 500 # heuristic, tune later | |
| def extract_text_native(pdf_path: str) -> list[Document]: | |
| loader = PyPDFLoader(pdf_path) | |
| documents = loader.load() | |
| if not documents: | |
| raise IngestionError( | |
| code="PDF_PARSE_FAILED", | |
| message="No pages extracted from PDF" | |
| ) | |
| full_text = "\n".join(d.page_content for d in documents).strip() | |
| if len(full_text) < MIN_TEXT_LENGTH: | |
| raise IngestionError( | |
| code="INSUFFICIENT_TEXT", | |
| message="PDF likely scanned or image-based" | |
| ) | |
| return documents | |