@huggingface/tasks 0.3.3 → 0.4.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.
- package/dist/index.cjs +46 -4
- package/dist/index.d.ts +2029 -12
- package/dist/index.js +46 -4
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/model-data.ts +32 -7
- package/src/model-libraries-snippets.ts +41 -3
- package/src/model-libraries.ts +7 -0
- package/src/pipelines.ts +1 -1
- package/src/tasks/index.ts +58 -0
- package/src/tasks/summarization/inference.ts +3 -6
- package/src/tasks/summarization/spec/output.json +9 -2
- package/src/tasks/translation/inference.ts +3 -6
- package/src/tasks/translation/spec/output.json +9 -2
- package/src/widget-example.ts +10 -0
package/dist/index.js
CHANGED
|
@@ -1260,7 +1260,7 @@ var PIPELINE_DATA = {
|
|
|
1260
1260
|
color: "green"
|
|
1261
1261
|
},
|
|
1262
1262
|
"image-text-to-text": {
|
|
1263
|
-
name: "Image
|
|
1263
|
+
name: "Image-Text-to-Text",
|
|
1264
1264
|
modality: "multimodal",
|
|
1265
1265
|
color: "red",
|
|
1266
1266
|
hideInDatasets: true
|
|
@@ -4187,7 +4187,7 @@ model = joblib.load(
|
|
|
4187
4187
|
};
|
|
4188
4188
|
var sklearn = (model) => {
|
|
4189
4189
|
if (model.tags?.includes("skops")) {
|
|
4190
|
-
const skopsmodelFile = model.config?.sklearn?.
|
|
4190
|
+
const skopsmodelFile = model.config?.sklearn?.model?.file;
|
|
4191
4191
|
const skopssaveFormat = model.config?.sklearn?.model_format;
|
|
4192
4192
|
if (!skopsmodelFile) {
|
|
4193
4193
|
return [`# \u26A0\uFE0F Model filename not specified in config.json`];
|
|
@@ -4257,7 +4257,7 @@ var speechBrainMethod = (speechbrainInterface) => {
|
|
|
4257
4257
|
}
|
|
4258
4258
|
};
|
|
4259
4259
|
var speechbrain = (model) => {
|
|
4260
|
-
const speechbrainInterface = model.config?.speechbrain?.
|
|
4260
|
+
const speechbrainInterface = model.config?.speechbrain?.speechbrain_interface;
|
|
4261
4261
|
if (speechbrainInterface === void 0) {
|
|
4262
4262
|
return [`# interface not specified in config.json`];
|
|
4263
4263
|
}
|
|
@@ -4335,7 +4335,7 @@ var peftTask = (peftTaskType) => {
|
|
|
4335
4335
|
}
|
|
4336
4336
|
};
|
|
4337
4337
|
var peft = (model) => {
|
|
4338
|
-
const {
|
|
4338
|
+
const { base_model_name_or_path: peftBaseModel, task_type: peftTaskType } = model.config?.peft ?? {};
|
|
4339
4339
|
const pefttask = peftTask(peftTaskType);
|
|
4340
4340
|
if (!pefttask) {
|
|
4341
4341
|
return [`Task type is invalid.`];
|
|
@@ -4406,6 +4406,41 @@ var pythae = (model) => [
|
|
|
4406
4406
|
|
|
4407
4407
|
model = AutoModel.load_from_hf_hub("${model.id}")`
|
|
4408
4408
|
];
|
|
4409
|
+
var musicgen = (model) => [
|
|
4410
|
+
`from audiocraft.models import MusicGen
|
|
4411
|
+
|
|
4412
|
+
model = MusicGen.get_pretrained("${model.id}")
|
|
4413
|
+
|
|
4414
|
+
descriptions = ['happy rock', 'energetic EDM', 'sad jazz']
|
|
4415
|
+
wav = model.generate(descriptions) # generates 3 samples.`
|
|
4416
|
+
];
|
|
4417
|
+
var magnet = (model) => [
|
|
4418
|
+
`from audiocraft.models import MAGNeT
|
|
4419
|
+
|
|
4420
|
+
model = MAGNeT.get_pretrained("${model.id}")
|
|
4421
|
+
|
|
4422
|
+
descriptions = ['disco beat', 'energetic EDM', 'funky groove']
|
|
4423
|
+
wav = model.generate(descriptions) # generates 3 samples.`
|
|
4424
|
+
];
|
|
4425
|
+
var audiogen = (model) => [
|
|
4426
|
+
`from audiocraft.models import AudioGen
|
|
4427
|
+
|
|
4428
|
+
model = AudioGen.get_pretrained("${model.id}")
|
|
4429
|
+
model.set_generation_params(duration=5) # generate 5 seconds.
|
|
4430
|
+
descriptions = ['dog barking', 'sirene of an emergency vehicle', 'footsteps in a corridor']
|
|
4431
|
+
wav = model.generate(descriptions) # generates 3 samples.`
|
|
4432
|
+
];
|
|
4433
|
+
var audiocraft = (model) => {
|
|
4434
|
+
if (model.tags?.includes("musicgen")) {
|
|
4435
|
+
return musicgen(model);
|
|
4436
|
+
} else if (model.tags?.includes("audiogen")) {
|
|
4437
|
+
return audiogen(model);
|
|
4438
|
+
} else if (model.tags?.includes("magnet")) {
|
|
4439
|
+
return magnet(model);
|
|
4440
|
+
} else {
|
|
4441
|
+
return [`# Type of model unknown.`];
|
|
4442
|
+
}
|
|
4443
|
+
};
|
|
4409
4444
|
|
|
4410
4445
|
// src/model-libraries.ts
|
|
4411
4446
|
var MODEL_LIBRARIES_UI_ELEMENTS = {
|
|
@@ -4439,6 +4474,13 @@ var MODEL_LIBRARIES_UI_ELEMENTS = {
|
|
|
4439
4474
|
term: { path: "pytorch_model.bin" }
|
|
4440
4475
|
}
|
|
4441
4476
|
},
|
|
4477
|
+
audiocraft: {
|
|
4478
|
+
prettyLabel: "Audiocraft",
|
|
4479
|
+
repoName: "audiocraft",
|
|
4480
|
+
repoUrl: "https://github.com/facebookresearch/audiocraft",
|
|
4481
|
+
snippets: audiocraft,
|
|
4482
|
+
filter: false
|
|
4483
|
+
},
|
|
4442
4484
|
bertopic: {
|
|
4443
4485
|
prettyLabel: "BERTopic",
|
|
4444
4486
|
repoName: "BERTopic",
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -19,12 +19,14 @@ export type { LibraryUiElement, ModelLibraryKey } from "./model-libraries";
|
|
|
19
19
|
export type { ModelData, TransformersInfo } from "./model-data";
|
|
20
20
|
export type { SpecialTokensMap, TokenizerConfig } from "./tokenizer-data";
|
|
21
21
|
export type {
|
|
22
|
+
ChatMessage,
|
|
22
23
|
WidgetExample,
|
|
23
24
|
WidgetExampleAttribute,
|
|
24
25
|
WidgetExampleAssetAndPromptInput,
|
|
25
26
|
WidgetExampleAssetAndTextInput,
|
|
26
27
|
WidgetExampleAssetAndZeroShotInput,
|
|
27
28
|
WidgetExampleAssetInput,
|
|
29
|
+
WidgetExampleChatInput,
|
|
28
30
|
WidgetExampleSentenceSimilarityInput,
|
|
29
31
|
WidgetExampleStructuredDataInput,
|
|
30
32
|
WidgetExampleTableDataInput,
|
package/src/model-data.ts
CHANGED
|
@@ -40,21 +40,46 @@ export interface ModelData {
|
|
|
40
40
|
/**
|
|
41
41
|
* this dictionary has useful information about the model configuration
|
|
42
42
|
*/
|
|
43
|
-
config?:
|
|
44
|
-
adapter_transformers?: { model_class?: string; model_name?: string };
|
|
43
|
+
config?: {
|
|
45
44
|
architectures?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Dict of AutoModel or Auto… class name to local import path in the repo
|
|
47
|
+
*/
|
|
48
|
+
auto_map?: {
|
|
49
|
+
/**
|
|
50
|
+
* String Property
|
|
51
|
+
*/
|
|
52
|
+
[x: string]: string;
|
|
53
|
+
};
|
|
54
|
+
model_type?: string;
|
|
55
|
+
quantization_config?: {
|
|
56
|
+
bits?: number;
|
|
57
|
+
load_in_4bit?: boolean;
|
|
58
|
+
load_in_8bit?: boolean;
|
|
59
|
+
};
|
|
60
|
+
tokenizer_config?: TokenizerConfig;
|
|
61
|
+
adapter_transformers?: {
|
|
62
|
+
model_name?: string;
|
|
63
|
+
model_class?: string;
|
|
64
|
+
};
|
|
65
|
+
diffusers?: {
|
|
66
|
+
_class_name?: string;
|
|
67
|
+
};
|
|
46
68
|
sklearn?: {
|
|
47
|
-
|
|
69
|
+
model?: {
|
|
70
|
+
file?: string;
|
|
71
|
+
};
|
|
48
72
|
model_format?: string;
|
|
49
73
|
};
|
|
50
74
|
speechbrain?: {
|
|
51
|
-
|
|
75
|
+
speechbrain_interface?: string;
|
|
76
|
+
vocoder_interface?: string;
|
|
77
|
+
vocoder_model_id?: string;
|
|
52
78
|
};
|
|
53
79
|
peft?: {
|
|
54
|
-
|
|
80
|
+
base_model_name_or_path?: string;
|
|
55
81
|
task_type?: string;
|
|
56
82
|
};
|
|
57
|
-
tokenizer_config?: TokenizerConfig;
|
|
58
83
|
};
|
|
59
84
|
/**
|
|
60
85
|
* all the model tags
|
|
@@ -80,7 +105,7 @@ export interface ModelData {
|
|
|
80
105
|
*/
|
|
81
106
|
widgetData?: WidgetExample[] | undefined;
|
|
82
107
|
/**
|
|
83
|
-
* Parameters that will be used by the widget when calling Inference
|
|
108
|
+
* Parameters that will be used by the widget when calling Inference API (serverless)
|
|
84
109
|
* https://huggingface.co/docs/api-inference/detailed_parameters
|
|
85
110
|
*
|
|
86
111
|
* can be set in the model card metadata (under `inference/parameters`)
|
|
@@ -293,7 +293,7 @@ model = joblib.load(
|
|
|
293
293
|
|
|
294
294
|
export const sklearn = (model: ModelData): string[] => {
|
|
295
295
|
if (model.tags?.includes("skops")) {
|
|
296
|
-
const skopsmodelFile = model.config?.sklearn?.
|
|
296
|
+
const skopsmodelFile = model.config?.sklearn?.model?.file;
|
|
297
297
|
const skopssaveFormat = model.config?.sklearn?.model_format;
|
|
298
298
|
if (!skopsmodelFile) {
|
|
299
299
|
return [`# ⚠️ Model filename not specified in config.json`];
|
|
@@ -372,7 +372,7 @@ const speechBrainMethod = (speechbrainInterface: string) => {
|
|
|
372
372
|
};
|
|
373
373
|
|
|
374
374
|
export const speechbrain = (model: ModelData): string[] => {
|
|
375
|
-
const speechbrainInterface = model.config?.speechbrain?.
|
|
375
|
+
const speechbrainInterface = model.config?.speechbrain?.speechbrain_interface;
|
|
376
376
|
if (speechbrainInterface === undefined) {
|
|
377
377
|
return [`# interface not specified in config.json`];
|
|
378
378
|
}
|
|
@@ -465,7 +465,7 @@ const peftTask = (peftTaskType?: string) => {
|
|
|
465
465
|
};
|
|
466
466
|
|
|
467
467
|
export const peft = (model: ModelData): string[] => {
|
|
468
|
-
const {
|
|
468
|
+
const { base_model_name_or_path: peftBaseModel, task_type: peftTaskType } = model.config?.peft ?? {};
|
|
469
469
|
const pefttask = peftTask(peftTaskType);
|
|
470
470
|
if (!pefttask) {
|
|
471
471
|
return [`Task type is invalid.`];
|
|
@@ -548,4 +548,42 @@ export const pythae = (model: ModelData): string[] => [
|
|
|
548
548
|
model = AutoModel.load_from_hf_hub("${model.id}")`,
|
|
549
549
|
];
|
|
550
550
|
|
|
551
|
+
const musicgen = (model: ModelData): string[] => [
|
|
552
|
+
`from audiocraft.models import MusicGen
|
|
553
|
+
|
|
554
|
+
model = MusicGen.get_pretrained("${model.id}")
|
|
555
|
+
|
|
556
|
+
descriptions = ['happy rock', 'energetic EDM', 'sad jazz']
|
|
557
|
+
wav = model.generate(descriptions) # generates 3 samples.`,
|
|
558
|
+
];
|
|
559
|
+
|
|
560
|
+
const magnet = (model: ModelData): string[] => [
|
|
561
|
+
`from audiocraft.models import MAGNeT
|
|
562
|
+
|
|
563
|
+
model = MAGNeT.get_pretrained("${model.id}")
|
|
564
|
+
|
|
565
|
+
descriptions = ['disco beat', 'energetic EDM', 'funky groove']
|
|
566
|
+
wav = model.generate(descriptions) # generates 3 samples.`,
|
|
567
|
+
];
|
|
568
|
+
|
|
569
|
+
const audiogen = (model: ModelData): string[] => [
|
|
570
|
+
`from audiocraft.models import AudioGen
|
|
571
|
+
|
|
572
|
+
model = AudioGen.get_pretrained("${model.id}")
|
|
573
|
+
model.set_generation_params(duration=5) # generate 5 seconds.
|
|
574
|
+
descriptions = ['dog barking', 'sirene of an emergency vehicle', 'footsteps in a corridor']
|
|
575
|
+
wav = model.generate(descriptions) # generates 3 samples.`,
|
|
576
|
+
];
|
|
577
|
+
|
|
578
|
+
export const audiocraft = (model: ModelData): string[] => {
|
|
579
|
+
if (model.tags?.includes("musicgen")) {
|
|
580
|
+
return musicgen(model);
|
|
581
|
+
} else if (model.tags?.includes("audiogen")) {
|
|
582
|
+
return audiogen(model);
|
|
583
|
+
} else if (model.tags?.includes("magnet")) {
|
|
584
|
+
return magnet(model);
|
|
585
|
+
} else {
|
|
586
|
+
return [`# Type of model unknown.`];
|
|
587
|
+
}
|
|
588
|
+
};
|
|
551
589
|
//#endregion
|
package/src/model-libraries.ts
CHANGED
|
@@ -88,6 +88,13 @@ export const MODEL_LIBRARIES_UI_ELEMENTS = {
|
|
|
88
88
|
term: { path: "pytorch_model.bin" },
|
|
89
89
|
},
|
|
90
90
|
},
|
|
91
|
+
audiocraft: {
|
|
92
|
+
prettyLabel: "Audiocraft",
|
|
93
|
+
repoName: "audiocraft",
|
|
94
|
+
repoUrl: "https://github.com/facebookresearch/audiocraft",
|
|
95
|
+
snippets: snippets.audiocraft,
|
|
96
|
+
filter: false,
|
|
97
|
+
},
|
|
91
98
|
bertopic: {
|
|
92
99
|
prettyLabel: "BERTopic",
|
|
93
100
|
repoName: "BERTopic",
|
package/src/pipelines.ts
CHANGED
package/src/tasks/index.ts
CHANGED
|
@@ -36,6 +36,64 @@ import zeroShotClassification from "./zero-shot-classification/data";
|
|
|
36
36
|
import zeroShotImageClassification from "./zero-shot-image-classification/data";
|
|
37
37
|
import zeroShotObjectDetection from "./zero-shot-object-detection/data";
|
|
38
38
|
|
|
39
|
+
export type * from "./audio-classification/inference";
|
|
40
|
+
export type * from "./automatic-speech-recognition/inference";
|
|
41
|
+
export type * from "./document-question-answering/inference";
|
|
42
|
+
export type * from "./feature-extraction/inference";
|
|
43
|
+
export type * from "./fill-mask/inference";
|
|
44
|
+
export type {
|
|
45
|
+
ImageClassificationInput,
|
|
46
|
+
ImageClassificationOutput,
|
|
47
|
+
ImageClassificationOutputElement,
|
|
48
|
+
ImageClassificationParameters,
|
|
49
|
+
} from "./image-classification/inference";
|
|
50
|
+
export type * from "./image-to-image/inference";
|
|
51
|
+
export type { ImageToTextInput, ImageToTextOutput, ImageToTextParameters } from "./image-to-text/inference";
|
|
52
|
+
export type * from "./image-segmentation/inference";
|
|
53
|
+
export type * from "./object-detection/inference";
|
|
54
|
+
export type * from "./depth-estimation/inference";
|
|
55
|
+
export type * from "./question-answering/inference";
|
|
56
|
+
export type * from "./sentence-similarity/inference";
|
|
57
|
+
export type * from "./summarization/inference";
|
|
58
|
+
export type * from "./table-question-answering/inference";
|
|
59
|
+
export type { TextToImageInput, TextToImageOutput, TextToImageParameters } from "./text-to-image/inference";
|
|
60
|
+
export type { TextToAudioParameters, TextToSpeechInput, TextToSpeechOutput } from "./text-to-speech/inference";
|
|
61
|
+
export type * from "./token-classification/inference";
|
|
62
|
+
export type {
|
|
63
|
+
Text2TextGenerationParameters,
|
|
64
|
+
Text2TextGenerationTruncationStrategy,
|
|
65
|
+
TranslationInput,
|
|
66
|
+
TranslationOutput,
|
|
67
|
+
} from "./translation/inference";
|
|
68
|
+
export type {
|
|
69
|
+
ClassificationOutputTransform,
|
|
70
|
+
TextClassificationInput,
|
|
71
|
+
TextClassificationOutput,
|
|
72
|
+
TextClassificationOutputElement,
|
|
73
|
+
TextClassificationParameters,
|
|
74
|
+
} from "./text-classification/inference";
|
|
75
|
+
export type {
|
|
76
|
+
FinishReason,
|
|
77
|
+
PrefillToken,
|
|
78
|
+
TextGenerationInput,
|
|
79
|
+
TextGenerationOutput,
|
|
80
|
+
TextGenerationOutputDetails,
|
|
81
|
+
TextGenerationParameters,
|
|
82
|
+
TextGenerationSequenceDetails,
|
|
83
|
+
Token,
|
|
84
|
+
} from "./text-generation/inference";
|
|
85
|
+
export type * from "./video-classification/inference";
|
|
86
|
+
export type * from "./visual-question-answering/inference";
|
|
87
|
+
export type * from "./zero-shot-classification/inference";
|
|
88
|
+
export type * from "./zero-shot-image-classification/inference";
|
|
89
|
+
export type {
|
|
90
|
+
BoundingBox,
|
|
91
|
+
ZeroShotObjectDetectionInput,
|
|
92
|
+
ZeroShotObjectDetectionInputData,
|
|
93
|
+
ZeroShotObjectDetectionOutput,
|
|
94
|
+
ZeroShotObjectDetectionOutputElement,
|
|
95
|
+
} from "./zero-shot-object-detection/inference";
|
|
96
|
+
|
|
39
97
|
import type { ModelLibraryKey } from "../model-libraries";
|
|
40
98
|
|
|
41
99
|
/**
|
|
@@ -45,15 +45,12 @@ export interface Text2TextGenerationParameters {
|
|
|
45
45
|
export type Text2TextGenerationTruncationStrategy = "do_not_truncate" | "longest_first" | "only_first" | "only_second";
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Outputs for Summarization
|
|
49
|
-
*
|
|
50
|
-
* Outputs of inference for the Text2text Generation task
|
|
48
|
+
* Outputs of inference for the Summarization task
|
|
51
49
|
*/
|
|
52
50
|
export interface SummarizationOutput {
|
|
53
|
-
generatedText: unknown;
|
|
54
51
|
/**
|
|
55
|
-
* The
|
|
52
|
+
* The summarized text.
|
|
56
53
|
*/
|
|
57
|
-
|
|
54
|
+
summary_text: string;
|
|
58
55
|
[property: string]: unknown;
|
|
59
56
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$ref": "/inference/schemas/text2text-generation/output.json",
|
|
3
2
|
"$id": "/inference/schemas/summarization/output.json",
|
|
4
3
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
|
4
|
+
"description": "Outputs of inference for the Summarization task",
|
|
5
5
|
"title": "SummarizationOutput",
|
|
6
|
-
"
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"summary_text": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The summarized text."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"required": ["summary_text"]
|
|
7
14
|
}
|
|
@@ -45,15 +45,12 @@ export interface Text2TextGenerationParameters {
|
|
|
45
45
|
export type Text2TextGenerationTruncationStrategy = "do_not_truncate" | "longest_first" | "only_first" | "only_second";
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* Outputs for Translation
|
|
49
|
-
*
|
|
50
|
-
* Outputs of inference for the Text2text Generation task
|
|
48
|
+
* Outputs of inference for the Translation task
|
|
51
49
|
*/
|
|
52
50
|
export interface TranslationOutput {
|
|
53
|
-
generatedText: unknown;
|
|
54
51
|
/**
|
|
55
|
-
* The
|
|
52
|
+
* The translated text.
|
|
56
53
|
*/
|
|
57
|
-
|
|
54
|
+
translation_text: string;
|
|
58
55
|
[property: string]: unknown;
|
|
59
56
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$ref": "/inference/schemas/text2text-generation/output.json",
|
|
3
2
|
"$id": "/inference/schemas/translation/output.json",
|
|
4
3
|
"$schema": "http://json-schema.org/draft-06/schema#",
|
|
4
|
+
"description": "Outputs of inference for the Translation task",
|
|
5
5
|
"title": "TranslationOutput",
|
|
6
|
-
"
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"translation_text": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The translated text."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"required": ["translation_text"]
|
|
7
14
|
}
|
package/src/widget-example.ts
CHANGED
|
@@ -51,6 +51,15 @@ export interface WidgetExampleBase<TOutput> {
|
|
|
51
51
|
output?: TOutput;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
export interface ChatMessage {
|
|
55
|
+
role: "user" | "assistant" | "system";
|
|
56
|
+
content: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface WidgetExampleChatInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
|
|
60
|
+
messages: ChatMessage[];
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
export interface WidgetExampleTextInput<TOutput = WidgetExampleOutput> extends WidgetExampleBase<TOutput> {
|
|
55
64
|
text: string;
|
|
56
65
|
}
|
|
@@ -101,6 +110,7 @@ export interface WidgetExampleSentenceSimilarityInput<TOutput = WidgetExampleOut
|
|
|
101
110
|
//#endregion
|
|
102
111
|
|
|
103
112
|
export type WidgetExample<TOutput = WidgetExampleOutput> =
|
|
113
|
+
| WidgetExampleChatInput<TOutput>
|
|
104
114
|
| WidgetExampleTextInput<TOutput>
|
|
105
115
|
| WidgetExampleTextAndContextInput<TOutput>
|
|
106
116
|
| WidgetExampleTextAndTableInput<TOutput>
|