AnandSingh/hunyuanocr-mlx
2186
HunyuanOCR MLX
HunyuanOCR converted to Apple MLX for native Apple Silicon inference on Mac.
This is a conversion of Tencent's HunyuanOCR — a 1B parameter OCR expert Vision-Language Model. It achieves SOTA across text spotting, complex document parsing, information extraction, video subtitle extraction, and photo translation.
Model Architecture
Quick Start
pip install mlx transformers torch torchvision Pillow
git clone https://huggingface.co/AnandSingh/hunyuanocr-mlximport mlx.core as mx
from PIL import Image
# Import the model code
from hunyuan_ocr_mlx import HunyuanOCR, HunyuanOCRProcessor
model = HunyuanOCR("config.json")
model.load_weights("model.safetensors")
processor = HunyuanOCRProcessor.from_pretrained(".")
# Run OCR
img = Image.open("document.jpg")
prompt = "检测并识别图片中的文字,将文本坐标格式化输出。"
processed = processor.process([img], [prompt])
hidden_states, past_kvs = model(
input_ids=processed.input_ids,
pixel_values=processed.pixel_values,
position_ids=processed.position_ids,
attention_mask=processed.attention_mask,
grid_thw=processed.grid_thw,
)
# Generate
logits = model.lm_head(hidden_states[:, -1:, :])
next_token = mx.argmax(logits[:, -1, :], axis=-1)Prompt Examples
Requirements
- Apple Silicon Mac (M1/M2/M3/M4)
- macOS 14+
- Python 3.9+
- MLX, transformers, torch, Pillow
License
This model is a derivative of Tencent HunyuanOCR, licensed under the Tencent Hunyuan Community License Agreement.
Attribution
Original model by Tencent Hunyuan Vision Team. This MLX conversion is not affiliated with or endorsed by Tencent.
