Spaces:
Sleeping
Sleeping
File size: 899 Bytes
e8e1f78 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import asyncio
import fitz
from app.observability.decorators import (
observe
)
class PDFParser:
@staticmethod
@observe("PDF Parsing - Step 2.1")
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) |