@huggingface/tasks 0.12.22 → 0.12.24
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 +503 -132
- package/dist/index.js +503 -132
- package/dist/src/hardware.d.ts +20 -0
- package/dist/src/hardware.d.ts.map +1 -1
- package/dist/src/model-libraries-snippets.d.ts +1 -0
- package/dist/src/model-libraries-snippets.d.ts.map +1 -1
- package/dist/src/model-libraries.d.ts +9 -2
- package/dist/src/model-libraries.d.ts.map +1 -1
- package/dist/src/snippets/common.d.ts +20 -0
- package/dist/src/snippets/common.d.ts.map +1 -0
- package/dist/src/snippets/curl.d.ts +15 -8
- package/dist/src/snippets/curl.d.ts.map +1 -1
- package/dist/src/snippets/js.d.ts +17 -10
- package/dist/src/snippets/js.d.ts.map +1 -1
- package/dist/src/snippets/python.d.ts +20 -13
- package/dist/src/snippets/python.d.ts.map +1 -1
- package/dist/src/snippets/types.d.ts +4 -0
- package/dist/src/snippets/types.d.ts.map +1 -1
- package/dist/src/tasks/depth-estimation/data.d.ts.map +1 -1
- package/dist/src/tasks/image-segmentation/data.d.ts.map +1 -1
- package/dist/src/tasks/image-text-to-text/data.d.ts.map +1 -1
- package/dist/src/tasks/object-detection/data.d.ts.map +1 -1
- package/dist/src/tasks/text-to-speech/data.d.ts.map +1 -1
- package/dist/src/tasks/token-classification/inference.d.ts +8 -5
- package/dist/src/tasks/token-classification/inference.d.ts.map +1 -1
- package/dist/src/tasks/video-text-to-text/data.d.ts.map +1 -1
- package/dist/src/tasks/visual-question-answering/inference.d.ts +0 -1
- package/dist/src/tasks/visual-question-answering/inference.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hardware.ts +20 -0
- package/src/model-libraries-snippets.ts +28 -3
- package/src/model-libraries.ts +8 -1
- package/src/snippets/common.ts +63 -0
- package/src/snippets/curl.ts +71 -26
- package/src/snippets/js.ts +165 -40
- package/src/snippets/python.ts +186 -48
- package/src/snippets/types.ts +5 -0
- package/src/tasks/depth-estimation/data.ts +15 -7
- package/src/tasks/image-segmentation/about.md +1 -1
- package/src/tasks/image-segmentation/data.ts +10 -9
- package/src/tasks/image-text-to-text/data.ts +17 -9
- package/src/tasks/keypoint-detection/data.ts +1 -1
- package/src/tasks/object-detection/data.ts +5 -4
- package/src/tasks/text-generation/data.ts +7 -7
- package/src/tasks/text-to-image/data.ts +2 -2
- package/src/tasks/text-to-speech/data.ts +5 -1
- package/src/tasks/text-to-video/data.ts +10 -10
- package/src/tasks/token-classification/inference.ts +8 -5
- package/src/tasks/token-classification/spec/output.json +6 -2
- package/src/tasks/video-text-to-text/data.ts +8 -0
- package/src/tasks/visual-question-answering/inference.ts +0 -1
- package/src/tasks/visual-question-answering/spec/output.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2224,20 +2224,24 @@ var taskData11 = {
|
|
|
2224
2224
|
id: "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
|
2225
2225
|
},
|
|
2226
2226
|
{
|
|
2227
|
-
description: "Cutting-edge
|
|
2228
|
-
id: "
|
|
2227
|
+
description: "Cutting-edge vision language models.",
|
|
2228
|
+
id: "allenai/Molmo-7B-D-0924"
|
|
2229
2229
|
},
|
|
2230
2230
|
{
|
|
2231
2231
|
description: "Small yet powerful model.",
|
|
2232
2232
|
id: "vikhyatk/moondream2"
|
|
2233
2233
|
},
|
|
2234
2234
|
{
|
|
2235
|
-
description: "Strong image-text-to-text model
|
|
2236
|
-
id: "
|
|
2235
|
+
description: "Strong image-text-to-text model.",
|
|
2236
|
+
id: "Qwen/Qwen2-VL-7B-Instruct"
|
|
2237
2237
|
},
|
|
2238
2238
|
{
|
|
2239
2239
|
description: "Strong image-text-to-text model.",
|
|
2240
|
-
id: "
|
|
2240
|
+
id: "mistralai/Pixtral-12B-2409"
|
|
2241
|
+
},
|
|
2242
|
+
{
|
|
2243
|
+
description: "Strong image-text-to-text model focused on documents.",
|
|
2244
|
+
id: "stepfun-ai/GOT-OCR2_0"
|
|
2241
2245
|
}
|
|
2242
2246
|
],
|
|
2243
2247
|
spaces: [
|
|
@@ -2251,19 +2255,23 @@ var taskData11 = {
|
|
|
2251
2255
|
},
|
|
2252
2256
|
{
|
|
2253
2257
|
description: "Powerful vision-language model assistant.",
|
|
2254
|
-
id: "
|
|
2258
|
+
id: "akhaliq/Molmo-7B-D-0924"
|
|
2259
|
+
},
|
|
2260
|
+
{
|
|
2261
|
+
description: "An image-text-to-text application focused on documents.",
|
|
2262
|
+
id: "stepfun-ai/GOT_official_online_demo"
|
|
2255
2263
|
},
|
|
2256
2264
|
{
|
|
2257
2265
|
description: "An application to compare outputs of different vision language models.",
|
|
2258
2266
|
id: "merve/compare_VLMs"
|
|
2259
2267
|
},
|
|
2260
2268
|
{
|
|
2261
|
-
description: "An application for
|
|
2262
|
-
id: "
|
|
2269
|
+
description: "An application for chatting with an image-text-to-text model.",
|
|
2270
|
+
id: "GanymedeNil/Qwen2-VL-7B"
|
|
2263
2271
|
}
|
|
2264
2272
|
],
|
|
2265
2273
|
summary: "Image-text-to-text models take in an image and text prompt and output text. These models are also called vision-language models, or VLMs. The difference from image-to-text models is that these models take an additional text input, not restricting the model to certain use cases like image captioning, and may also be trained to accept a conversation as input.",
|
|
2266
|
-
widgetModels: ["
|
|
2274
|
+
widgetModels: ["meta-llama/Llama-3.2-11B-Vision-Instruct"],
|
|
2267
2275
|
youtubeId: "IoGaGfU1CIg"
|
|
2268
2276
|
};
|
|
2269
2277
|
var data_default11 = taskData11;
|
|
@@ -2311,23 +2319,23 @@ var taskData12 = {
|
|
|
2311
2319
|
models: [
|
|
2312
2320
|
{
|
|
2313
2321
|
// TO DO: write description
|
|
2314
|
-
description: "Solid
|
|
2315
|
-
id: "
|
|
2322
|
+
description: "Solid semantic segmentation model trained on ADE20k.",
|
|
2323
|
+
id: "openmmlab/upernet-convnext-small"
|
|
2316
2324
|
},
|
|
2317
2325
|
{
|
|
2318
2326
|
description: "Background removal model.",
|
|
2319
2327
|
id: "briaai/RMBG-1.4"
|
|
2320
2328
|
},
|
|
2321
|
-
{
|
|
2322
|
-
description: "Semantic segmentation model trained on ADE20k benchmark dataset with 512x512 resolution.",
|
|
2323
|
-
id: "nvidia/segformer-b0-finetuned-ade-512-512"
|
|
2324
|
-
},
|
|
2325
2329
|
{
|
|
2326
2330
|
description: "A multipurpose image segmentation model for high resolution images.",
|
|
2327
2331
|
id: "ZhengPeng7/BiRefNet"
|
|
2328
2332
|
},
|
|
2329
2333
|
{
|
|
2330
|
-
description: "
|
|
2334
|
+
description: "Powerful human-centric image segmentation model.",
|
|
2335
|
+
id: "facebook/sapiens-seg-1b"
|
|
2336
|
+
},
|
|
2337
|
+
{
|
|
2338
|
+
description: "Panoptic segmentation model trained on the COCO (common objects) dataset.",
|
|
2331
2339
|
id: "facebook/mask2former-swin-large-coco-panoptic"
|
|
2332
2340
|
}
|
|
2333
2341
|
],
|
|
@@ -2341,8 +2349,8 @@ var taskData12 = {
|
|
|
2341
2349
|
id: "jbrinkma/segment-anything"
|
|
2342
2350
|
},
|
|
2343
2351
|
{
|
|
2344
|
-
description: "A
|
|
2345
|
-
id: "
|
|
2352
|
+
description: "A human-centric segmentation model.",
|
|
2353
|
+
id: "facebook/sapiens-pose"
|
|
2346
2354
|
},
|
|
2347
2355
|
{
|
|
2348
2356
|
description: "An instance segmentation application to predict neuronal cell types from microscopy images.",
|
|
@@ -2457,15 +2465,15 @@ var taskData14 = {
|
|
|
2457
2465
|
],
|
|
2458
2466
|
models: [
|
|
2459
2467
|
{
|
|
2460
|
-
description: "Solid object detection model trained on the
|
|
2468
|
+
description: "Solid object detection model pre-trained on the COCO 2017 dataset.",
|
|
2461
2469
|
id: "facebook/detr-resnet-50"
|
|
2462
2470
|
},
|
|
2463
2471
|
{
|
|
2464
|
-
description: "
|
|
2465
|
-
id: "
|
|
2472
|
+
description: "Real-time and accurate object detection model.",
|
|
2473
|
+
id: "jameslahm/yolov10x"
|
|
2466
2474
|
},
|
|
2467
2475
|
{
|
|
2468
|
-
description: "Fast and accurate object detection model trained on COCO
|
|
2476
|
+
description: "Fast and accurate object detection model trained on COCO and Object365 datasets.",
|
|
2469
2477
|
id: "PekingU/rtdetr_r18vd_coco_o365"
|
|
2470
2478
|
}
|
|
2471
2479
|
],
|
|
@@ -2531,11 +2539,15 @@ var taskData15 = {
|
|
|
2531
2539
|
},
|
|
2532
2540
|
{
|
|
2533
2541
|
description: "A strong monocular depth estimation model.",
|
|
2534
|
-
id: "
|
|
2542
|
+
id: "jingheya/lotus-depth-g-v1-0"
|
|
2535
2543
|
},
|
|
2536
2544
|
{
|
|
2537
|
-
description: "A
|
|
2538
|
-
id: "
|
|
2545
|
+
description: "A depth estimation model that predicts depth in videos.",
|
|
2546
|
+
id: "tencent/DepthCrafter"
|
|
2547
|
+
},
|
|
2548
|
+
{
|
|
2549
|
+
description: "A robust depth estimation model.",
|
|
2550
|
+
id: "apple/DepthPro"
|
|
2539
2551
|
}
|
|
2540
2552
|
],
|
|
2541
2553
|
spaces: [
|
|
@@ -2544,12 +2556,16 @@ var taskData15 = {
|
|
|
2544
2556
|
id: "radames/dpt-depth-estimation-3d-voxels"
|
|
2545
2557
|
},
|
|
2546
2558
|
{
|
|
2547
|
-
description: "An application
|
|
2548
|
-
id: "depth-
|
|
2559
|
+
description: "An application for bleeding-edge depth estimation.",
|
|
2560
|
+
id: "akhaliq/depth-pro"
|
|
2561
|
+
},
|
|
2562
|
+
{
|
|
2563
|
+
description: "An application on cutting-edge depth estimation in videos.",
|
|
2564
|
+
id: "tencent/DepthCrafter"
|
|
2549
2565
|
},
|
|
2550
2566
|
{
|
|
2551
|
-
description: "
|
|
2552
|
-
id: "
|
|
2567
|
+
description: "A human-centric depth estimation application.",
|
|
2568
|
+
id: "facebook/sapiens-depth"
|
|
2553
2569
|
}
|
|
2554
2570
|
],
|
|
2555
2571
|
summary: "Depth estimation is the task of predicting depth of the objects present in an image.",
|
|
@@ -3127,8 +3143,8 @@ var taskData24 = {
|
|
|
3127
3143
|
id: "jbilcke-hf/ai-comic-factory"
|
|
3128
3144
|
},
|
|
3129
3145
|
{
|
|
3130
|
-
description: "
|
|
3131
|
-
id: "
|
|
3146
|
+
description: "An application to match multiple custom image generation models.",
|
|
3147
|
+
id: "multimodalart/flux-lora-lab"
|
|
3132
3148
|
},
|
|
3133
3149
|
{
|
|
3134
3150
|
description: "A powerful yet very fast image generation application.",
|
|
@@ -3211,9 +3227,13 @@ var taskData25 = {
|
|
|
3211
3227
|
id: "suno/bark"
|
|
3212
3228
|
},
|
|
3213
3229
|
{
|
|
3214
|
-
description: "XTTS
|
|
3230
|
+
description: "An application on XTTS, a voice generation model that lets you clone voices into different languages.",
|
|
3215
3231
|
id: "coqui/xtts"
|
|
3216
3232
|
},
|
|
3233
|
+
{
|
|
3234
|
+
description: "An application that generates speech in different styles in English and Chinese.",
|
|
3235
|
+
id: "mrfakename/E2-F5-TTS"
|
|
3236
|
+
},
|
|
3217
3237
|
{
|
|
3218
3238
|
description: "An application that synthesizes speech for diverse speaker prompts.",
|
|
3219
3239
|
id: "parler-tts/parler_tts_mini"
|
|
@@ -3532,10 +3552,6 @@ var taskData29 = {
|
|
|
3532
3552
|
description: "A text-generation model trained to follow instructions.",
|
|
3533
3553
|
id: "google/gemma-2-2b-it"
|
|
3534
3554
|
},
|
|
3535
|
-
{
|
|
3536
|
-
description: "A code generation model that can generate code in 80+ languages.",
|
|
3537
|
-
id: "bigcode/starcoder"
|
|
3538
|
-
},
|
|
3539
3555
|
{
|
|
3540
3556
|
description: "Very powerful text generation model trained to follow instructions.",
|
|
3541
3557
|
id: "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
|
@@ -3549,12 +3565,12 @@ var taskData29 = {
|
|
|
3549
3565
|
id: "AI-MO/NuminaMath-7B-TIR"
|
|
3550
3566
|
},
|
|
3551
3567
|
{
|
|
3552
|
-
description: "Strong
|
|
3553
|
-
id: "
|
|
3568
|
+
description: "Strong text generation model to follow instructions.",
|
|
3569
|
+
id: "Qwen/Qwen2.5-7B-Instruct"
|
|
3554
3570
|
},
|
|
3555
3571
|
{
|
|
3556
3572
|
description: "Very strong open-source large language model.",
|
|
3557
|
-
id: "
|
|
3573
|
+
id: "nvidia/Llama-3.1-Nemotron-70B-Instruct"
|
|
3558
3574
|
}
|
|
3559
3575
|
],
|
|
3560
3576
|
spaces: [
|
|
@@ -3562,6 +3578,10 @@ var taskData29 = {
|
|
|
3562
3578
|
description: "A leaderboard to compare different open-source text generation models based on various benchmarks.",
|
|
3563
3579
|
id: "open-llm-leaderboard/open_llm_leaderboard"
|
|
3564
3580
|
},
|
|
3581
|
+
{
|
|
3582
|
+
description: "A leaderboard for comparing chain-of-thought performance of models.",
|
|
3583
|
+
id: "logikon/open_cot_leaderboard"
|
|
3584
|
+
},
|
|
3565
3585
|
{
|
|
3566
3586
|
description: "An text generation based application based on a very powerful LLaMA2 model.",
|
|
3567
3587
|
id: "ysharma/Explore_llamav2_with_TGI"
|
|
@@ -3648,30 +3668,30 @@ var taskData30 = {
|
|
|
3648
3668
|
],
|
|
3649
3669
|
models: [
|
|
3650
3670
|
{
|
|
3651
|
-
description: "A strong model for video generation.",
|
|
3652
|
-
id: "
|
|
3671
|
+
description: "A strong model for consistent video generation.",
|
|
3672
|
+
id: "rain1011/pyramid-flow-sd3"
|
|
3653
3673
|
},
|
|
3654
3674
|
{
|
|
3655
3675
|
description: "A robust model for text-to-video generation.",
|
|
3656
|
-
id: "
|
|
3676
|
+
id: "VideoCrafter/VideoCrafter2"
|
|
3657
3677
|
},
|
|
3658
3678
|
{
|
|
3659
|
-
description: "A text-to-video generation model
|
|
3660
|
-
id: "
|
|
3679
|
+
description: "A cutting-edge text-to-video generation model.",
|
|
3680
|
+
id: "TIGER-Lab/T2V-Turbo-V2"
|
|
3661
3681
|
}
|
|
3662
3682
|
],
|
|
3663
3683
|
spaces: [
|
|
3664
3684
|
{
|
|
3665
3685
|
description: "An application that generates video from text.",
|
|
3666
|
-
id: "
|
|
3686
|
+
id: "VideoCrafter/VideoCrafter"
|
|
3667
3687
|
},
|
|
3668
3688
|
{
|
|
3669
|
-
description: "
|
|
3670
|
-
id: "
|
|
3689
|
+
description: "Consistent video generation application.",
|
|
3690
|
+
id: "TIGER-Lab/T2V-Turbo-V2"
|
|
3671
3691
|
},
|
|
3672
3692
|
{
|
|
3673
|
-
description: "
|
|
3674
|
-
id: "
|
|
3693
|
+
description: "A cutting edge video generation application.",
|
|
3694
|
+
id: "Pyramid-Flow/pyramid-flow"
|
|
3675
3695
|
}
|
|
3676
3696
|
],
|
|
3677
3697
|
summary: "Text-to-video models can be used in any application that requires generating consistent sequence of images from text. ",
|
|
@@ -4288,7 +4308,7 @@ var taskData39 = {
|
|
|
4288
4308
|
},
|
|
4289
4309
|
{
|
|
4290
4310
|
description: "Strong keypoint detection model used to detect human pose.",
|
|
4291
|
-
id: "
|
|
4311
|
+
id: "facebook/sapiens-pose-1b"
|
|
4292
4312
|
}
|
|
4293
4313
|
],
|
|
4294
4314
|
spaces: [
|
|
@@ -4317,6 +4337,10 @@ var taskData40 = {
|
|
|
4317
4337
|
{
|
|
4318
4338
|
description: "A dataset of instructions and question-answer pairs about videos.",
|
|
4319
4339
|
id: "lmms-lab/VideoChatGPT"
|
|
4340
|
+
},
|
|
4341
|
+
{
|
|
4342
|
+
description: "Large video understanding dataset.",
|
|
4343
|
+
id: "HuggingFaceFV/finevideo"
|
|
4320
4344
|
}
|
|
4321
4345
|
],
|
|
4322
4346
|
demo: {
|
|
@@ -4354,6 +4378,10 @@ var taskData40 = {
|
|
|
4354
4378
|
{
|
|
4355
4379
|
description: "An application to chat with a video-text-to-text model.",
|
|
4356
4380
|
id: "llava-hf/video-llava"
|
|
4381
|
+
},
|
|
4382
|
+
{
|
|
4383
|
+
description: "A leaderboard for various video-text-to-text models.",
|
|
4384
|
+
id: "opencompass/openvlm_video_leaderboard"
|
|
4357
4385
|
}
|
|
4358
4386
|
],
|
|
4359
4387
|
summary: "Video-text-to-text models take in a video and a text prompt and output text. These models are also called video-language models.",
|
|
@@ -5118,12 +5146,30 @@ with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
|
|
5118
5146
|
var sampleFactory = (model) => [
|
|
5119
5147
|
`python -m sample_factory.huggingface.load_from_hub -r ${model.id} -d ./train_dir`
|
|
5120
5148
|
];
|
|
5149
|
+
function get_widget_examples_from_st_model(model) {
|
|
5150
|
+
const widgetExample = model.widgetData?.[0];
|
|
5151
|
+
if (widgetExample) {
|
|
5152
|
+
return [widgetExample.source_sentence, ...widgetExample.sentences];
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5121
5155
|
var sentenceTransformers = (model) => {
|
|
5122
5156
|
const remote_code_snippet = model.tags.includes(TAG_CUSTOM_CODE) ? ", trust_remote_code=True" : "";
|
|
5157
|
+
const exampleSentences = get_widget_examples_from_st_model(model) ?? [
|
|
5158
|
+
"The weather is lovely today.",
|
|
5159
|
+
"It's so sunny outside!",
|
|
5160
|
+
"He drove to the stadium."
|
|
5161
|
+
];
|
|
5123
5162
|
return [
|
|
5124
5163
|
`from sentence_transformers import SentenceTransformer
|
|
5125
5164
|
|
|
5126
|
-
model = SentenceTransformer("${model.id}"${remote_code_snippet})
|
|
5165
|
+
model = SentenceTransformer("${model.id}"${remote_code_snippet})
|
|
5166
|
+
|
|
5167
|
+
sentences = ${JSON.stringify(exampleSentences, null, 4)}
|
|
5168
|
+
embeddings = model.encode(sentences)
|
|
5169
|
+
|
|
5170
|
+
similarities = model.similarity(embeddings, embeddings)
|
|
5171
|
+
print(similarities.shape)
|
|
5172
|
+
# [${exampleSentences.length}, ${exampleSentences.length}]`
|
|
5127
5173
|
];
|
|
5128
5174
|
};
|
|
5129
5175
|
var setfit = (model) => [
|
|
@@ -5225,7 +5271,7 @@ var transformersJS = (model) => {
|
|
|
5225
5271
|
if (!model.pipeline_tag) {
|
|
5226
5272
|
return [`// \u26A0\uFE0F Unknown pipeline tag`];
|
|
5227
5273
|
}
|
|
5228
|
-
const libName = "@
|
|
5274
|
+
const libName = "@huggingface/transformers";
|
|
5229
5275
|
return [
|
|
5230
5276
|
`// npm i ${libName}
|
|
5231
5277
|
import { pipeline } from '${libName}';
|
|
@@ -5369,6 +5415,11 @@ var nemo = (model) => {
|
|
|
5369
5415
|
}
|
|
5370
5416
|
return command ?? [`# tag did not correspond to a valid NeMo domain.`];
|
|
5371
5417
|
};
|
|
5418
|
+
var pxia = (model) => [
|
|
5419
|
+
`from pxia import AutoModel
|
|
5420
|
+
|
|
5421
|
+
model = AutoModel.from_pretrained("${model.id}")`
|
|
5422
|
+
];
|
|
5372
5423
|
var pythae = (model) => [
|
|
5373
5424
|
`from pythae.models import AutoModel
|
|
5374
5425
|
|
|
@@ -5854,6 +5905,13 @@ var MODEL_LIBRARIES_UI_ELEMENTS = {
|
|
|
5854
5905
|
filter: true,
|
|
5855
5906
|
countDownloads: `path:"adapter_config.json"`
|
|
5856
5907
|
},
|
|
5908
|
+
pxia: {
|
|
5909
|
+
prettyLabel: "pxia",
|
|
5910
|
+
repoName: "pxia",
|
|
5911
|
+
repoUrl: "https://github.com/not-lain/pxia",
|
|
5912
|
+
snippets: pxia,
|
|
5913
|
+
filter: false
|
|
5914
|
+
},
|
|
5857
5915
|
"pyannote-audio": {
|
|
5858
5916
|
prettyLabel: "pyannote.audio",
|
|
5859
5917
|
repoName: "pyannote-audio",
|
|
@@ -6086,7 +6144,7 @@ var MODEL_LIBRARIES_UI_ELEMENTS = {
|
|
|
6086
6144
|
"transformers.js": {
|
|
6087
6145
|
prettyLabel: "Transformers.js",
|
|
6088
6146
|
repoName: "transformers.js",
|
|
6089
|
-
repoUrl: "https://github.com/
|
|
6147
|
+
repoUrl: "https://github.com/huggingface/transformers.js",
|
|
6090
6148
|
docsUrl: "https://huggingface.co/docs/hub/transformers-js",
|
|
6091
6149
|
snippets: transformersJS,
|
|
6092
6150
|
filter: true
|
|
@@ -6275,30 +6333,91 @@ __export(curl_exports, {
|
|
|
6275
6333
|
snippetTextGeneration: () => snippetTextGeneration,
|
|
6276
6334
|
snippetZeroShotClassification: () => snippetZeroShotClassification
|
|
6277
6335
|
});
|
|
6278
|
-
|
|
6336
|
+
|
|
6337
|
+
// src/snippets/common.ts
|
|
6338
|
+
function stringifyMessages(messages, opts) {
|
|
6339
|
+
const keyRole = opts.attributeKeyQuotes ? `"role"` : "role";
|
|
6340
|
+
const keyContent = opts.attributeKeyQuotes ? `"role"` : "role";
|
|
6341
|
+
const messagesStringified = messages.map(({ role, content }) => {
|
|
6342
|
+
if (typeof content === "string") {
|
|
6343
|
+
content = JSON.stringify(content).slice(1, -1);
|
|
6344
|
+
if (opts.customContentEscaper) {
|
|
6345
|
+
content = opts.customContentEscaper(content);
|
|
6346
|
+
}
|
|
6347
|
+
return `{ ${keyRole}: "${role}", ${keyContent}: "${content}" }`;
|
|
6348
|
+
} else {
|
|
6349
|
+
2;
|
|
6350
|
+
content = content.map(({ image_url, text, type }) => ({
|
|
6351
|
+
type,
|
|
6352
|
+
image_url,
|
|
6353
|
+
...text ? { text: JSON.stringify(text).slice(1, -1) } : void 0
|
|
6354
|
+
}));
|
|
6355
|
+
content = JSON.stringify(content).slice(1, -1);
|
|
6356
|
+
if (opts.customContentEscaper) {
|
|
6357
|
+
content = opts.customContentEscaper(content);
|
|
6358
|
+
}
|
|
6359
|
+
return `{ ${keyRole}: "${role}", ${keyContent}: ${content} }`;
|
|
6360
|
+
}
|
|
6361
|
+
});
|
|
6362
|
+
return opts.start + messagesStringified.join(opts.sep) + opts.end;
|
|
6363
|
+
}
|
|
6364
|
+
function stringifyGenerationConfig(config, opts) {
|
|
6365
|
+
const quote = opts.attributeKeyQuotes ? `"` : "";
|
|
6366
|
+
return opts.start + Object.entries(config).map(([key, val]) => `${quote}${key}${quote}${opts.attributeValueConnector}${val}`).join(opts.sep) + opts.end;
|
|
6367
|
+
}
|
|
6368
|
+
|
|
6369
|
+
// src/snippets/curl.ts
|
|
6370
|
+
var snippetBasic = (model, accessToken) => ({
|
|
6371
|
+
content: `curl https://api-inference.huggingface.co/models/${model.id} \\
|
|
6279
6372
|
-X POST \\
|
|
6280
6373
|
-d '{"inputs": ${getModelInputSnippet(model, true)}}' \\
|
|
6281
6374
|
-H 'Content-Type: application/json' \\
|
|
6282
|
-
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
|
|
6283
|
-
|
|
6375
|
+
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`
|
|
6376
|
+
});
|
|
6377
|
+
var snippetTextGeneration = (model, accessToken, opts) => {
|
|
6284
6378
|
if (model.tags.includes("conversational")) {
|
|
6285
|
-
|
|
6379
|
+
const streaming = opts?.streaming ?? true;
|
|
6380
|
+
const messages = opts?.messages ?? [
|
|
6381
|
+
{ role: "user", content: "What is the capital of France?" }
|
|
6382
|
+
];
|
|
6383
|
+
const config = {
|
|
6384
|
+
...opts?.temperature ? { temperature: opts.temperature } : void 0,
|
|
6385
|
+
max_tokens: opts?.max_tokens ?? 500,
|
|
6386
|
+
...opts?.top_p ? { top_p: opts.top_p } : void 0
|
|
6387
|
+
};
|
|
6388
|
+
return {
|
|
6389
|
+
content: `curl 'https://api-inference.huggingface.co/models/${model.id}/v1/chat/completions' \\
|
|
6286
6390
|
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}" \\
|
|
6287
6391
|
-H 'Content-Type: application/json' \\
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6392
|
+
--data '{
|
|
6393
|
+
"model": "${model.id}",
|
|
6394
|
+
"messages": ${stringifyMessages(messages, {
|
|
6395
|
+
sep: ",\n ",
|
|
6396
|
+
start: `[
|
|
6397
|
+
`,
|
|
6398
|
+
end: `
|
|
6399
|
+
]`,
|
|
6400
|
+
attributeKeyQuotes: true,
|
|
6401
|
+
customContentEscaper: (str) => str.replace(/'/g, "'\\''")
|
|
6402
|
+
})},
|
|
6403
|
+
${stringifyGenerationConfig(config, {
|
|
6404
|
+
sep: ",\n ",
|
|
6405
|
+
start: "",
|
|
6406
|
+
end: "",
|
|
6407
|
+
attributeKeyQuotes: true,
|
|
6408
|
+
attributeValueConnector: ": "
|
|
6409
|
+
})},
|
|
6410
|
+
"stream": ${!!streaming}
|
|
6411
|
+
}'`
|
|
6412
|
+
};
|
|
6295
6413
|
} else {
|
|
6296
6414
|
return snippetBasic(model, accessToken);
|
|
6297
6415
|
}
|
|
6298
6416
|
};
|
|
6299
6417
|
var snippetImageTextToTextGeneration = (model, accessToken) => {
|
|
6300
6418
|
if (model.tags.includes("conversational")) {
|
|
6301
|
-
return
|
|
6419
|
+
return {
|
|
6420
|
+
content: `curl 'https://api-inference.huggingface.co/models/${model.id}/v1/chat/completions' \\
|
|
6302
6421
|
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}" \\
|
|
6303
6422
|
-H 'Content-Type: application/json' \\
|
|
6304
6423
|
-d '{
|
|
@@ -6315,20 +6434,25 @@ var snippetImageTextToTextGeneration = (model, accessToken) => {
|
|
|
6315
6434
|
"max_tokens": 500,
|
|
6316
6435
|
"stream": false
|
|
6317
6436
|
}'
|
|
6318
|
-
|
|
6437
|
+
`
|
|
6438
|
+
};
|
|
6319
6439
|
} else {
|
|
6320
6440
|
return snippetBasic(model, accessToken);
|
|
6321
6441
|
}
|
|
6322
6442
|
};
|
|
6323
|
-
var snippetZeroShotClassification = (model, accessToken) =>
|
|
6443
|
+
var snippetZeroShotClassification = (model, accessToken) => ({
|
|
6444
|
+
content: `curl https://api-inference.huggingface.co/models/${model.id} \\
|
|
6324
6445
|
-X POST \\
|
|
6325
6446
|
-d '{"inputs": ${getModelInputSnippet(model, true)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}' \\
|
|
6326
6447
|
-H 'Content-Type: application/json' \\
|
|
6327
|
-
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
|
|
6328
|
-
|
|
6448
|
+
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`
|
|
6449
|
+
});
|
|
6450
|
+
var snippetFile = (model, accessToken) => ({
|
|
6451
|
+
content: `curl https://api-inference.huggingface.co/models/${model.id} \\
|
|
6329
6452
|
-X POST \\
|
|
6330
6453
|
--data-binary '@${getModelInputSnippet(model, true, true)}' \\
|
|
6331
|
-
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
|
|
6454
|
+
-H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"`
|
|
6455
|
+
});
|
|
6332
6456
|
var curlSnippets = {
|
|
6333
6457
|
// Same order as in js/src/lib/interfaces/Types.ts
|
|
6334
6458
|
"text-classification": snippetBasic,
|
|
@@ -6356,7 +6480,7 @@ var curlSnippets = {
|
|
|
6356
6480
|
"image-segmentation": snippetFile
|
|
6357
6481
|
};
|
|
6358
6482
|
function getCurlInferenceSnippet(model, accessToken) {
|
|
6359
|
-
return model.pipeline_tag && model.pipeline_tag in curlSnippets ? curlSnippets[model.pipeline_tag]?.(model, accessToken) ?? "" : "";
|
|
6483
|
+
return model.pipeline_tag && model.pipeline_tag in curlSnippets ? curlSnippets[model.pipeline_tag]?.(model, accessToken) ?? { content: "" } : { content: "" };
|
|
6360
6484
|
}
|
|
6361
6485
|
function hasCurlInferenceSnippet(model) {
|
|
6362
6486
|
return !!model.pipeline_tag && model.pipeline_tag in curlSnippets;
|
|
@@ -6379,18 +6503,114 @@ __export(python_exports, {
|
|
|
6379
6503
|
snippetZeroShotClassification: () => snippetZeroShotClassification2,
|
|
6380
6504
|
snippetZeroShotImageClassification: () => snippetZeroShotImageClassification
|
|
6381
6505
|
});
|
|
6382
|
-
var snippetConversational = (model, accessToken) =>
|
|
6506
|
+
var snippetConversational = (model, accessToken, opts) => {
|
|
6507
|
+
const streaming = opts?.streaming ?? true;
|
|
6508
|
+
const messages = opts?.messages ?? [
|
|
6509
|
+
{ role: "user", content: "What is the capital of France?" }
|
|
6510
|
+
];
|
|
6511
|
+
const messagesStr = stringifyMessages(messages, {
|
|
6512
|
+
sep: ",\n ",
|
|
6513
|
+
start: `[
|
|
6514
|
+
`,
|
|
6515
|
+
end: `
|
|
6516
|
+
]`,
|
|
6517
|
+
attributeKeyQuotes: true
|
|
6518
|
+
});
|
|
6519
|
+
const config = {
|
|
6520
|
+
...opts?.temperature ? { temperature: opts.temperature } : void 0,
|
|
6521
|
+
max_tokens: opts?.max_tokens ?? 500,
|
|
6522
|
+
...opts?.top_p ? { top_p: opts.top_p } : void 0
|
|
6523
|
+
};
|
|
6524
|
+
const configStr = stringifyGenerationConfig(config, {
|
|
6525
|
+
sep: ",\n ",
|
|
6526
|
+
start: "",
|
|
6527
|
+
end: "",
|
|
6528
|
+
attributeValueConnector: "="
|
|
6529
|
+
});
|
|
6530
|
+
if (streaming) {
|
|
6531
|
+
return [
|
|
6532
|
+
{
|
|
6533
|
+
client: "huggingface_hub",
|
|
6534
|
+
content: `from huggingface_hub import InferenceClient
|
|
6383
6535
|
|
|
6384
6536
|
client = InferenceClient(api_key="${accessToken || "{API_TOKEN}"}")
|
|
6385
6537
|
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6538
|
+
messages = ${messagesStr}
|
|
6539
|
+
|
|
6540
|
+
stream = client.chat.completions.create(
|
|
6541
|
+
model="${model.id}",
|
|
6542
|
+
messages=messages,
|
|
6543
|
+
${configStr},
|
|
6544
|
+
stream=True
|
|
6545
|
+
)
|
|
6546
|
+
|
|
6547
|
+
for chunk in stream:
|
|
6548
|
+
print(chunk.choices[0].delta.content)`
|
|
6549
|
+
},
|
|
6550
|
+
{
|
|
6551
|
+
client: "openai",
|
|
6552
|
+
content: `from openai import OpenAI
|
|
6553
|
+
|
|
6554
|
+
client = OpenAI(
|
|
6555
|
+
base_url="https://api-inference.huggingface.co/v1/",
|
|
6556
|
+
api_key="${accessToken || "{API_TOKEN}"}"
|
|
6557
|
+
)
|
|
6558
|
+
|
|
6559
|
+
messages = ${messagesStr}
|
|
6560
|
+
|
|
6561
|
+
stream = client.chat.completions.create(
|
|
6562
|
+
model="${model.id}",
|
|
6563
|
+
messages=messages,
|
|
6564
|
+
${configStr},
|
|
6565
|
+
stream=True
|
|
6566
|
+
)
|
|
6567
|
+
|
|
6568
|
+
for chunk in stream:
|
|
6569
|
+
print(chunk.choices[0].delta.content)`
|
|
6570
|
+
}
|
|
6571
|
+
];
|
|
6572
|
+
} else {
|
|
6573
|
+
return [
|
|
6574
|
+
{
|
|
6575
|
+
client: "huggingface_hub",
|
|
6576
|
+
content: `from huggingface_hub import InferenceClient
|
|
6577
|
+
|
|
6578
|
+
client = InferenceClient(api_key="${accessToken || "{API_TOKEN}"}")
|
|
6579
|
+
|
|
6580
|
+
messages = ${messagesStr}
|
|
6581
|
+
|
|
6582
|
+
completion = client.chat.completions.create(
|
|
6583
|
+
model="${model.id}",
|
|
6584
|
+
messages=messages,
|
|
6585
|
+
${configStr}
|
|
6586
|
+
)
|
|
6587
|
+
|
|
6588
|
+
print(completion.choices[0].message)`
|
|
6589
|
+
},
|
|
6590
|
+
{
|
|
6591
|
+
client: "openai",
|
|
6592
|
+
content: `from openai import OpenAI
|
|
6593
|
+
|
|
6594
|
+
client = OpenAI(
|
|
6595
|
+
base_url="https://api-inference.huggingface.co/v1/",
|
|
6596
|
+
api_key="${accessToken || "{API_TOKEN}"}"
|
|
6597
|
+
)
|
|
6598
|
+
|
|
6599
|
+
messages = ${messagesStr}
|
|
6600
|
+
|
|
6601
|
+
completion = client.chat.completions.create(
|
|
6602
|
+
model="${model.id}",
|
|
6603
|
+
messages=messages,
|
|
6604
|
+
${configStr}
|
|
6605
|
+
)
|
|
6606
|
+
|
|
6607
|
+
print(completion.choices[0].message)`
|
|
6608
|
+
}
|
|
6609
|
+
];
|
|
6610
|
+
}
|
|
6611
|
+
};
|
|
6612
|
+
var snippetConversationalWithImage = (model, accessToken) => ({
|
|
6613
|
+
content: `from huggingface_hub import InferenceClient
|
|
6394
6614
|
|
|
6395
6615
|
client = InferenceClient(api_key="${accessToken || "{API_TOKEN}"}")
|
|
6396
6616
|
|
|
@@ -6410,16 +6630,20 @@ for message in client.chat_completion(
|
|
|
6410
6630
|
max_tokens=500,
|
|
6411
6631
|
stream=True,
|
|
6412
6632
|
):
|
|
6413
|
-
print(message.choices[0].delta.content, end="")
|
|
6414
|
-
|
|
6633
|
+
print(message.choices[0].delta.content, end="")`
|
|
6634
|
+
});
|
|
6635
|
+
var snippetZeroShotClassification2 = (model) => ({
|
|
6636
|
+
content: `def query(payload):
|
|
6415
6637
|
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6416
6638
|
return response.json()
|
|
6417
6639
|
|
|
6418
6640
|
output = query({
|
|
6419
6641
|
"inputs": ${getModelInputSnippet(model)},
|
|
6420
6642
|
"parameters": {"candidate_labels": ["refund", "legal", "faq"]},
|
|
6421
|
-
})
|
|
6422
|
-
|
|
6643
|
+
})`
|
|
6644
|
+
});
|
|
6645
|
+
var snippetZeroShotImageClassification = (model) => ({
|
|
6646
|
+
content: `def query(data):
|
|
6423
6647
|
with open(data["image_path"], "rb") as f:
|
|
6424
6648
|
img = f.read()
|
|
6425
6649
|
payload={
|
|
@@ -6432,22 +6656,28 @@ var snippetZeroShotImageClassification = (model) => `def query(data):
|
|
|
6432
6656
|
output = query({
|
|
6433
6657
|
"image_path": ${getModelInputSnippet(model)},
|
|
6434
6658
|
"parameters": {"candidate_labels": ["cat", "dog", "llama"]},
|
|
6435
|
-
})
|
|
6436
|
-
|
|
6659
|
+
})`
|
|
6660
|
+
});
|
|
6661
|
+
var snippetBasic2 = (model) => ({
|
|
6662
|
+
content: `def query(payload):
|
|
6437
6663
|
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6438
6664
|
return response.json()
|
|
6439
6665
|
|
|
6440
6666
|
output = query({
|
|
6441
6667
|
"inputs": ${getModelInputSnippet(model)},
|
|
6442
|
-
})
|
|
6443
|
-
|
|
6668
|
+
})`
|
|
6669
|
+
});
|
|
6670
|
+
var snippetFile2 = (model) => ({
|
|
6671
|
+
content: `def query(filename):
|
|
6444
6672
|
with open(filename, "rb") as f:
|
|
6445
6673
|
data = f.read()
|
|
6446
6674
|
response = requests.post(API_URL, headers=headers, data=data)
|
|
6447
6675
|
return response.json()
|
|
6448
6676
|
|
|
6449
|
-
output = query(${getModelInputSnippet(model)})
|
|
6450
|
-
|
|
6677
|
+
output = query(${getModelInputSnippet(model)})`
|
|
6678
|
+
});
|
|
6679
|
+
var snippetTextToImage = (model) => ({
|
|
6680
|
+
content: `def query(payload):
|
|
6451
6681
|
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6452
6682
|
return response.content
|
|
6453
6683
|
image_bytes = query({
|
|
@@ -6456,16 +6686,20 @@ image_bytes = query({
|
|
|
6456
6686
|
# You can access the image with PIL.Image for example
|
|
6457
6687
|
import io
|
|
6458
6688
|
from PIL import Image
|
|
6459
|
-
image = Image.open(io.BytesIO(image_bytes))
|
|
6460
|
-
|
|
6689
|
+
image = Image.open(io.BytesIO(image_bytes))`
|
|
6690
|
+
});
|
|
6691
|
+
var snippetTabular = (model) => ({
|
|
6692
|
+
content: `def query(payload):
|
|
6461
6693
|
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6462
6694
|
return response.content
|
|
6463
6695
|
response = query({
|
|
6464
6696
|
"inputs": {"data": ${getModelInputSnippet(model)}},
|
|
6465
|
-
})
|
|
6697
|
+
})`
|
|
6698
|
+
});
|
|
6466
6699
|
var snippetTextToAudio = (model) => {
|
|
6467
6700
|
if (model.library_name === "transformers") {
|
|
6468
|
-
return
|
|
6701
|
+
return {
|
|
6702
|
+
content: `def query(payload):
|
|
6469
6703
|
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6470
6704
|
return response.content
|
|
6471
6705
|
|
|
@@ -6474,9 +6708,11 @@ audio_bytes = query({
|
|
|
6474
6708
|
})
|
|
6475
6709
|
# You can access the audio with IPython.display for example
|
|
6476
6710
|
from IPython.display import Audio
|
|
6477
|
-
Audio(audio_bytes)
|
|
6711
|
+
Audio(audio_bytes)`
|
|
6712
|
+
};
|
|
6478
6713
|
} else {
|
|
6479
|
-
return
|
|
6714
|
+
return {
|
|
6715
|
+
content: `def query(payload):
|
|
6480
6716
|
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6481
6717
|
return response.json()
|
|
6482
6718
|
|
|
@@ -6485,10 +6721,12 @@ audio, sampling_rate = query({
|
|
|
6485
6721
|
})
|
|
6486
6722
|
# You can access the audio with IPython.display for example
|
|
6487
6723
|
from IPython.display import Audio
|
|
6488
|
-
Audio(audio, rate=sampling_rate)
|
|
6724
|
+
Audio(audio, rate=sampling_rate)`
|
|
6725
|
+
};
|
|
6489
6726
|
}
|
|
6490
6727
|
};
|
|
6491
|
-
var snippetDocumentQuestionAnswering = (model) =>
|
|
6728
|
+
var snippetDocumentQuestionAnswering = (model) => ({
|
|
6729
|
+
content: `def query(payload):
|
|
6492
6730
|
with open(payload["image"], "rb") as f:
|
|
6493
6731
|
img = f.read()
|
|
6494
6732
|
payload["image"] = base64.b64encode(img).decode("utf-8")
|
|
@@ -6497,7 +6735,8 @@ var snippetDocumentQuestionAnswering = (model) => `def query(payload):
|
|
|
6497
6735
|
|
|
6498
6736
|
output = query({
|
|
6499
6737
|
"inputs": ${getModelInputSnippet(model)},
|
|
6500
|
-
})
|
|
6738
|
+
})`
|
|
6739
|
+
});
|
|
6501
6740
|
var pythonSnippets = {
|
|
6502
6741
|
// Same order as in tasks/src/pipelines.ts
|
|
6503
6742
|
"text-classification": snippetBasic2,
|
|
@@ -6528,19 +6767,25 @@ var pythonSnippets = {
|
|
|
6528
6767
|
"image-to-text": snippetFile2,
|
|
6529
6768
|
"zero-shot-image-classification": snippetZeroShotImageClassification
|
|
6530
6769
|
};
|
|
6531
|
-
function getPythonInferenceSnippet(model, accessToken) {
|
|
6770
|
+
function getPythonInferenceSnippet(model, accessToken, opts) {
|
|
6532
6771
|
if (model.pipeline_tag === "text-generation" && model.tags.includes("conversational")) {
|
|
6533
|
-
return snippetConversational(model, accessToken);
|
|
6772
|
+
return snippetConversational(model, accessToken, opts);
|
|
6534
6773
|
} else if (model.pipeline_tag === "image-text-to-text" && model.tags.includes("conversational")) {
|
|
6535
6774
|
return snippetConversationalWithImage(model, accessToken);
|
|
6536
6775
|
} else {
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6776
|
+
let snippets = model.pipeline_tag && model.pipeline_tag in pythonSnippets ? pythonSnippets[model.pipeline_tag]?.(model, accessToken) ?? { content: "" } : { content: "" };
|
|
6777
|
+
snippets = Array.isArray(snippets) ? snippets : [snippets];
|
|
6778
|
+
return snippets.map((snippet) => {
|
|
6779
|
+
return {
|
|
6780
|
+
...snippet,
|
|
6781
|
+
content: `import requests
|
|
6782
|
+
|
|
6540
6783
|
API_URL = "https://api-inference.huggingface.co/models/${model.id}"
|
|
6541
6784
|
headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
|
|
6542
|
-
|
|
6543
|
-
${
|
|
6785
|
+
|
|
6786
|
+
${snippet.content}`
|
|
6787
|
+
};
|
|
6788
|
+
});
|
|
6544
6789
|
}
|
|
6545
6790
|
}
|
|
6546
6791
|
function hasPythonInferenceSnippet(model) {
|
|
@@ -6561,7 +6806,8 @@ __export(js_exports, {
|
|
|
6561
6806
|
snippetTextToImage: () => snippetTextToImage2,
|
|
6562
6807
|
snippetZeroShotClassification: () => snippetZeroShotClassification3
|
|
6563
6808
|
});
|
|
6564
|
-
var snippetBasic3 = (model, accessToken) =>
|
|
6809
|
+
var snippetBasic3 = (model, accessToken) => ({
|
|
6810
|
+
content: `async function query(data) {
|
|
6565
6811
|
const response = await fetch(
|
|
6566
6812
|
"https://api-inference.huggingface.co/models/${model.id}",
|
|
6567
6813
|
{
|
|
@@ -6579,27 +6825,120 @@ var snippetBasic3 = (model, accessToken) => `async function query(data) {
|
|
|
6579
6825
|
|
|
6580
6826
|
query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
|
|
6581
6827
|
console.log(JSON.stringify(response));
|
|
6582
|
-
})
|
|
6583
|
-
|
|
6828
|
+
});`
|
|
6829
|
+
});
|
|
6830
|
+
var snippetTextGeneration2 = (model, accessToken, opts) => {
|
|
6584
6831
|
if (model.tags.includes("conversational")) {
|
|
6585
|
-
|
|
6832
|
+
const streaming = opts?.streaming ?? true;
|
|
6833
|
+
const messages = opts?.messages ?? [
|
|
6834
|
+
{ role: "user", content: "What is the capital of France?" }
|
|
6835
|
+
];
|
|
6836
|
+
const messagesStr = stringifyMessages(messages, { sep: ",\n ", start: "[\n ", end: "\n ]" });
|
|
6837
|
+
const config = {
|
|
6838
|
+
...opts?.temperature ? { temperature: opts.temperature } : void 0,
|
|
6839
|
+
max_tokens: opts?.max_tokens ?? 500,
|
|
6840
|
+
...opts?.top_p ? { top_p: opts.top_p } : void 0
|
|
6841
|
+
};
|
|
6842
|
+
const configStr = stringifyGenerationConfig(config, {
|
|
6843
|
+
sep: ",\n ",
|
|
6844
|
+
start: "",
|
|
6845
|
+
end: "",
|
|
6846
|
+
attributeValueConnector: ": "
|
|
6847
|
+
});
|
|
6848
|
+
if (streaming) {
|
|
6849
|
+
return [
|
|
6850
|
+
{
|
|
6851
|
+
client: "huggingface_hub",
|
|
6852
|
+
content: `import { HfInference } from "@huggingface/inference"
|
|
6586
6853
|
|
|
6587
|
-
const
|
|
6854
|
+
const client = new HfInference("${accessToken || `{API_TOKEN}`}")
|
|
6588
6855
|
|
|
6589
|
-
|
|
6856
|
+
let out = "";
|
|
6857
|
+
|
|
6858
|
+
const stream = client.chatCompletionStream({
|
|
6590
6859
|
model: "${model.id}",
|
|
6591
|
-
messages:
|
|
6592
|
-
|
|
6593
|
-
})
|
|
6594
|
-
|
|
6595
|
-
|
|
6860
|
+
messages: ${messagesStr},
|
|
6861
|
+
${configStr}
|
|
6862
|
+
});
|
|
6863
|
+
|
|
6864
|
+
for await (const chunk of stream) {
|
|
6865
|
+
if (chunk.choices && chunk.choices.length > 0) {
|
|
6866
|
+
const newContent = chunk.choices[0].delta.content;
|
|
6867
|
+
out += newContent;
|
|
6868
|
+
console.log(newContent);
|
|
6869
|
+
}
|
|
6870
|
+
}`
|
|
6871
|
+
},
|
|
6872
|
+
{
|
|
6873
|
+
client: "openai",
|
|
6874
|
+
content: `import { OpenAI } from "openai"
|
|
6875
|
+
|
|
6876
|
+
const client = new OpenAI({
|
|
6877
|
+
baseURL: "https://api-inference.huggingface.co/v1/",
|
|
6878
|
+
apiKey: "${accessToken || `{API_TOKEN}`}"
|
|
6879
|
+
})
|
|
6880
|
+
|
|
6881
|
+
let out = "";
|
|
6882
|
+
|
|
6883
|
+
const stream = await client.chat.completions.create({
|
|
6884
|
+
model: "${model.id}",
|
|
6885
|
+
messages: ${messagesStr},
|
|
6886
|
+
${configStr},
|
|
6887
|
+
stream: true,
|
|
6888
|
+
});
|
|
6889
|
+
|
|
6890
|
+
for await (const chunk of stream) {
|
|
6891
|
+
if (chunk.choices && chunk.choices.length > 0) {
|
|
6892
|
+
const newContent = chunk.choices[0].delta.content;
|
|
6893
|
+
out += newContent;
|
|
6894
|
+
console.log(newContent);
|
|
6895
|
+
}
|
|
6896
|
+
}`
|
|
6897
|
+
}
|
|
6898
|
+
];
|
|
6899
|
+
} else {
|
|
6900
|
+
return [
|
|
6901
|
+
{
|
|
6902
|
+
client: "huggingface_hub",
|
|
6903
|
+
content: `import { HfInference } from '@huggingface/inference'
|
|
6904
|
+
|
|
6905
|
+
const client = new HfInference("${accessToken || `{API_TOKEN}`}")
|
|
6906
|
+
|
|
6907
|
+
const chatCompletion = await client.chatCompletion({
|
|
6908
|
+
model: "${model.id}",
|
|
6909
|
+
messages: ${messagesStr},
|
|
6910
|
+
${configStr}
|
|
6911
|
+
});
|
|
6912
|
+
|
|
6913
|
+
console.log(chatCompletion.choices[0].message);`
|
|
6914
|
+
},
|
|
6915
|
+
{
|
|
6916
|
+
client: "openai",
|
|
6917
|
+
content: `import { OpenAI } from "openai"
|
|
6918
|
+
|
|
6919
|
+
const client = new OpenAI({
|
|
6920
|
+
baseURL: "https://api-inference.huggingface.co/v1/",
|
|
6921
|
+
apiKey: "${accessToken || `{API_TOKEN}`}"
|
|
6922
|
+
})
|
|
6923
|
+
|
|
6924
|
+
const chatCompletion = await client.chat.completions.create({
|
|
6925
|
+
model: "${model.id}",
|
|
6926
|
+
messages: ${messagesStr},
|
|
6927
|
+
${configStr}
|
|
6928
|
+
});
|
|
6929
|
+
|
|
6930
|
+
console.log(chatCompletion.choices[0].message);`
|
|
6931
|
+
}
|
|
6932
|
+
];
|
|
6933
|
+
}
|
|
6596
6934
|
} else {
|
|
6597
6935
|
return snippetBasic3(model, accessToken);
|
|
6598
6936
|
}
|
|
6599
6937
|
};
|
|
6600
6938
|
var snippetImageTextToTextGeneration2 = (model, accessToken) => {
|
|
6601
6939
|
if (model.tags.includes("conversational")) {
|
|
6602
|
-
return
|
|
6940
|
+
return {
|
|
6941
|
+
content: `import { HfInference } from "@huggingface/inference";
|
|
6603
6942
|
|
|
6604
6943
|
const inference = new HfInference("${accessToken || `{API_TOKEN}`}");
|
|
6605
6944
|
const imageUrl = "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg";
|
|
@@ -6618,12 +6957,14 @@ for await (const chunk of inference.chatCompletionStream({
|
|
|
6618
6957
|
max_tokens: 500,
|
|
6619
6958
|
})) {
|
|
6620
6959
|
process.stdout.write(chunk.choices[0]?.delta?.content || "");
|
|
6621
|
-
}
|
|
6960
|
+
}`
|
|
6961
|
+
};
|
|
6622
6962
|
} else {
|
|
6623
6963
|
return snippetBasic3(model, accessToken);
|
|
6624
6964
|
}
|
|
6625
6965
|
};
|
|
6626
|
-
var snippetZeroShotClassification3 = (model, accessToken) =>
|
|
6966
|
+
var snippetZeroShotClassification3 = (model, accessToken) => ({
|
|
6967
|
+
content: `async function query(data) {
|
|
6627
6968
|
const response = await fetch(
|
|
6628
6969
|
"https://api-inference.huggingface.co/models/${model.id}",
|
|
6629
6970
|
{
|
|
@@ -6640,11 +6981,13 @@ var snippetZeroShotClassification3 = (model, accessToken) => `async function que
|
|
|
6640
6981
|
}
|
|
6641
6982
|
|
|
6642
6983
|
query({"inputs": ${getModelInputSnippet(
|
|
6643
|
-
|
|
6644
|
-
)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}).then((response) => {
|
|
6984
|
+
model
|
|
6985
|
+
)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}).then((response) => {
|
|
6645
6986
|
console.log(JSON.stringify(response));
|
|
6646
|
-
})
|
|
6647
|
-
|
|
6987
|
+
});`
|
|
6988
|
+
});
|
|
6989
|
+
var snippetTextToImage2 = (model, accessToken) => ({
|
|
6990
|
+
content: `async function query(data) {
|
|
6648
6991
|
const response = await fetch(
|
|
6649
6992
|
"https://api-inference.huggingface.co/models/${model.id}",
|
|
6650
6993
|
{
|
|
@@ -6661,7 +7004,8 @@ var snippetTextToImage2 = (model, accessToken) => `async function query(data) {
|
|
|
6661
7004
|
}
|
|
6662
7005
|
query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
|
|
6663
7006
|
// Use image
|
|
6664
|
-
})
|
|
7007
|
+
});`
|
|
7008
|
+
});
|
|
6665
7009
|
var snippetTextToAudio2 = (model, accessToken) => {
|
|
6666
7010
|
const commonSnippet = `async function query(data) {
|
|
6667
7011
|
const response = await fetch(
|
|
@@ -6676,25 +7020,30 @@ var snippetTextToAudio2 = (model, accessToken) => {
|
|
|
6676
7020
|
}
|
|
6677
7021
|
);`;
|
|
6678
7022
|
if (model.library_name === "transformers") {
|
|
6679
|
-
return
|
|
7023
|
+
return {
|
|
7024
|
+
content: commonSnippet + `
|
|
6680
7025
|
const result = await response.blob();
|
|
6681
7026
|
return result;
|
|
6682
7027
|
}
|
|
6683
7028
|
query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
|
|
6684
7029
|
// Returns a byte object of the Audio wavform. Use it directly!
|
|
6685
|
-
})
|
|
7030
|
+
});`
|
|
7031
|
+
};
|
|
6686
7032
|
} else {
|
|
6687
|
-
return
|
|
7033
|
+
return {
|
|
7034
|
+
content: commonSnippet + `
|
|
6688
7035
|
const result = await response.json();
|
|
6689
7036
|
return result;
|
|
6690
7037
|
}
|
|
6691
7038
|
|
|
6692
7039
|
query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
|
|
6693
7040
|
console.log(JSON.stringify(response));
|
|
6694
|
-
})
|
|
7041
|
+
});`
|
|
7042
|
+
};
|
|
6695
7043
|
}
|
|
6696
7044
|
};
|
|
6697
|
-
var snippetFile3 = (model, accessToken) =>
|
|
7045
|
+
var snippetFile3 = (model, accessToken) => ({
|
|
7046
|
+
content: `async function query(filename) {
|
|
6698
7047
|
const data = fs.readFileSync(filename);
|
|
6699
7048
|
const response = await fetch(
|
|
6700
7049
|
"https://api-inference.huggingface.co/models/${model.id}",
|
|
@@ -6713,7 +7062,8 @@ var snippetFile3 = (model, accessToken) => `async function query(filename) {
|
|
|
6713
7062
|
|
|
6714
7063
|
query(${getModelInputSnippet(model)}).then((response) => {
|
|
6715
7064
|
console.log(JSON.stringify(response));
|
|
6716
|
-
})
|
|
7065
|
+
});`
|
|
7066
|
+
});
|
|
6717
7067
|
var jsSnippets = {
|
|
6718
7068
|
// Same order as in js/src/lib/interfaces/Types.ts
|
|
6719
7069
|
"text-classification": snippetBasic3,
|
|
@@ -6741,7 +7091,7 @@ var jsSnippets = {
|
|
|
6741
7091
|
"image-segmentation": snippetFile3
|
|
6742
7092
|
};
|
|
6743
7093
|
function getJsInferenceSnippet(model, accessToken) {
|
|
6744
|
-
return model.pipeline_tag && model.pipeline_tag in jsSnippets ? jsSnippets[model.pipeline_tag]?.(model, accessToken) ?? "" : "";
|
|
7094
|
+
return model.pipeline_tag && model.pipeline_tag in jsSnippets ? jsSnippets[model.pipeline_tag]?.(model, accessToken) ?? { content: "" } : { content: "" };
|
|
6745
7095
|
}
|
|
6746
7096
|
function hasJsInferenceSnippet(model) {
|
|
6747
7097
|
return !!model.pipeline_tag && model.pipeline_tag in jsSnippets;
|
|
@@ -6808,6 +7158,11 @@ var SKUS = {
|
|
|
6808
7158
|
tflops: 31.24,
|
|
6809
7159
|
memory: [24]
|
|
6810
7160
|
},
|
|
7161
|
+
A2: {
|
|
7162
|
+
tflops: 4.531,
|
|
7163
|
+
// source: https://www.techpowerup.com/gpu-specs/a2.c3848
|
|
7164
|
+
memory: [16]
|
|
7165
|
+
},
|
|
6811
7166
|
"RTX 4090": {
|
|
6812
7167
|
tflops: 82.58,
|
|
6813
7168
|
memory: [24]
|
|
@@ -6970,6 +7325,14 @@ var SKUS = {
|
|
|
6970
7325
|
tflops: 184.6,
|
|
6971
7326
|
memory: [32]
|
|
6972
7327
|
},
|
|
7328
|
+
MI60: {
|
|
7329
|
+
tflops: 29.5,
|
|
7330
|
+
memory: [32]
|
|
7331
|
+
},
|
|
7332
|
+
MI50: {
|
|
7333
|
+
tflops: 26.5,
|
|
7334
|
+
memory: [16]
|
|
7335
|
+
},
|
|
6973
7336
|
"RX 7900 XTX": {
|
|
6974
7337
|
tflops: 122.8,
|
|
6975
7338
|
memory: [24]
|
|
@@ -7002,6 +7365,14 @@ var SKUS = {
|
|
|
7002
7365
|
tflops: 32.33,
|
|
7003
7366
|
memory: [16]
|
|
7004
7367
|
},
|
|
7368
|
+
"RX 6700 XT": {
|
|
7369
|
+
tflops: 26.43,
|
|
7370
|
+
memory: [12]
|
|
7371
|
+
},
|
|
7372
|
+
"RX 6700": {
|
|
7373
|
+
tflops: 22.58,
|
|
7374
|
+
memory: [10]
|
|
7375
|
+
},
|
|
7005
7376
|
"Radeon Pro VII": {
|
|
7006
7377
|
tflops: 26.11,
|
|
7007
7378
|
memory: [16]
|