ComfyUI Node

GLM-OCR

Real OCR in the graph, no API key, no sending your images anywhere

By baijunty·Created 8 months ago·Updated 3 months ago· 0
GLM-OCR
  • images
  • STRING
names
prompt_type

Every now and then a workflow needs to actually read an image - a screenshot full of UI text, a meme with a caption, a scan, a table you'd rather not retype. GLM-OCR runs a real vision-language model locally inside ComfyUI and returns the text as JSON. No API key, no cloud upload, no per-page billing. Your images never leave your machine.

It's also the heavyweight of this pack and the one with the most moving parts, so let's be honest about what you're signing up for before you fall in love.

How it works

The node loads zai-org/GLM-OCR - a real, open OCR model from Zhipu's z.ai team, released around March 2026 and built on their GLM vision-lineage - using HuggingFace transformers. It converts each IMAGE tensor back to a PIL image, builds a chat-style message ("here's an image, here's my instruction"), and asks the model for text. The model is loaded once and cached at the class level, so the second and third runs skip the load.

The one knob it gives you, prompt_type, is a three-way selector that changes the instruction the model sees:

  • text_recognition - plain "Text Recognition:" for everyday text.
  • formula_recognition - for math and formulas.
  • table_recognition - for tables.

Output is a STRING holding JSON keyed by filename: {"page1.png": "the extracted text..."}. That JSON plugs into any downstream string processing, a save node, or a "show text" preview so you can eyeball the results.

The inputs that matter

  • images (IMAGE) and names (STRING) - the batch of images and their filenames, which become the JSON keys. The names input expects to line up with the batch.
  • prompt_type - optional, defaults to text_recognition. Choose the mode that matches your content.

Installing it - read this twice

The pack itself installs like any other (Manager, search "image_embeddings", or clone into custom_nodes). But the pack's own pyproject.toml does not list transformers as a dependency - the GLM node needs it and the rest of the pack doesn't. You'll have to install it yourself:

pip install transformers

Then the first run downloads the GLM-OCR model from HuggingFace - that's a multi-GB pull, and it happens on your first queue, so don't panic when nothing happens for a while on run one. It lands in your HuggingFace cache, so it's one-time (until it gets too old and the hub stops serving it).

Where people get burned

This node is a GPU hog. GLM-OCR is not a lightweight OCR tool - it's a vision-language model, so it wants a few GB of VRAM on top of whatever's running the diffusion model. On a cramped card, run it before or after your generation, not during, and expect it to slow your iteration.

It also batches through every image in the tensor one at a time, and it's generous with max_new_tokens - a dense table can produce a lot of tokens, which is slow. Keep batches small. If the model fails to load, it's almost always transformers missing, outdated, or a failed first download; install it, update it, and re-queue. For plain image-to-text this is the nicest local option in the pack - just don't treat it as a free lunch.

Categoryutils

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
namesSTRING
prompt_typeoptCOMBO3 options: text_recognition, formula_recognition, table_recognition

Outputs (1)

NameTypeDescription
STRINGSTRING