Performed further optimizations on the factor loop and report extraction loop, added log handling for both processes, and implemented a screenshot feature for report extraction. (#100)

- Performed further optimizations on the factor loop and report extraction loop.
- Added log handling for both processes.
- Implemented a screenshot feature for report extraction.
This commit is contained in:
WinstonLiyt
2024-07-24 12:15:56 +08:00
committed by GitHub
parent 40d108687c
commit 226a0470ac
8 changed files with 160 additions and 48 deletions
@@ -1,6 +1,8 @@
from __future__ import annotations
from pathlib import Path
import fitz
from PIL import Image
from typing import TYPE_CHECKING
from azure.ai.formrecognizer import DocumentAnalysisClient
@@ -96,3 +98,11 @@ def load_and_process_pdfs_by_azure_document_intelligence(path: Path) -> dict[str
RD_AGENT_SETTINGS.azure_document_intelligence_endpoint,
)
return content_dict
def extract_first_page_screenshot_from_pdf(pdf_path: Path) -> Image:
doc = fitz.open(pdf_path)
page = doc.load_page(0)
pix = page.get_pixmap()
image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
return image