Spaces:
Sleeping
Sleeping
Download app/rag/parser.py from vara201/simple-rag: direct link, hf CLI and curl.
- Browser
- Download file 899 Bytes
-
https://huggingface.co/spaces/vara201/simple-rag/resolve/main/app/rag/parser.py
- Command line
-
hf download hf://spaces/vara201/simple-rag/app/rag/parser.py
-
curl -L -o parser.py https://huggingface.co/spaces/vara201/simple-rag/resolve/main/app/rag/parser.py
899 Bytes
| import asyncio | |
| import fitz | |
| from app.observability.decorators import ( | |
| observe | |
| ) | |
| class PDFParser: | |
| async def extract_pages( | |
| file_path: str, | |
| user_id: str, | |
| document_id: str, | |
| filename: str | |
| ): | |
| def _parse(): | |
| pdf = fitz.open(file_path) | |
| pages = [] | |
| for idx, page in enumerate( | |
| pdf, | |
| start=1 | |
| ): | |
| pages.append( | |
| { | |
| "user_id": user_id, | |
| "document_id": document_id, | |
| "filename": filename, | |
| "page_number": idx, | |
| "text": page.get_text() | |
| } | |
| ) | |
| pdf.close() | |
| return pages | |
| return await asyncio.to_thread(_parse) |