← All models

any-to-any Β· unified understanding + generation Β· WebGPU Β· ~2.4 GB

Janus-Pro β€” read an image and draw one, from one model

Janus-Pro is a unified multimodal model: the same 1B network both understands images β€” hand it a photo and ask anything β€” and generates them β€” give it a prompt and it paints a picture, pixel by pixel. It pulls this off by decoupling the vision path: one encoder for seeing, a separate image tokenizer for drawing. Both run entirely on your GPU. Nothing is uploaded.

At a glance

Modelonnx-community/Janus-Pro-1B-ONNX (ONNX build of deepseek-ai/Janus-Pro-1B)
Taskany-to-any β€” image-text-to-text (understanding) + text-to-image (generation)
ArchitectureSigLIP vision encoder (understanding) + VQ image tokenizer & decode head (generation) β†’ shared autoregressive LLM
Params / dtype~1B Β· WebGPU w/ shader-f16: LLM q4f16, heads fp16; no f16: LLM q4, embeds/heads fp32
BackendWebGPU (required) Β· prepare_inputs_embeds runs on WASM (upstream op bug)
Download~2.4 GB (with shader-f16) / ~4 GB fallback β€” cached after first load
Image tokens576 (a 24Γ—24 grid) per generated image, decoded to a 384Γ—384 raster
LicenseMIT
Web APIsWebGPU, Web Workers, Canvas, FileReader

Run it

Two cats on a couch A busy street scene An invoice with line items A photographed sign with text
…or drop / choose your own image
Selected image
The model's answer will stream here.

See inside

The trick behind a unified model is two vision paths, one brain. For understanding, your image goes through a SigLIP encoder into ~576 vision tokens that sit in the prompt next to your words, and the shared LLM reads the whole sequence and writes an answer. For generation, there's no input image β€” the LLM instead emits 576 discrete image tokens one at a time, and a separate VQ decoder turns that grid back into pixels. Same weights, two front doors.

Constructed prompt (understanding)

Ask about an image to see the templated prompt.

Token stream (value Β· ms since start)

Text tokens (understanding) appear here as they're generated. In generation mode, watch the 24Γ—24 grid above fill in.

Why it matters

Until now, "read this image" and "draw this image" were two different models, two downloads, two APIs. Janus-Pro folds both into a single ~1B model you can ship to a browser tab β€” private, offline-capable after first load, free per call. One asset unlocks a round-trip: see β†’ describe β†’ imagine β†’ draw.

Use cases

Basics

Both core moves side by side: describe an image, and generate one from a prompt.

Practical

Visual Q&A on a document, and generate an app icon / illustration from a text brief.

Wild

Round-trip: Janus generates an image, then describes its own output.

Multi-model

Janus understands an image β†’ a text model rewrites the caption into a polished blurb.

How the API works

Both paths load the same processor and model. Understanding calls generate with an image placeholder in the conversation; generation switches the chat template to text_to_image and calls generate_images, which decodes the emitted image tokens into a RawImage:

import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";

const model_id = "onnx-community/Janus-Pro-1B-ONNX";
const processor = await AutoProcessor.from_pretrained(model_id);           // β†’ VLChatProcessor
const model = await MultiModalityCausalLM.from_pretrained(model_id, { device: "webgpu", dtype: {…} });

// (a) Understanding: image + text β†’ text
const conv = [{ role: "<|User|>", content: "<image_placeholder>\nWhat is this?", images: [url] }];
const inputs = await processor(conv);
const out = await model.generate({ ...inputs, max_new_tokens: 200, do_sample: false });
console.log(processor.batch_decode(out.slice(null, [inputs.input_ids.dims.at(-1), null]), { skip_special_tokens: true })[0]);

// (b) Generation: text β†’ image
const gconv = [{ role: "<|User|>", content: "a red fox in autumn leaves" }];
const ginputs = await processor(gconv, { chat_template: "text_to_image" });
const n = processor.num_image_tokens;                                       // 576
const images = await model.generate_images({ ...ginputs, min_new_tokens: n, max_new_tokens: n, do_sample: true });
await images[0].save("out.png");

This page runs exactly that, in a Web Worker, and gates on a real WebGPU adapter first β€” if none exists it shows a labelled needs-WebGPU state instead of a fake image.

References