Xenova HF staff commited on
Commit
e2b9e50
1 Parent(s): dc9a15a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +101 -1
README.md CHANGED
@@ -1,3 +1,103 @@
1
  ---
2
  license: other
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: other
3
+ base_model:
4
+ - deepseek-ai/Janus-1.3B
5
+ pipeline_tag: any-to-any
6
+ library_name: transformers.js
7
+ tags:
8
+ - text-to-image
9
+ - image-to-text
10
+ - image-text-to-text
11
+ ---
12
+
13
+ https://huggingface.co/deepseek-ai/Janus-1.3B with ONNX weights to be compatible with Transformers.js.
14
+
15
+ ## Usage (Transformers.js)
16
+
17
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
18
+ ```bash
19
+ npm i @huggingface/transformers
20
+ ```
21
+
22
+ **Example:** Image+text to text
23
+
24
+ ```js
25
+ import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
26
+
27
+ // Load processor and model
28
+ const model_id = "onnx-community/Janus-1.3B-ONNX";
29
+ const processor = await AutoProcessor.from_pretrained(model_id);
30
+ const model = await MultiModalityCausalLM.from_pretrained(model_id);
31
+
32
+ // Prepare inputs
33
+ const conversation = [
34
+ {
35
+ role: "User",
36
+ content: "<image_placeholder>\nConvert the formula into latex code.",
37
+ images: ["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/quadratic_formula.png"],
38
+ },
39
+ ];
40
+ const inputs = await processor(conversation);
41
+
42
+ // Generate response
43
+ const outputs = await model.generate({
44
+ ...inputs,
45
+ max_new_tokens: 150,
46
+ do_sample: false,
47
+ });
48
+
49
+ // Decode output
50
+ const new_tokens = outputs.slice(null, [inputs.input_ids.dims.at(-1), null]);
51
+ const decoded = processor.batch_decode(new_tokens, { skip_special_tokens: true });
52
+ console.log(decoded[0]);
53
+ ```
54
+
55
+ Sample output:
56
+
57
+ ````
58
+ Sure, here is the LaTeX code for the given formula:
59
+
60
+ ```
61
+ x = \frac{-b \pm \sqrt{b^2 - 4a c}}{2a}
62
+ ```
63
+
64
+ This code represents the mathematical expression for the variable \( x \).
65
+ ````
66
+
67
+ **Example:** Text to image
68
+
69
+ ```js
70
+ import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
71
+
72
+ // Load processor and model
73
+ const model_id = "onnx-community/Janus-1.3B-ONNX";
74
+ const processor = await AutoProcessor.from_pretrained(model_id);
75
+ const model = await MultiModalityCausalLM.from_pretrained(model_id);
76
+
77
+ // Prepare inputs
78
+ const conversation = [
79
+ {
80
+ role: "User",
81
+ 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.",
82
+ },
83
+ ];
84
+ const inputs = await processor(conversation, { chat_template: "text_to_image" });
85
+
86
+ // Generate response
87
+ const num_image_tokens = processor.num_image_tokens;
88
+ const outputs = await model.generate_images({
89
+ ...inputs,
90
+ min_new_tokens: num_image_tokens,
91
+ max_new_tokens: num_image_tokens,
92
+ do_sample: true,
93
+ });
94
+
95
+ // Save the generated image
96
+ await outputs[0].save("test.png");
97
+ ```
98
+
99
+ Sample outputs:
100
+
101
+ | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/wEGNOgE0B9U8o82lCODyF.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/57unIAQmnKNMKLv9Vkdfk.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/z3X8wn74dNh4XVOV4msuK.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/6BXCX_BEA7Xfg8eW82qWn.png) |
102
+ |---|---|---|---|
103
+ | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/3jifxfVMwWFNh0KgkcY7v.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/TpgVDGXDg3SLEMTZ4NmT9.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/z4FcpR847f_Ec9gd5HY84.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/x2VNcmO89fztUmOtZpdcB.png) |