Downloads · 30 days
13
10% of all-time downloads
maloukafer/GLM-OCR-finetuned-documents
GLM-OCR-finetuned-documents is a machine learning model from maloukafer. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Modèle GLM-OCR fine-tuné avec LoRA sur ~5 466 documents annotés manuellement.
Downloads · 30 days
13
10% of all-time downloads
All-time downloads
136
Public
Repo size
262 KB
Likes
0
Public
Click a slice to open those files.
.json6.8 MB · 100%
From the Hugging Face model README
Modèle GLM-OCR fine-tuné avec LoRA sur ~5 466 documents annotés manuellement.
from transformers import AutoProcessor, GlmOcrForConditionalGeneration
import torch
from PIL import Image
model_id = "maloukafer/GLM-OCR-finetuned-documents"
processor = AutoProcessor.from_pretrained(model_id)
model = GlmOcrForConditionalGeneration.from_pretrained(
model_id, dtype=torch.bfloat16, device_map="auto"
)
model.eval()
image = Image.open("document.jpg").convert("RGB")
messages = [{"role": "user", "content": [
{"type": "image"},
{"type": "text", "text": "Document Parsing:"}
]}]
text_input = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = processor(text=text_input, images=[image], return_tensors="pt").to("cuda")
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
n = inputs["input_ids"].shape[1]
text = processor.decode(out[0][n:], skip_special_tokens=True).strip()
print(text)