Spaces:
Sleeping
Sleeping
Download ingest/parse.py from Ritabanm/deepdive-IR: direct link, hf CLI and curl.
- Browser
- Download file 368 Bytes
-
https://huggingface.co/spaces/Ritabanm/deepdive-IR/resolve/main/ingest/parse.py
- Command line
-
hf download hf://spaces/Ritabanm/deepdive-IR/ingest/parse.py
-
curl -L -o parse.py https://huggingface.co/spaces/Ritabanm/deepdive-IR/resolve/main/ingest/parse.py
368 Bytes
| from bs4 import BeautifulSoup | |
| from pypdf import PdfReader | |
| from io import BytesIO | |
| def html_to_text(html: str) -> str: | |
| soup = BeautifulSoup(html, "html.parser") | |
| return soup.get_text(separator="\n") | |
| def pdf_bytes_to_text(b: bytes) -> str: | |
| reader = PdfReader(BytesIO(b)) | |
| pages = [p.extract_text() or "" for p in reader.pages] | |
| return "\n".join(pages) | |