đ Janus-1.3B ONNX with Transformers.js
This project makes https://huggingface.co/deepseek-ai/Janus-1.3B compatible with Transformers.js using ONNX weights. It supports various modalities like text - to - image, image - to - text, and image - text - to - text.
đ Quick Start
đĻ Installation
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @huggingface/transformers
đģ Usage Examples
[Basic Usage]
Example 1: Image+text to text
import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
const model_id = "onnx-community/Janus-1.3B-ONNX";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await MultiModalityCausalLM.from_pretrained(model_id);
const conversation = [
{
role: "User",
content: "<image_placeholder>\nConvert the formula into latex code.",
images: ["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/quadratic_formula.png"],
},
];
const inputs = await processor(conversation);
const outputs = await model.generate({
...inputs,
max_new_tokens: 150,
do_sample: false,
});
const new_tokens = outputs.slice(null, [inputs.input_ids.dims.at(-1), null]);
const decoded = processor.batch_decode(new_tokens, { skip_special_tokens: true });
console.log(decoded[0]);
Sample output:
Sure, here is the LaTeX code for the given formula:
x = \frac{-b \pm \sqrt{b^2 - 4a c}}{2a}
This code represents the mathematical expression for the variable \( x \).
Example 2: Text to image
import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
const model_id = "onnx-community/Janus-1.3B-ONNX";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await MultiModalityCausalLM.from_pretrained(model_id);
const conversation = [
{
role: "User",
content: "A cute and adorable baby fox with big brown eyes, autumn leaves in the background enchanting,immortal,fluffy, shiny mane,Petals,fairyism,unreal engine 5 and Octane Render,highly detailed, photorealistic, cinematic, natural colors.",
},
];
const inputs = await processor(conversation, { chat_template: "text_to_image" });
const num_image_tokens = processor.num_image_tokens;
const outputs = await model.generate_images({
...inputs,
min_new_tokens: num_image_tokens,
max_new_tokens: num_image_tokens,
do_sample: true,
});
await outputs[0].save("test.png");
Sample outputs:
đ Try it out
Want to play around with the model? Check out the online WebGPU demo.
đ License
The license for this project is other
.
đ Documentation
Model Information
Property |
Details |
Model Type |
Compatible with Transformers.js using ONNX weights, supporting text - to - image, image - to - text, and image - text - to - text modalities |
Base Model |
deepseek - ai/Janus - 1.3B |
Pipeline Tag |
any - to - any |
Library Name |
transformers.js |
Tags |
text - to - image, image - to - text, image - text - to - text |