Views
No views yet
transformers). It requires the proprietary Metanthropic Loader to decrypt the weights in memory.1import os
2from huggingface_hub import hf_hub_download
3from cryptography.hazmat.primitives.ciphers.aead import AESGCM
4from transformers import AutoModelForImageTextToText, AutoProcessor
5
6# 1. Configuration
7REPO_ID = "metanthropic/BulBul-OCR"
8FILENAME = "bulbul-ocr-v1.mguf"
9SECRET_KEY = "YOUR_ACCESS_KEY_HERE" # Provided by Metanthropic Admin
10
11# 2. Download Encrypted Asset
12file_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
13
14# 3. Secure Decryption (In-Memory)
15key_bytes = bytes.fromhex(SECRET_KEY)
16aesgcm = AESGCM(key_bytes)
17
18with open(file_path, "rb") as f:
19 nonce = f.read(12)
20 header_len = int.from_bytes(f.read(4), 'little')
21 encrypted_header = f.read(header_len)
22 rest_of_body = f.read()
23
24# Decrypt Header
25decrypted_header = aesgcm.decrypt(nonce, encrypted_header, None)
26
27# 4. Load Model
28# (Note: In production, use a temp file or stream directly to avoid disk writes)
29os.makedirs("temp_load", exist_ok=True)
30with open("temp_load/model.safetensors", "wb") as f:
31 f.write(decrypted_header)
32 f.write(rest_of_body)
33
34print("✅ Model Decrypted. Loading into VRAM...")
35model = AutoModelForImageTextToText.from_pretrained(
36 "temp_load",
37 trust_remote_code=True,
38 device_map="auto"
39)
40processor = AutoProcessor.from_pretrained(REPO_ID, trust_remote_code=True)
41
42# 5. Run Inference
43from PIL import Image
44
45# Load your image
46image = Image.open("document.png")
47
48# Process and generate
49inputs = processor(images=image, return_tensors="pt").to(model.device)
50generated_ids = model.generate(**inputs, max_new_tokens=512)
51result = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
52
53print(result)pip install transformers huggingface_hub cryptography pillow torch| Dataset | Accuracy | Speed (imgs/sec) |
|---|---|---|
| SROIE | 94.2% | 12.5 |
| FUNSD | 91.8% | 10.3 |
| RVL-CDIP | 89.7% | 15.2 |
1@misc{bulbul-ocr-2024,
2 title={BulBul-OCR: A Sovereign Vision-Language Model for Optical Character Recognition},
3 author={Metanthropic Research Labs},
4 year={2024},
5 publisher={Metanthropic},
6 howpublished={\url{https://huggingface.co/metanthropic/BulBul-OCR}}
7}