Spaces:
Runtime error
Runtime error
Download pdf_utils.py from shubhendu-ghosh/polydocs: direct link, hf CLI and curl.
- Browser
- Download file 441 Bytes
-
https://huggingface.co/spaces/shubhendu-ghosh/polydocs/resolve/main/pdf_utils.py
- Command line
-
hf download hf://spaces/shubhendu-ghosh/polydocs/pdf_utils.py
-
curl -L -o pdf_utils.py https://huggingface.co/spaces/shubhendu-ghosh/polydocs/resolve/main/pdf_utils.py
441 Bytes
| from PyPDF2 import PdfReader | |
| from langchain.text_splitter import RecursiveCharacterTextSplitter | |
| async def extract_text_from_pdfs(files): | |
| text = "" | |
| for file in files: | |
| pdf = PdfReader(file.file) | |
| for page in pdf.pages: | |
| text += page.extract_text() | |
| return text | |
| def split_text(text): | |
| splitter = RecursiveCharacterTextSplitter(chunk_size=10000, chunk_overlap=1000) | |
| return splitter.split_text(text) | |