@min-pack/tfjs-node 2.17.1 → 3.8.1-patch.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +4 -2
  2. package/addon-node_modules/onnxruntime-node/bin/{napi-v3/linux/x64/libonnxruntime.so.1.14.0 → napi-v6/linux/arm64/libonnxruntime.so.1} +0 -0
  3. package/addon-node_modules/onnxruntime-node/bin/napi-v6/linux/arm64/onnxruntime_binding.node +0 -0
  4. package/addon-node_modules/onnxruntime-node/bin/napi-v6/linux/x64/libonnxruntime.so.1 +0 -0
  5. package/addon-node_modules/onnxruntime-node/bin/napi-v6/linux/x64/onnxruntime_binding.node +0 -0
  6. package/index.d.ts +2 -0
  7. package/index.js +7102 -3371
  8. package/package.json +1 -10
  9. package/tfjs-types/backends/onnx.d.ts +37 -0
  10. package/tfjs-types/base/feature_extraction_utils.d.ts +41 -0
  11. package/tfjs-types/base/image_processors_utils.d.ts +332 -0
  12. package/tfjs-types/base/processing_utils.d.ts +89 -0
  13. package/tfjs-types/configs.d.ts +93 -0
  14. package/tfjs-types/env.d.ts +112 -0
  15. package/tfjs-types/generation/configuration_utils.d.ts +326 -0
  16. package/tfjs-types/generation/logits_process.d.ts +364 -0
  17. package/tfjs-types/generation/logits_sampler.d.ts +51 -0
  18. package/tfjs-types/generation/parameters.d.ts +47 -0
  19. package/tfjs-types/generation/stopping_criteria.d.ts +81 -0
  20. package/tfjs-types/generation/streamers.d.ts +88 -0
  21. package/tfjs-types/models/audio_spectrogram_transformer/feature_extraction_audio_spectrogram_transformer.d.ts +25 -0
  22. package/tfjs-types/models/auto/feature_extraction_auto.d.ts +5 -0
  23. package/tfjs-types/models/auto/image_processing_auto.d.ts +5 -0
  24. package/tfjs-types/models/auto/processing_auto.d.ts +39 -0
  25. package/tfjs-types/models/beit/image_processing_beit.d.ts +4 -0
  26. package/tfjs-types/models/bit/image_processing_bit.d.ts +4 -0
  27. package/tfjs-types/models/chinese_clip/image_processing_chinese_clip.d.ts +4 -0
  28. package/tfjs-types/models/clap/feature_extraction_clap.d.ts +57 -0
  29. package/tfjs-types/models/clip/image_processing_clip.d.ts +6 -0
  30. package/tfjs-types/models/convnext/image_processing_convnext.d.ts +12 -0
  31. package/tfjs-types/models/dac/feature_extraction_dac.d.ts +4 -0
  32. package/tfjs-types/models/deit/image_processing_deit.d.ts +6 -0
  33. package/tfjs-types/models/detr/image_processing_detr.d.ts +42 -0
  34. package/tfjs-types/models/dinov3_vit/image_processing_dinov3_vit.d.ts +4 -0
  35. package/tfjs-types/models/donut/image_processing_donut.d.ts +7 -0
  36. package/tfjs-types/models/dpt/image_processing_dpt.d.ts +6 -0
  37. package/tfjs-types/models/efficientnet/image_processing_efficientnet.d.ts +6 -0
  38. package/tfjs-types/models/encodec/feature_extraction_encodec.d.ts +13 -0
  39. package/tfjs-types/models/feature_extractors.d.ts +16 -0
  40. package/tfjs-types/models/florence2/processing_florence2.d.ts +39 -0
  41. package/tfjs-types/models/gemma3n/feature_extraction_gemma3n.d.ts +35 -0
  42. package/tfjs-types/models/gemma3n/processing_gemma3n.d.ts +31 -0
  43. package/tfjs-types/models/glpn/image_processing_glpn.d.ts +4 -0
  44. package/tfjs-types/models/grounding_dino/image_processing_grounding_dino.d.ts +20 -0
  45. package/tfjs-types/models/grounding_dino/processing_grounding_dino.d.ts +27 -0
  46. package/tfjs-types/models/idefics3/image_processing_idefics3.d.ts +40 -0
  47. package/tfjs-types/models/idefics3/processing_idefics3.d.ts +19 -0
  48. package/tfjs-types/models/image_processors.d.ts +44 -0
  49. package/tfjs-types/models/janus/image_processing_janus.d.ts +7 -0
  50. package/tfjs-types/models/janus/processing_janus.d.ts +77 -0
  51. package/tfjs-types/models/jina_clip/image_processing_jina_clip.d.ts +5 -0
  52. package/tfjs-types/models/jina_clip/processing_jina_clip.d.ts +9 -0
  53. package/tfjs-types/models/llava/processing_llava.d.ts +12 -0
  54. package/tfjs-types/models/llava_onevision/image_processing_llava_onevision.d.ts +4 -0
  55. package/tfjs-types/models/mask2former/image_processing_mask2former.d.ts +4 -0
  56. package/tfjs-types/models/maskformer/image_processing_maskformer.d.ts +22 -0
  57. package/tfjs-types/models/mgp_str/processing_mgp_str.d.ts +64 -0
  58. package/tfjs-types/models/mobilenet_v1/image_processing_mobilenet_v1.d.ts +6 -0
  59. package/tfjs-types/models/mobilenet_v2/image_processing_mobilenet_v2.d.ts +6 -0
  60. package/tfjs-types/models/mobilenet_v3/image_processing_mobilenet_v3.d.ts +6 -0
  61. package/tfjs-types/models/mobilenet_v4/image_processing_mobilenet_v4.d.ts +6 -0
  62. package/tfjs-types/models/mobilevit/image_processing_mobilevit.d.ts +6 -0
  63. package/tfjs-types/models/moonshine/feature_extraction_moonshine.d.ts +13 -0
  64. package/tfjs-types/models/moonshine/processing_moonshine.d.ts +17 -0
  65. package/tfjs-types/models/nougat/image_processing_nougat.d.ts +4 -0
  66. package/tfjs-types/models/owlv2/image_processing_owlv2.d.ts +4 -0
  67. package/tfjs-types/models/owlvit/image_processing_owlvit.d.ts +10 -0
  68. package/tfjs-types/models/owlvit/processing_owlvit.d.ts +8 -0
  69. package/tfjs-types/models/paligemma/processing_paligemma.d.ts +12 -0
  70. package/tfjs-types/models/parakeet/feature_extraction_parakeet.d.ts +22 -0
  71. package/tfjs-types/models/phi3_v/image_processing_phi3_v.d.ts +17 -0
  72. package/tfjs-types/models/phi3_v/processing_phi3_v.d.ts +21 -0
  73. package/tfjs-types/models/pixtral/image_processing_pixtral.d.ts +4 -0
  74. package/tfjs-types/models/pixtral/processing_pixtral.d.ts +12 -0
  75. package/tfjs-types/models/processors.d.ts +25 -0
  76. package/tfjs-types/models/pvt/image_processing_pvt.d.ts +4 -0
  77. package/tfjs-types/models/pyannote/feature_extraction_pyannote.d.ts +31 -0
  78. package/tfjs-types/models/pyannote/processing_pyannote.d.ts +19 -0
  79. package/tfjs-types/models/qwen2_vl/image_processing_qwen2_vl.d.ts +11 -0
  80. package/tfjs-types/models/qwen2_vl/processing_qwen2_vl.d.ts +17 -0
  81. package/tfjs-types/models/rt_detr/image_processing_rt_detr.d.ts +8 -0
  82. package/tfjs-types/models/sam/image_processing_sam.d.ts +103 -0
  83. package/tfjs-types/models/sam/processing_sam.d.ts +9 -0
  84. package/tfjs-types/models/sam2/image_processing_sam2.d.ts +2 -0
  85. package/tfjs-types/models/sam2/processing_sam2.d.ts +6 -0
  86. package/tfjs-types/models/sam3/image_processing_sam3.d.ts +2 -0
  87. package/tfjs-types/models/sapiens/image_processing_sapiens.d.ts +10 -0
  88. package/tfjs-types/models/seamless_m4t/feature_extraction_seamless_m4t.d.ts +34 -0
  89. package/tfjs-types/models/segformer/image_processing_segformer.d.ts +10 -0
  90. package/tfjs-types/models/siglip/image_processing_siglip.d.ts +4 -0
  91. package/tfjs-types/models/smolvlm/image_processing_smolvlm.d.ts +2 -0
  92. package/tfjs-types/models/smolvlm/processing_smolvlm.d.ts +2 -0
  93. package/tfjs-types/models/snac/feature_extraction_snac.d.ts +4 -0
  94. package/tfjs-types/models/speecht5/feature_extraction_speecht5.d.ts +4 -0
  95. package/tfjs-types/models/speecht5/processing_speecht5.d.ts +14 -0
  96. package/tfjs-types/models/swin2sr/image_processing_swin2sr.d.ts +5 -0
  97. package/tfjs-types/models/ultravox/processing_ultravox.d.ts +16 -0
  98. package/tfjs-types/models/vit/image_processing_vit.d.ts +6 -0
  99. package/tfjs-types/models/vitmatte/image_processing_vitmatte.d.ts +12 -0
  100. package/tfjs-types/models/vitpose/image_processing_vitpose.d.ts +26 -0
  101. package/tfjs-types/models/voxtral/processing_voxtral.d.ts +16 -0
  102. package/tfjs-types/models/wav2vec2/feature_extraction_wav2vec2.d.ts +19 -0
  103. package/tfjs-types/models/wav2vec2/processing_wav2vec2.d.ts +14 -0
  104. package/tfjs-types/models/wav2vec2_with_lm/processing_wav2vec2_with_lm.d.ts +14 -0
  105. package/tfjs-types/models/wespeaker/feature_extraction_wespeaker.d.ts +23 -0
  106. package/tfjs-types/models/whisper/common_whisper.d.ts +8 -0
  107. package/tfjs-types/models/whisper/feature_extraction_whisper.d.ts +23 -0
  108. package/tfjs-types/models/whisper/generation_whisper.d.ts +76 -0
  109. package/tfjs-types/models/whisper/processing_whisper.d.ts +17 -0
  110. package/tfjs-types/models/yolos/image_processing_yolos.d.ts +10 -0
  111. package/tfjs-types/models.d.ts +4396 -0
  112. package/tfjs-types/ops/registry.d.ts +13 -0
  113. package/tfjs-types/pipelines.d.ts +2433 -0
  114. package/tfjs-types/tokenizers.d.ts +1002 -0
  115. package/tfjs-types/transformers.d.ts +27 -0
  116. package/tfjs-types/utils/audio.d.ts +160 -0
  117. package/tfjs-types/utils/constants.d.ts +8 -0
  118. package/tfjs-types/utils/core.d.ts +231 -0
  119. package/tfjs-types/utils/data-structures.d.ts +294 -0
  120. package/tfjs-types/utils/devices.d.ts +18 -0
  121. package/tfjs-types/utils/dtypes.d.ts +20 -0
  122. package/tfjs-types/utils/generic.d.ts +11 -0
  123. package/tfjs-types/utils/hub.d.ts +175 -0
  124. package/tfjs-types/utils/image.d.ts +141 -0
  125. package/tfjs-types/utils/maths.d.ts +282 -0
  126. package/tfjs-types/utils/tensor.d.ts +490 -0
  127. package/tfjs-types/utils/video.d.ts +37 -0
  128. package/addon-node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/libonnxruntime.so.1.14.0 +0 -0
  129. package/addon-node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/onnxruntime_binding.node +0 -0
  130. package/addon-node_modules/onnxruntime-node/bin/napi-v3/linux/x64/onnxruntime_binding.node +0 -0
@@ -0,0 +1,294 @@
1
+ /**
2
+ * @file Custom data structures.
3
+ *
4
+ * These are only used internally, meaning an end-user shouldn't
5
+ * need to access anything here.
6
+ *
7
+ * @module utils/data-structures
8
+ */
9
+ /**
10
+ * Efficient Heap-based Implementation of a Priority Queue.
11
+ * It uses an array-based binary heap, where the root is at index `0`, and the
12
+ * children of node `i` are located at indices `2i + 1` and `2i + 2`, respectively.
13
+ *
14
+ * Adapted from the following sources:
15
+ * - https://stackoverflow.com/a/42919752/13989043 (original)
16
+ * - https://github.com/belladoreai/llama-tokenizer-js (minor improvements)
17
+ */
18
+ export class PriorityQueue {
19
+ /**
20
+ * Create a new PriorityQueue.
21
+ * @param {function(any, any): boolean} comparator Comparator function to determine priority. Defaults to a MaxHeap.
22
+ */
23
+ constructor(comparator?: (arg0: any, arg1: any) => boolean, maxSize?: number);
24
+ _heap: any[];
25
+ _comparator: (arg0: any, arg1: any) => boolean;
26
+ _maxSize: number;
27
+ /**
28
+ * The size of the queue
29
+ */
30
+ get size(): number;
31
+ /**
32
+ * Check if the queue is empty.
33
+ * @returns {boolean} `true` if the queue is empty, `false` otherwise.
34
+ */
35
+ isEmpty(): boolean;
36
+ /**
37
+ * Return the element with the highest priority in the queue.
38
+ * @returns {any} The highest priority element in the queue.
39
+ */
40
+ peek(): any;
41
+ /**
42
+ * Add one or more elements to the queue.
43
+ * @param {...any} values The values to push into the queue.
44
+ * @returns {number} The new size of the queue.
45
+ */
46
+ push(...values: any[]): number;
47
+ /**
48
+ * Add multiple elements to the queue.
49
+ * @param {any[]} values The values to push into the queue.
50
+ * @returns {number} The new size of the queue.
51
+ */
52
+ extend(values: any[]): number;
53
+ /**
54
+ * Remove and return the element with the highest priority in the queue.
55
+ * @returns {any} The element with the highest priority in the queue.
56
+ */
57
+ pop(): any;
58
+ /**
59
+ * Replace the element with the highest priority in the queue with a new value.
60
+ * @param {*} value The new value.
61
+ * @returns {*} The replaced value.
62
+ */
63
+ replace(value: any): any;
64
+ /**
65
+ * Compute the index for the parent of the node at index `i`.
66
+ * @param {number} i The index of the node to get the parent of.
67
+ * @returns {number} The index of the parent node.
68
+ * @private
69
+ */
70
+ private _parent;
71
+ /**
72
+ * Compute the index for the left child of the node at index `i`.
73
+ * @param {number} i The index of the node to get the left child of.
74
+ * @returns {number} The index of the left child.
75
+ * @private
76
+ */
77
+ private _left;
78
+ /**
79
+ * Compute the index for the right child of the node at index `i`.
80
+ * @param {number} i The index of the node to get the right child of.
81
+ * @returns {number} The index of the right child.
82
+ * @private
83
+ */
84
+ private _right;
85
+ /**
86
+ * Check if the element at index `i` is greater than the element at index `j`.
87
+ * @param {number} i The index of the first element to compare.
88
+ * @param {number} j The index of the second element to compare.
89
+ * @returns {boolean} `true` if the element at index `i` is greater than the element at index `j`, `false` otherwise.
90
+ * @private
91
+ */
92
+ private _greater;
93
+ /**
94
+ * Swap the elements at indices `i` and `j`.
95
+ * @param {number} i The index of the first element to swap.
96
+ * @param {number} j The index of the second element to swap.
97
+ * @private
98
+ */
99
+ private _swap;
100
+ /**
101
+ * Maintain the heap property by updating positions in the heap,
102
+ * starting at the last element and moving up the heap.
103
+ * @private
104
+ */
105
+ private _siftUp;
106
+ /**
107
+ * Helper function to sift up from a given node.
108
+ * @param {number} node The index of the node to start sifting up from.
109
+ */
110
+ _siftUpFrom(node: number): void;
111
+ /**
112
+ * Maintain the heap property by updating positions in the heap,
113
+ * starting at the first element and moving down the heap.
114
+ * @private
115
+ */
116
+ private _siftDown;
117
+ /**
118
+ * Get the index of the smallest element in the heap. Since we use an array-based heap,
119
+ * the index can be computed without needing to traverse the heap.
120
+ * @private
121
+ */
122
+ private _smallest;
123
+ }
124
+ /**
125
+ * A trie structure to efficiently store and search for strings.
126
+ */
127
+ export class CharTrie {
128
+ root: CharTrieNode;
129
+ /**
130
+ * Adds one or more `texts` to the trie.
131
+ * @param {string[]} texts The strings to add to the trie.
132
+ */
133
+ extend(texts: string[]): void;
134
+ /**
135
+ * Adds text to the trie.
136
+ * @param {string} text The string to add to the trie.
137
+ */
138
+ push(text: string): void;
139
+ /**
140
+ * Searches the trie for all strings with a common prefix of `text`.
141
+ * @param {string} text The common prefix to search for.
142
+ * @yields {string} Each string in the trie that has `text` as a prefix.
143
+ */
144
+ commonPrefixSearch(text: string): Generator<string, void, unknown>;
145
+ }
146
+ /**
147
+ * A lattice data structure to be used for tokenization.
148
+ */
149
+ export class TokenLattice {
150
+ /**
151
+ * Creates a new TokenLattice instance.
152
+ *
153
+ * @param {string} sentence The input sentence to be tokenized.
154
+ * @param {number} bosTokenId The beginning-of-sequence token ID.
155
+ * @param {number} eosTokenId The end-of-sequence token ID.
156
+ */
157
+ constructor(sentence: string, bosTokenId: number, eosTokenId: number);
158
+ chars: string[];
159
+ len: number;
160
+ bosTokenId: number;
161
+ eosTokenId: number;
162
+ nodes: TokenLatticeNode[];
163
+ beginNodes: any[][];
164
+ endNodes: any[][];
165
+ /**
166
+ * Inserts a new token node into the token lattice.
167
+ *
168
+ * @param {number} pos The starting position of the token.
169
+ * @param {number} length The length of the token.
170
+ * @param {number} score The score of the token.
171
+ * @param {number} tokenId The token ID of the token.
172
+ */
173
+ insert(pos: number, length: number, score: number, tokenId: number): void;
174
+ /**
175
+ * Implements the Viterbi algorithm to compute the most likely sequence of tokens.
176
+ *
177
+ * @returns {TokenLatticeNode[]} The most likely sequence of tokens.
178
+ */
179
+ viterbi(): TokenLatticeNode[];
180
+ /**
181
+ * @param {TokenLatticeNode} node
182
+ * @returns {string} The array of nodes representing the most likely sequence of tokens.
183
+ */
184
+ piece(node: TokenLatticeNode): string;
185
+ /**
186
+ * @returns {string[]} The most likely sequence of tokens.
187
+ */
188
+ tokens(): string[];
189
+ /**
190
+ * @returns {number[]} The most likely sequence of token ids.
191
+ */
192
+ tokenIds(): number[];
193
+ }
194
+ /**
195
+ * A data structure which uses a trie to split a string into tokens based on a dictionary.
196
+ * It can also use a regular expression to preprocess the input text before splitting.
197
+ *
198
+ * NOTE: To ensure multi-byte characters are handled correctly, we operate at byte-level instead of character-level.
199
+ */
200
+ export class DictionarySplitter {
201
+ /**
202
+ * @param {string[]} dictionary The dictionary of words to use for splitting.
203
+ */
204
+ constructor(dictionary: string[]);
205
+ trie: any;
206
+ /**
207
+ * Builds a trie from the given dictionary.
208
+ * @param {string[]} dictionary The dictionary of words to build the trie from.
209
+ * @returns {Object} The root node of the trie.
210
+ * @private
211
+ */
212
+ private _buildTrie;
213
+ /**
214
+ * Splits the input text into tokens based on the dictionary.
215
+ * @param {string} text The input text to split.
216
+ * @returns {string[]} An array of tokens.
217
+ */
218
+ split(text: string): string[];
219
+ }
220
+ /**
221
+ * A simple Least Recently Used (LRU) cache implementation in JavaScript.
222
+ * This cache stores key-value pairs and evicts the least recently used item
223
+ * when the capacity is exceeded.
224
+ */
225
+ export class LRUCache {
226
+ /**
227
+ * Creates an LRUCache instance.
228
+ * @param {number} capacity The maximum number of items the cache can hold.
229
+ */
230
+ constructor(capacity: number);
231
+ capacity: number;
232
+ cache: Map<any, any>;
233
+ /**
234
+ * Retrieves the value associated with the given key and marks the key as recently used.
235
+ * @param {any} key The key to retrieve.
236
+ * @returns {any} The value associated with the key, or undefined if the key does not exist.
237
+ */
238
+ get(key: any): any;
239
+ /**
240
+ * Inserts or updates the key-value pair in the cache.
241
+ * If the key already exists, it is updated and marked as recently used.
242
+ * If the cache exceeds its capacity, the least recently used item is evicted.
243
+ * @param {any} key The key to add or update.
244
+ * @param {any} value The value to associate with the key.
245
+ */
246
+ put(key: any, value: any): void;
247
+ /**
248
+ * Clears the cache.
249
+ */
250
+ clear(): void;
251
+ }
252
+ /**
253
+ * Represents a node in a character trie.
254
+ */
255
+ declare class CharTrieNode {
256
+ /**
257
+ * Returns a new `CharTrieNode` instance with default values.
258
+ * @returns {CharTrieNode} A new `CharTrieNode` instance with `isLeaf` set to `false` and an empty `children` map.
259
+ */
260
+ static default(): CharTrieNode;
261
+ /**
262
+ * Create a new CharTrieNode.
263
+ * @param {boolean} isLeaf Whether the node is a leaf node or not.
264
+ * @param {Map<string, CharTrieNode>} children A map containing the node's children, where the key is a character and the value is a `CharTrieNode`.
265
+ */
266
+ constructor(isLeaf: boolean, children: Map<string, CharTrieNode>);
267
+ isLeaf: boolean;
268
+ children: Map<string, CharTrieNode>;
269
+ }
270
+ declare class TokenLatticeNode {
271
+ /**
272
+ * Represents a node in a token lattice for a given sentence.
273
+ * @param {number} tokenId The ID of the token associated with this node.
274
+ * @param {number} nodeId The ID of this node.
275
+ * @param {number} pos The starting position of the token in the sentence.
276
+ * @param {number} length The length of the token.
277
+ * @param {number} score The score associated with the token.
278
+ */
279
+ constructor(tokenId: number, nodeId: number, pos: number, length: number, score: number);
280
+ tokenId: number;
281
+ nodeId: number;
282
+ pos: number;
283
+ length: number;
284
+ score: number;
285
+ prev: any;
286
+ backtraceScore: number;
287
+ /**
288
+ * Returns a clone of this node.
289
+ * @returns {TokenLatticeNode} A clone of this node.
290
+ */
291
+ clone(): TokenLatticeNode;
292
+ }
293
+ export {};
294
+ //# sourceMappingURL=data-structures.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The list of devices supported by Transformers.js
3
+ */
4
+ export const DEVICE_TYPES: Readonly<{
5
+ auto: "auto";
6
+ gpu: "gpu";
7
+ cpu: "cpu";
8
+ wasm: "wasm";
9
+ webgpu: "webgpu";
10
+ cuda: "cuda";
11
+ dml: "dml";
12
+ webnn: "webnn";
13
+ 'webnn-npu': "webnn-npu";
14
+ 'webnn-gpu': "webnn-gpu";
15
+ 'webnn-cpu': "webnn-cpu";
16
+ }>;
17
+ export type DeviceType = keyof typeof DEVICE_TYPES;
18
+ //# sourceMappingURL=devices.d.ts.map
@@ -0,0 +1,20 @@
1
+ export function isWebGpuFp16Supported(): Promise<boolean>;
2
+ export const DATA_TYPES: Readonly<{
3
+ auto: "auto";
4
+ fp32: "fp32";
5
+ fp16: "fp16";
6
+ q8: "q8";
7
+ int8: "int8";
8
+ uint8: "uint8";
9
+ q4: "q4";
10
+ bnb4: "bnb4";
11
+ q4f16: "q4f16";
12
+ }>;
13
+ /** @typedef {keyof typeof DATA_TYPES} DataType */
14
+ export const DEFAULT_DEVICE_DTYPE_MAPPING: Readonly<{
15
+ wasm: "q8";
16
+ }>;
17
+ /** @type {Record<Exclude<DataType, "auto">, string>} */
18
+ export const DEFAULT_DTYPE_SUFFIX_MAPPING: Record<Exclude<DataType, "auto">, string>;
19
+ export type DataType = keyof typeof DATA_TYPES;
20
+ //# sourceMappingURL=dtypes.d.ts.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A base class for creating callable objects.
3
+ * See [here](https://stackoverflow.com/q/76073890) for more information.
4
+ *
5
+ * @type {new () => {(...args: any[]): any, _call(...args: any[]): any}}
6
+ */
7
+ export const Callable: new () => {
8
+ (...args: any[]): any;
9
+ _call(...args: any[]): any;
10
+ };
11
+ //# sourceMappingURL=generic.d.ts.map
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Helper function to get a file, using either the Fetch API or FileSystem API.
3
+ *
4
+ * @param {URL|string} urlOrPath The URL/path of the file to get.
5
+ * @returns {Promise<FileResponse|Response>} A promise that resolves to a FileResponse object (if the file is retrieved using the FileSystem API), or a Response object (if the file is retrieved using the Fetch API).
6
+ */
7
+ export function getFile(urlOrPath: URL | string): Promise<FileResponse | Response>;
8
+ /**
9
+ * Retrieves a file from either a remote URL using the Fetch API or from the local file system using the FileSystem API.
10
+ * If the filesystem is available and `env.useCache = true`, the file will be downloaded and cached.
11
+ *
12
+ * @param {string} path_or_repo_id This can be either:
13
+ * - a string, the *model id* of a model repo on huggingface.co.
14
+ * - a path to a *directory* potentially containing the file.
15
+ * @param {string} filename The name of the file to locate in `path_or_repo`.
16
+ * @param {boolean} [fatal=true] Whether to throw an error if the file is not found.
17
+ * @param {PretrainedOptions} [options] An object containing optional parameters.
18
+ * @param {boolean} [return_path=false] Whether to return the path of the file instead of the file content.
19
+ *
20
+ * @throws Will throw an error if the file is not found and `fatal` is true.
21
+ * @returns {Promise<string|Uint8Array>} A Promise that resolves with the file content as a Uint8Array if `return_path` is false, or the file path as a string if `return_path` is true.
22
+ */
23
+ export function getModelFile(path_or_repo_id: string, filename: string, fatal?: boolean, options?: PretrainedOptions, return_path?: boolean): Promise<string | Uint8Array>;
24
+ /**
25
+ * Fetches a text file from a given path and file name.
26
+ *
27
+ * @param {string} modelPath The path to the directory containing the file.
28
+ * @param {string} fileName The name of the file to fetch.
29
+ * @param {boolean} [fatal=true] Whether to throw an error if the file is not found.
30
+ * @param {PretrainedOptions} [options] An object containing optional parameters.
31
+ * @returns {Promise<string|null>} The text content of the file.
32
+ * @throws Will throw an error if the file is not found and `fatal` is true.
33
+ */
34
+ export function getModelText(modelPath: string, fileName: string, fatal?: boolean, options?: PretrainedOptions): Promise<string | null>;
35
+ /**
36
+ * Fetches a JSON file from a given path and file name.
37
+ *
38
+ * @param {string} modelPath The path to the directory containing the file.
39
+ * @param {string} fileName The name of the file to fetch.
40
+ * @param {boolean} [fatal=true] Whether to throw an error if the file is not found.
41
+ * @param {PretrainedOptions} [options] An object containing optional parameters.
42
+ * @returns {Promise<Object>} The JSON data parsed into a JavaScript object.
43
+ * @throws Will throw an error if the file is not found and `fatal` is true.
44
+ */
45
+ export function getModelJSON(modelPath: string, fileName: string, fatal?: boolean, options?: PretrainedOptions): Promise<any>;
46
+ /**
47
+ * @typedef {boolean|number} ExternalData Whether to load the model using the external data format (used for models >= 2GB in size).
48
+ * If `true`, the model will be loaded using the external data format.
49
+ * If a number, this many chunks will be loaded using the external data format (of the form: "model.onnx_data[_{chunk_number}]").
50
+ */
51
+ export const MAX_EXTERNAL_DATA_CHUNKS: 100;
52
+ /**
53
+ * Whether to load the model using the external data format (used for models >= 2GB in size).
54
+ * If `true`, the model will be loaded using the external data format.
55
+ * If a number, this many chunks will be loaded using the external data format (of the form: "model.onnx_data[_{chunk_number}]").
56
+ */
57
+ export type ExternalData = boolean | number;
58
+ /**
59
+ * Options for loading a pretrained model.
60
+ */
61
+ export type PretrainedOptions = {
62
+ /**
63
+ * If specified, this function will be called during model construction, to provide the user with progress updates.
64
+ */
65
+ progress_callback?: import("./core.js").ProgressCallback;
66
+ /**
67
+ * Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
68
+ * - The model is a model provided by the library (loaded with the *model id* string of a pretrained model).
69
+ * - The model is loaded by supplying a local directory as `pretrained_model_name_or_path` and a configuration JSON file named *config.json* is found in the directory.
70
+ */
71
+ config?: import("../configs.js").PretrainedConfig;
72
+ /**
73
+ * Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.
74
+ */
75
+ cache_dir?: string;
76
+ /**
77
+ * Whether or not to only look at local files (e.g., not try downloading the model).
78
+ */
79
+ local_files_only?: boolean;
80
+ /**
81
+ * The specific model version to use. It can be a branch name, a tag name, or a commit id,
82
+ * since we use a git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git.
83
+ * NOTE: This setting is ignored for local requests.
84
+ */
85
+ revision?: string;
86
+ };
87
+ /**
88
+ * Options for loading a pretrained model.
89
+ */
90
+ export type ModelSpecificPretrainedOptions = {
91
+ /**
92
+ * In case the relevant files are located inside a subfolder of the model repo on huggingface.co,
93
+ * you can specify the folder name here.
94
+ */
95
+ subfolder?: string;
96
+ /**
97
+ * If specified, load the model with this name (excluding the .onnx suffix). Currently only valid for encoder- or decoder-only models.
98
+ */
99
+ model_file_name?: string;
100
+ /**
101
+ * The device to run the model on. If not specified, the device will be chosen from the environment settings.
102
+ */
103
+ device?: import("./devices.js").DeviceType | Record<string, import("./devices.js").DeviceType>;
104
+ /**
105
+ * The data type to use for the model. If not specified, the data type will be chosen from the environment settings.
106
+ */
107
+ dtype?: import("./dtypes.js").DataType | Record<string, import("./dtypes.js").DataType>;
108
+ /**
109
+ * Whether to load the model using the external data format (used for models >= 2GB in size).
110
+ */
111
+ use_external_data_format?: ExternalData | Record<string, ExternalData>;
112
+ /**
113
+ * (Optional) User-specified session options passed to the runtime. If not provided, suitable defaults will be chosen.
114
+ */
115
+ session_options?: import("onnxruntime-common").InferenceSession.SessionOptions;
116
+ };
117
+ /**
118
+ * Options for loading a pretrained model.
119
+ */
120
+ export type PretrainedModelOptions = PretrainedOptions & ModelSpecificPretrainedOptions;
121
+ declare class FileResponse {
122
+ /**
123
+ * Creates a new `FileResponse` object.
124
+ * @param {string} filePath
125
+ */
126
+ constructor(filePath: string);
127
+ filePath: string;
128
+ headers: Headers;
129
+ exists: boolean;
130
+ status: number;
131
+ statusText: string;
132
+ body: ReadableStream<any>;
133
+ /**
134
+ * Updates the 'content-type' header property of the response based on the extension of
135
+ * the file specified by the filePath property of the current object.
136
+ * @returns {void}
137
+ */
138
+ updateContentType(): void;
139
+ /**
140
+ * Clone the current FileResponse object.
141
+ * @returns {FileResponse} A new FileResponse object with the same properties as the current object.
142
+ */
143
+ clone(): FileResponse;
144
+ /**
145
+ * Reads the contents of the file specified by the filePath property and returns a Promise that
146
+ * resolves with an ArrayBuffer containing the file's contents.
147
+ * @returns {Promise<ArrayBuffer>} A Promise that resolves with an ArrayBuffer containing the file's contents.
148
+ * @throws {Error} If the file cannot be read.
149
+ */
150
+ arrayBuffer(): Promise<ArrayBuffer>;
151
+ /**
152
+ * Reads the contents of the file specified by the filePath property and returns a Promise that
153
+ * resolves with a Blob containing the file's contents.
154
+ * @returns {Promise<Blob>} A Promise that resolves with a Blob containing the file's contents.
155
+ * @throws {Error} If the file cannot be read.
156
+ */
157
+ blob(): Promise<Blob>;
158
+ /**
159
+ * Reads the contents of the file specified by the filePath property and returns a Promise that
160
+ * resolves with a string containing the file's contents.
161
+ * @returns {Promise<string>} A Promise that resolves with a string containing the file's contents.
162
+ * @throws {Error} If the file cannot be read.
163
+ */
164
+ text(): Promise<string>;
165
+ /**
166
+ * Reads the contents of the file specified by the filePath property and returns a Promise that
167
+ * resolves with a parsed JavaScript object containing the file's contents.
168
+ *
169
+ * @returns {Promise<Object>} A Promise that resolves with a parsed JavaScript object containing the file's contents.
170
+ * @throws {Error} If the file cannot be read.
171
+ */
172
+ json(): Promise<any>;
173
+ }
174
+ export {};
175
+ //# sourceMappingURL=hub.d.ts.map
@@ -0,0 +1,141 @@
1
+ export class RawImage {
2
+ /**
3
+ * Helper method for reading an image from a variety of input types.
4
+ * @param {RawImage|string|URL|Blob|HTMLCanvasElement|OffscreenCanvas} input
5
+ * @returns The image object.
6
+ *
7
+ * **Example:** Read image from a URL.
8
+ * ```javascript
9
+ * let image = await RawImage.read('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg');
10
+ * // RawImage {
11
+ * // "data": Uint8ClampedArray [ 25, 25, 25, 19, 19, 19, ... ],
12
+ * // "width": 800,
13
+ * // "height": 533,
14
+ * // "channels": 3
15
+ * // }
16
+ * ```
17
+ */
18
+ static read(input: RawImage | string | URL | Blob | HTMLCanvasElement | OffscreenCanvas): Promise<RawImage>;
19
+ /**
20
+ * Read an image from a canvas.
21
+ * @param {HTMLCanvasElement|OffscreenCanvas} canvas The canvas to read the image from.
22
+ * @returns {RawImage} The image object.
23
+ */
24
+ static fromCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): RawImage;
25
+ /**
26
+ * Read an image from a URL or file path.
27
+ * @param {string|URL} url The URL or file path to read the image from.
28
+ * @returns {Promise<RawImage>} The image object.
29
+ */
30
+ static fromURL(url: string | URL): Promise<RawImage>;
31
+ /**
32
+ * Helper method to create a new Image from a blob.
33
+ * @param {Blob} blob The blob to read the image from.
34
+ * @returns {Promise<RawImage>} The image object.
35
+ */
36
+ static fromBlob(blob: Blob): Promise<RawImage>;
37
+ /**
38
+ * Helper method to create a new Image from a tensor
39
+ * @param {Tensor} tensor
40
+ */
41
+ static fromTensor(tensor: Tensor, channel_format?: string): RawImage;
42
+ /**
43
+ * Create a new `RawImage` object.
44
+ * @param {Uint8ClampedArray|Uint8Array} data The pixel data.
45
+ * @param {number} width The width of the image.
46
+ * @param {number} height The height of the image.
47
+ * @param {1|2|3|4} channels The number of channels.
48
+ */
49
+ constructor(data: Uint8ClampedArray | Uint8Array, width: number, height: number, channels: 1 | 2 | 3 | 4);
50
+ data: Uint8Array<ArrayBufferLike> | Uint8ClampedArray<ArrayBufferLike>;
51
+ width: number;
52
+ height: number;
53
+ channels: 2 | 1 | 3 | 4;
54
+ /**
55
+ * Returns the size of the image (width, height).
56
+ * @returns {[number, number]} The size of the image (width, height).
57
+ */
58
+ get size(): [number, number];
59
+ /**
60
+ * Convert the image to grayscale format.
61
+ * @returns {RawImage} `this` to support chaining.
62
+ */
63
+ grayscale(): RawImage;
64
+ /**
65
+ * Convert the image to RGB format.
66
+ * @returns {RawImage} `this` to support chaining.
67
+ */
68
+ rgb(): RawImage;
69
+ /**
70
+ * Convert the image to RGBA format.
71
+ * @returns {RawImage} `this` to support chaining.
72
+ */
73
+ rgba(): RawImage;
74
+ /**
75
+ * Apply an alpha mask to the image. Operates in place.
76
+ * @param {RawImage} mask The mask to apply. It should have a single channel.
77
+ * @returns {RawImage} The masked image.
78
+ * @throws {Error} If the mask is not the same size as the image.
79
+ * @throws {Error} If the image does not have 4 channels.
80
+ * @throws {Error} If the mask is not a single channel.
81
+ */
82
+ putAlpha(mask: RawImage): RawImage;
83
+ /**
84
+ * Resize the image to the given dimensions. This method uses the canvas API to perform the resizing.
85
+ * @param {number} width The width of the new image. `null` or `-1` will preserve the aspect ratio.
86
+ * @param {number} height The height of the new image. `null` or `-1` will preserve the aspect ratio.
87
+ * @param {Object} options Additional options for resizing.
88
+ * @param {0|1|2|3|4|5|string} [options.resample] The resampling method to use.
89
+ * @returns {Promise<RawImage>} `this` to support chaining.
90
+ */
91
+ resize(width: number, height: number, { resample, }?: {
92
+ resample?: 0 | 1 | 2 | 3 | 4 | 5 | string;
93
+ }): Promise<RawImage>;
94
+ pad([left, right, top, bottom]: [any, any, any, any]): Promise<any>;
95
+ crop([x_min, y_min, x_max, y_max]: [any, any, any, any]): Promise<any>;
96
+ center_crop(crop_width: any, crop_height: any): Promise<any>;
97
+ toBlob(type?: string, quality?: number): Promise<any>;
98
+ toTensor(channel_format?: string): Tensor;
99
+ toCanvas(): any;
100
+ /**
101
+ * Split this image into individual bands. This method returns an array of individual image bands from an image.
102
+ * For example, splitting an "RGB" image creates three new images each containing a copy of one of the original bands (red, green, blue).
103
+ *
104
+ * Inspired by PIL's `Image.split()` [function](https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.split).
105
+ * @returns {RawImage[]} An array containing bands.
106
+ */
107
+ split(): RawImage[];
108
+ /**
109
+ * Helper method to update the image data.
110
+ * @param {Uint8ClampedArray} data The new image data.
111
+ * @param {number} width The new width of the image.
112
+ * @param {number} height The new height of the image.
113
+ * @param {1|2|3|4|null} [channels] The new number of channels of the image.
114
+ * @private
115
+ */
116
+ private _update;
117
+ /**
118
+ * Clone the image
119
+ * @returns {RawImage} The cloned image
120
+ */
121
+ clone(): RawImage;
122
+ /**
123
+ * Helper method for converting image to have a certain number of channels
124
+ * @param {number} numChannels The number of channels. Must be 1, 3, or 4.
125
+ * @returns {RawImage} `this` to support chaining.
126
+ */
127
+ convert(numChannels: number): RawImage;
128
+ /**
129
+ * Save the image to the given path.
130
+ * @param {string} path The path to save the image to.
131
+ */
132
+ save(path: string): Promise<sharp.OutputInfo>;
133
+ toSharp(): sharp.Sharp;
134
+ }
135
+ /**
136
+ * Helper function to load an image from a URL, path, etc.
137
+ */
138
+ export const load_image: any;
139
+ import { Tensor } from './tensor.js';
140
+ import sharp from 'sharp';
141
+ //# sourceMappingURL=image.d.ts.map