Views
No views yet
npm i @huggingface/transformers1import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
2
3// Load processor and model
4const model_id = "onnx-community/Janus-1.3B-ONNX";
5const processor = await AutoProcessor.from_pretrained(model_id);
6const model = await MultiModalityCausalLM.from_pretrained(model_id);
7
8// Prepare inputs
9const conversation = [
10 {
11 role: "User",
12 content: "<image_placeholder>\nConvert the formula into latex code.",
13 images: ["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/quadratic_formula.png"],
14 },
15];
16const inputs = await processor(conversation);
17
18// Generate response
19const outputs = await model.generate({
20 ...inputs,
21 max_new_tokens: 150,
22 do_sample: false,
23});
24
25// Decode output
26const new_tokens = outputs.slice(null, [inputs.input_ids.dims.at(-1), null]);
27const decoded = processor.batch_decode(new_tokens, { skip_special_tokens: true });
28console.log(decoded[0]);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 \).1import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
2
3// Load processor and model
4const model_id = "onnx-community/Janus-1.3B-ONNX";
5const processor = await AutoProcessor.from_pretrained(model_id);
6const model = await MultiModalityCausalLM.from_pretrained(model_id);
7
8// Prepare inputs
9const conversation = [
10 {
11 role: "User",
12 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.",
13 },
14];
15const inputs = await processor(conversation, { chat_template: "text_to_image" });
16
17// Generate response
18const num_image_tokens = processor.num_image_tokens;
19const outputs = await model.generate_images({
20 ...inputs,
21 min_new_tokens: num_image_tokens,
22 max_new_tokens: num_image_tokens,
23 do_sample: true,
24});
25
26// Save the generated image
27await outputs[0].save("test.png");![]() | ![]() | ![]() | ![]() |
|---|---|---|---|
![]() | ![]() | ![]() | ![]() |