@huggingface/tasks 0.10.20 → 0.10.22

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 CHANGED
@@ -4296,13 +4296,18 @@ var gliner = (model) => [
4296
4296
  model = GLiNER.from_pretrained("${model.id}")`
4297
4297
  ];
4298
4298
  var keras = (model) => [
4299
- `from huggingface_hub import from_pretrained_keras
4299
+ `# Available backend options are: "jax", "tensorflow", "torch".
4300
+ import os
4301
+ os.environ["KERAS_BACKEND"] = "tensorflow"
4302
+
4303
+ import keras
4300
4304
 
4301
- model = from_pretrained_keras("${model.id}")
4305
+ model = keras.saving.load_model("hf://${model.id}")
4302
4306
  `
4303
4307
  ];
4304
4308
  var keras_nlp = (model) => [
4305
4309
  `# Available backend options are: "jax", "tensorflow", "torch".
4310
+ import os
4306
4311
  os.environ["KERAS_BACKEND"] = "tensorflow"
4307
4312
 
4308
4313
  import keras_nlp
@@ -4311,6 +4316,20 @@ tokenizer = keras_nlp.models.Tokenizer.from_preset("hf://${model.id}")
4311
4316
  backbone = keras_nlp.models.Backbone.from_preset("hf://${model.id}")
4312
4317
  `
4313
4318
  ];
4319
+ var tf_keras = (model) => [
4320
+ `# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
4321
+ # See https://github.com/keras-team/tf-keras for more details.
4322
+ from huggingface_hub import from_pretrained_keras
4323
+
4324
+ model = from_pretrained_keras("${model.id}")
4325
+ `
4326
+ ];
4327
+ var mars5_tts = (model) => [
4328
+ `# Install from https://github.com/Camb-ai/MARS5-TTS
4329
+
4330
+ from inference import Mars5TTS
4331
+ mars5 = Mars5TTS.from_pretrained("${model.id}")`
4332
+ ];
4314
4333
  var open_clip = (model) => [
4315
4334
  `import open_clip
4316
4335
 
@@ -4759,6 +4778,19 @@ var audiocraft = (model) => {
4759
4778
  return [`# Type of model unknown.`];
4760
4779
  }
4761
4780
  };
4781
+ var whisperkit = () => [
4782
+ `# Install CLI with Homebrew on macOS device
4783
+ brew install whisperkit-cli
4784
+
4785
+ # View all available inference options
4786
+ whisperkit-cli transcribe --help
4787
+
4788
+ # Download and run inference using whisper base model
4789
+ whisperkit-cli transcribe --audio-path /path/to/audio.mp3
4790
+
4791
+ # Or use your preferred model variant
4792
+ whisperkit-cli transcribe --model "large-v3" --model-prefix "distil" --audio-path /path/to/audio.mp3 --verbose`
4793
+ ];
4762
4794
 
4763
4795
  // src/model-libraries.ts
4764
4796
  var MODEL_LIBRARIES_UI_ELEMENTS = {
@@ -4793,7 +4825,8 @@ var MODEL_LIBRARIES_UI_ELEMENTS = {
4793
4825
  repoName: "audiocraft",
4794
4826
  repoUrl: "https://github.com/facebookresearch/audiocraft",
4795
4827
  snippets: audiocraft,
4796
- filter: false
4828
+ filter: false,
4829
+ countDownloads: `path:"state_dict.bin"`
4797
4830
  },
4798
4831
  audioseal: {
4799
4832
  prettyLabel: "AudioSeal",
@@ -4945,6 +4978,16 @@ var MODEL_LIBRARIES_UI_ELEMENTS = {
4945
4978
  docsUrl: "https://huggingface.co/docs/hub/keras",
4946
4979
  snippets: keras,
4947
4980
  filter: true,
4981
+ countDownloads: `path:"config.json" OR path_extension:"keras"`
4982
+ },
4983
+ "tf-keras": {
4984
+ // Legacy "Keras 2" library (tensorflow-only)
4985
+ prettyLabel: "TF-Keras",
4986
+ repoName: "TF-Keras",
4987
+ repoUrl: "https://github.com/keras-team/tf-keras",
4988
+ docsUrl: "https://huggingface.co/docs/hub/tf-keras",
4989
+ snippets: tf_keras,
4990
+ filter: true,
4948
4991
  countDownloads: `path:"saved_model.pb"`
4949
4992
  },
4950
4993
  "keras-nlp": {
@@ -4964,6 +5007,14 @@ var MODEL_LIBRARIES_UI_ELEMENTS = {
4964
5007
  repoName: "mindspore",
4965
5008
  repoUrl: "https://github.com/mindspore-ai/mindspore"
4966
5009
  },
5010
+ "mars5-tts": {
5011
+ prettyLabel: "MARS5-TTS",
5012
+ repoName: "MARS5-TTS",
5013
+ repoUrl: "https://github.com/Camb-ai/MARS5-TTS",
5014
+ filter: false,
5015
+ countDownloads: `path:"mars5_ar.safetensors"`,
5016
+ snippets: mars5_tts
5017
+ },
4967
5018
  "ml-agents": {
4968
5019
  prettyLabel: "ml-agents",
4969
5020
  repoName: "ml-agents",
@@ -5199,6 +5250,8 @@ var MODEL_LIBRARIES_UI_ELEMENTS = {
5199
5250
  prettyLabel: "WhisperKit",
5200
5251
  repoName: "WhisperKit",
5201
5252
  repoUrl: "https://github.com/argmaxinc/WhisperKit",
5253
+ docsUrl: "https://github.com/argmaxinc/WhisperKit?tab=readme-ov-file#homebrew",
5254
+ snippets: whisperkit,
5202
5255
  countDownloads: `path_filename:"model" AND path_extension:"mil" AND _exists_:"path_prefix"`
5203
5256
  }
5204
5257
  };
@@ -5246,39 +5299,39 @@ var inputsZeroShotClassification = () => `"Hi, I recently bought a device from y
5246
5299
  var inputsTranslation = () => `"\u041C\u0435\u043D\u044F \u0437\u043E\u0432\u0443\u0442 \u0412\u043E\u043B\u044C\u0444\u0433\u0430\u043D\u0433 \u0438 \u044F \u0436\u0438\u0432\u0443 \u0432 \u0411\u0435\u0440\u043B\u0438\u043D\u0435"`;
5247
5300
  var inputsSummarization = () => `"The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct."`;
5248
5301
  var inputsTableQuestionAnswering = () => `{
5249
- "query": "How many stars does the transformers repository have?",
5250
- "table": {
5251
- "Repository": ["Transformers", "Datasets", "Tokenizers"],
5252
- "Stars": ["36542", "4512", "3934"],
5253
- "Contributors": ["651", "77", "34"],
5254
- "Programming language": [
5255
- "Python",
5256
- "Python",
5257
- "Rust, Python and NodeJS"
5258
- ]
5259
- }
5260
- }`;
5302
+ "query": "How many stars does the transformers repository have?",
5303
+ "table": {
5304
+ "Repository": ["Transformers", "Datasets", "Tokenizers"],
5305
+ "Stars": ["36542", "4512", "3934"],
5306
+ "Contributors": ["651", "77", "34"],
5307
+ "Programming language": [
5308
+ "Python",
5309
+ "Python",
5310
+ "Rust, Python and NodeJS"
5311
+ ]
5312
+ }
5313
+ }`;
5261
5314
  var inputsVisualQuestionAnswering = () => `{
5262
- "image": "cat.png",
5263
- "question": "What is in this image?"
5264
- }`;
5315
+ "image": "cat.png",
5316
+ "question": "What is in this image?"
5317
+ }`;
5265
5318
  var inputsQuestionAnswering = () => `{
5266
- "question": "What is my name?",
5267
- "context": "My name is Clara and I live in Berkeley."
5268
- }`;
5319
+ "question": "What is my name?",
5320
+ "context": "My name is Clara and I live in Berkeley."
5321
+ }`;
5269
5322
  var inputsTextClassification = () => `"I like you. I love you"`;
5270
5323
  var inputsTokenClassification = () => `"My name is Sarah Jessica Parker but you can call me Jessica"`;
5271
5324
  var inputsTextGeneration = () => `"Can you please let us know more details about your "`;
5272
5325
  var inputsText2TextGeneration = () => `"The answer to the universe is"`;
5273
5326
  var inputsFillMask = (model) => `"The answer to the universe is ${model.mask_token}."`;
5274
5327
  var inputsSentenceSimilarity = () => `{
5275
- "source_sentence": "That is a happy person",
5276
- "sentences": [
5277
- "That is a happy dog",
5278
- "That is a very happy person",
5279
- "Today is a sunny day"
5280
- ]
5281
- }`;
5328
+ "source_sentence": "That is a happy person",
5329
+ "sentences": [
5330
+ "That is a happy dog",
5331
+ "That is a very happy person",
5332
+ "Today is a sunny day"
5333
+ ]
5334
+ }`;
5282
5335
  var inputsFeatureExtraction = () => `"Today is a sunny day and I will get some ice cream."`;
5283
5336
  var inputsImageClassification = () => `"cats.jpg"`;
5284
5337
  var inputsImageToText = () => `"cats.jpg"`;
@@ -5347,6 +5400,7 @@ __export(curl_exports, {
5347
5400
  hasCurlInferenceSnippet: () => hasCurlInferenceSnippet,
5348
5401
  snippetBasic: () => snippetBasic,
5349
5402
  snippetFile: () => snippetFile,
5403
+ snippetTextGeneration: () => snippetTextGeneration,
5350
5404
  snippetZeroShotClassification: () => snippetZeroShotClassification
5351
5405
  });
5352
5406
  var snippetBasic = (model, accessToken) => `curl https://api-inference.huggingface.co/models/${model.id} \\
@@ -5355,6 +5409,22 @@ var snippetBasic = (model, accessToken) => `curl https://api-inference.huggingfa
5355
5409
  -H 'Content-Type: application/json' \\
5356
5410
  -H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}"
5357
5411
  `;
5412
+ var snippetTextGeneration = (model, accessToken) => {
5413
+ if (model.config?.tokenizer_config?.chat_template) {
5414
+ return `curl 'https://api-inference.huggingface.co/models/${model.id}/v1/chat/completions' \\
5415
+ -H "Authorization: Bearer ${accessToken || `{API_TOKEN}`}" \\
5416
+ -H 'Content-Type: application/json' \\
5417
+ -d '{
5418
+ "model": "${model.id}",
5419
+ "messages": [{"role": "user", "content": "What is the capital of France?"}],
5420
+ "max_tokens": 500,
5421
+ "stream": false
5422
+ }'
5423
+ `;
5424
+ } else {
5425
+ return snippetBasic(model, accessToken);
5426
+ }
5427
+ };
5358
5428
  var snippetZeroShotClassification = (model, accessToken) => `curl https://api-inference.huggingface.co/models/${model.id} \\
5359
5429
  -X POST \\
5360
5430
  -d '{"inputs": ${getModelInputSnippet(model, true)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}' \\
@@ -5376,7 +5446,7 @@ var curlSnippets = {
5376
5446
  translation: snippetBasic,
5377
5447
  summarization: snippetBasic,
5378
5448
  "feature-extraction": snippetBasic,
5379
- "text-generation": snippetBasic,
5449
+ "text-generation": snippetTextGeneration,
5380
5450
  "text2text-generation": snippetBasic,
5381
5451
  "fill-mask": snippetBasic,
5382
5452
  "sentence-similarity": snippetBasic,
@@ -5405,6 +5475,7 @@ __export(python_exports, {
5405
5475
  hasPythonInferenceSnippet: () => hasPythonInferenceSnippet,
5406
5476
  pythonSnippets: () => pythonSnippets,
5407
5477
  snippetBasic: () => snippetBasic2,
5478
+ snippetConversational: () => snippetConversational,
5408
5479
  snippetDocumentQuestionAnswering: () => snippetDocumentQuestionAnswering,
5409
5480
  snippetFile: () => snippetFile2,
5410
5481
  snippetTabular: () => snippetTabular,
@@ -5413,6 +5484,20 @@ __export(python_exports, {
5413
5484
  snippetZeroShotClassification: () => snippetZeroShotClassification2,
5414
5485
  snippetZeroShotImageClassification: () => snippetZeroShotImageClassification
5415
5486
  });
5487
+ var snippetConversational = (model, accessToken) => `from huggingface_hub import InferenceClient
5488
+
5489
+ client = InferenceClient(
5490
+ "${model.id}",
5491
+ token="${accessToken || "{API_TOKEN}"}",
5492
+ )
5493
+
5494
+ for message in client.chat_completion(
5495
+ messages=[{"role": "user", "content": "What is the capital of France?"}],
5496
+ max_tokens=500,
5497
+ stream=True,
5498
+ ):
5499
+ print(message.choices[0].delta.content, end="")
5500
+ `;
5416
5501
  var snippetZeroShotClassification2 = (model) => `def query(payload):
5417
5502
  response = requests.post(API_URL, headers=headers, json=payload)
5418
5503
  return response.json()
@@ -5530,13 +5615,17 @@ var pythonSnippets = {
5530
5615
  "zero-shot-image-classification": snippetZeroShotImageClassification
5531
5616
  };
5532
5617
  function getPythonInferenceSnippet(model, accessToken) {
5533
- const body = model.pipeline_tag && model.pipeline_tag in pythonSnippets ? pythonSnippets[model.pipeline_tag]?.(model) ?? "" : "";
5534
- return `import requests
5618
+ if (model.pipeline_tag === "text-generation" && model.config?.tokenizer_config?.chat_template) {
5619
+ return snippetConversational(model, accessToken);
5620
+ } else {
5621
+ const body = model.pipeline_tag && model.pipeline_tag in pythonSnippets ? pythonSnippets[model.pipeline_tag]?.(model, accessToken) ?? "" : "";
5622
+ return `import requests
5535
5623
 
5536
5624
  API_URL = "https://api-inference.huggingface.co/models/${model.id}"
5537
5625
  headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
5538
5626
 
5539
5627
  ${body}`;
5628
+ }
5540
5629
  }
5541
5630
  function hasPythonInferenceSnippet(model) {
5542
5631
  return !!model.pipeline_tag && model.pipeline_tag in pythonSnippets;
@@ -5550,6 +5639,7 @@ __export(js_exports, {
5550
5639
  jsSnippets: () => jsSnippets,
5551
5640
  snippetBasic: () => snippetBasic3,
5552
5641
  snippetFile: () => snippetFile3,
5642
+ snippetTextGeneration: () => snippetTextGeneration2,
5553
5643
  snippetTextToAudio: () => snippetTextToAudio2,
5554
5644
  snippetTextToImage: () => snippetTextToImage2,
5555
5645
  snippetZeroShotClassification: () => snippetZeroShotClassification3
@@ -5558,7 +5648,10 @@ var snippetBasic3 = (model, accessToken) => `async function query(data) {
5558
5648
  const response = await fetch(
5559
5649
  "https://api-inference.huggingface.co/models/${model.id}",
5560
5650
  {
5561
- headers: { Authorization: "Bearer ${accessToken || `{API_TOKEN}`}" },
5651
+ headers: {
5652
+ Authorization: "Bearer ${accessToken || `{API_TOKEN}`}"
5653
+ "Content-Type": "application/json",
5654
+ },
5562
5655
  method: "POST",
5563
5656
  body: JSON.stringify(data),
5564
5657
  }
@@ -5570,11 +5663,32 @@ var snippetBasic3 = (model, accessToken) => `async function query(data) {
5570
5663
  query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
5571
5664
  console.log(JSON.stringify(response));
5572
5665
  });`;
5666
+ var snippetTextGeneration2 = (model, accessToken) => {
5667
+ if (model.config?.tokenizer_config?.chat_template) {
5668
+ return `import { HfInference } from "@huggingface/inference";
5669
+
5670
+ const inference = new HfInference("${accessToken || `{API_TOKEN}`}");
5671
+
5672
+ for await (const chunk of inference.chatCompletionStream({
5673
+ model: "${model.id}",
5674
+ messages: [{ role: "user", content: "What is the capital of France?" }],
5675
+ max_tokens: 500,
5676
+ })) {
5677
+ process.stdout.write(chunk.choices[0]?.delta?.content || "");
5678
+ }
5679
+ `;
5680
+ } else {
5681
+ return snippetBasic3(model, accessToken);
5682
+ }
5683
+ };
5573
5684
  var snippetZeroShotClassification3 = (model, accessToken) => `async function query(data) {
5574
5685
  const response = await fetch(
5575
5686
  "https://api-inference.huggingface.co/models/${model.id}",
5576
5687
  {
5577
- headers: { Authorization: "Bearer ${accessToken || `{API_TOKEN}`}" },
5688
+ headers: {
5689
+ Authorization: "Bearer ${accessToken || `{API_TOKEN}`}"
5690
+ "Content-Type": "application/json",
5691
+ },
5578
5692
  method: "POST",
5579
5693
  body: JSON.stringify(data),
5580
5694
  }
@@ -5592,7 +5706,10 @@ var snippetTextToImage2 = (model, accessToken) => `async function query(data) {
5592
5706
  const response = await fetch(
5593
5707
  "https://api-inference.huggingface.co/models/${model.id}",
5594
5708
  {
5595
- headers: { Authorization: "Bearer ${accessToken || `{API_TOKEN}`}" },
5709
+ headers: {
5710
+ Authorization: "Bearer ${accessToken || `{API_TOKEN}`}"
5711
+ "Content-Type": "application/json",
5712
+ },
5596
5713
  method: "POST",
5597
5714
  body: JSON.stringify(data),
5598
5715
  }
@@ -5608,7 +5725,10 @@ var snippetTextToAudio2 = (model, accessToken) => {
5608
5725
  const response = await fetch(
5609
5726
  "https://api-inference.huggingface.co/models/${model.id}",
5610
5727
  {
5611
- headers: { Authorization: "Bearer ${accessToken || `{API_TOKEN}`}" },
5728
+ headers: {
5729
+ Authorization: "Bearer ${accessToken || `{API_TOKEN}`}"
5730
+ "Content-Type": "application/json",
5731
+ },
5612
5732
  method: "POST",
5613
5733
  body: JSON.stringify(data),
5614
5734
  }
@@ -5637,7 +5757,10 @@ var snippetFile3 = (model, accessToken) => `async function query(filename) {
5637
5757
  const response = await fetch(
5638
5758
  "https://api-inference.huggingface.co/models/${model.id}",
5639
5759
  {
5640
- headers: { Authorization: "Bearer ${accessToken || `{API_TOKEN}`}" },
5760
+ headers: {
5761
+ Authorization: "Bearer ${accessToken || `{API_TOKEN}`}"
5762
+ "Content-Type": "application/json",
5763
+ },
5641
5764
  method: "POST",
5642
5765
  body: data,
5643
5766
  }
@@ -5659,7 +5782,7 @@ var jsSnippets = {
5659
5782
  translation: snippetBasic3,
5660
5783
  summarization: snippetBasic3,
5661
5784
  "feature-extraction": snippetBasic3,
5662
- "text-generation": snippetBasic3,
5785
+ "text-generation": snippetTextGeneration2,
5663
5786
  "text2text-generation": snippetBasic3,
5664
5787
  "fill-mask": snippetBasic3,
5665
5788
  "sentence-similarity": snippetBasic3,
@@ -6121,7 +6244,7 @@ var LOCAL_APPS = {
6121
6244
  docsUrl: "https://lmstudio.ai",
6122
6245
  mainTask: "text-generation",
6123
6246
  displayOnModelPage: isGgufModel,
6124
- deeplink: (model, filepath) => new URL(`lmstudio://open_from_hf?model=${model.id}` + filepath ? `&file=${filepath}` : "")
6247
+ deeplink: (model, filepath) => new URL(`lmstudio://open_from_hf?model=${model.id}${filepath ? `&file=${filepath}` : ""}`)
6125
6248
  },
6126
6249
  jan: {
6127
6250
  prettyLabel: "Jan",