1
0
adaptation-slr/models/p2-ocr.py
2025-05-20 23:12:11 -05:00

24 lines
704 B
Python

# https://huggingface.co/allenai/olmOCR-7B-0225-preview
import torch
import base64
from io import BytesIO
from PIL import image
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
from olmocr.data.renderpdf import render_pdf_to_base64png
from olmocr.prompts import build_finetuning_prompt
from olmocr.prompts.anchor import get_anchor_text
# Initialize the model
model = Qwen2VLForConditionalGeneration.from_pretrained("allenai/olmOCR-7B-0225-preview", torch_dtype=torch.bfloat16).eval()
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
#for all pages in a pdf
for
#