@huggingface/tasks 0.21.54 → 0.21.55

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.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.litert_lm = exports.lerobot = exports.llama_cpp_python = exports.lightning_ir = exports.ltx = exports.kittentts = exports.kimi_audio = exports.kernels = exports.keras_hub = exports.zeromodels = exports.keras = exports.jev_style = exports.htrflow = exports.indextts = exports.gliner2 = exports.gliner = exports.gaussianformer = exports.flextab = exports.flexray = exports.flair = exports.fairseq = exports.espnet = exports.espnetASR = exports.espnetTTS = exports.edsnlp = exports.cartesia_mlx = exports.cartesia_pytorch = exports.diffusionkit = exports.diffusers = exports.describe_anything = exports.dia2 = exports.dia = exports.derm_foundation = exports.depth_pro = exports.depth_anything_v2 = exports.cxr_foundation = exports.cortiq = exports.sap_rpt_one_oss = exports.colipri = exports.collectorvision = exports.chronos_forecasting = exports.chatterbox = exports.bm25s = exports.bertopic = exports.ben2 = exports.audioseal = exports.asteroid = exports.araclip = exports.allennlp = exports.adapters = void 0;
4
- exports.vfimamba = exports.videoprism = exports.vibevoice = exports.sana = exports.sentis = exports.mlAgents = exports.stableBaselines3 = exports.fasttext = exports.peft = exports.transformersJS = exports.transformers = exports.terratorch = exports.speechbrain = exports.stanza = exports.span_marker = exports.spacy = exports.setfit = exports.sentenceTransformers = exports.aneforge = exports.sampleFactory = exports.sam_3d_body = exports.sam_3d_objects = exports.sam2 = exports.fastai = exports.stable_audio_tools = exports.sklearn = exports.seed_story = exports.saelens = exports.timm = exports.tensorflowtts = exports.routee_powertrain = exports.renderformer = exports.relik = exports.pyannote_audio = exports.pyannote_audio_pipeline = exports.pocket_tts = exports.phantom_wan = exports.perception_encoder = exports.paddleocr = exports.paddlenlp = exports.opendde = exports.openasr = exports.open_clip = exports.multimolecule = exports.mesh_anything = exports.memra = exports.matanyone = exports.mars5_tts = exports.mamba_ssm = exports.tf_keras = void 0;
5
- exports.moshi = exports.zonos = exports.hezar = exports.threedtopia_xl = exports.whisperkit = exports.audiocraft = exports.anemoi = exports.qwen3_tts = exports.pythae = exports.pxia = exports.outetts = exports.nemo = exports.pruna = exports.mobilint = exports.model2vec = exports.mlx = exports.mlxim = exports.univa = exports.swarmformer = exports.supertonic = exports.nobg = exports.birefnet = exports.ultralytics = exports.chattts = exports.vui = exports.voxcpm = exports.voicecraft = exports.lvface = void 0;
4
+ exports.videoprism = exports.vibevoice = exports.sana = exports.sentis = exports.mlAgents = exports.stableBaselines3 = exports.fasttext = exports.peft = exports.transformersJS = exports.transformers = exports.terratorch = exports.speechbrain = exports.stanza = exports.span_marker = exports.spacy = exports.setfit = exports.sentenceTransformers = exports.aneforge = exports.sampleFactory = exports.sam_3d_body = exports.sam_3d_objects = exports.sam2 = exports.fastai = exports.stable_audio_tools = exports.sklearn = exports.seed_story = exports.saelens = exports.timm = exports.tensorflowtts = exports.routee_powertrain = exports.renderformer = exports.relik = exports.pyannote_audio = exports.pyannote_audio_pipeline = exports.pocket_tts = exports.phantom_wan = exports.perception_encoder = exports.paddleocr = exports.paddlenlp = exports.opendde = exports.openasr = exports.open_clip = exports.multimolecule = exports.microduck = exports.mesh_anything = exports.memra = exports.matanyone = exports.mars5_tts = exports.mamba_ssm = exports.tf_keras = void 0;
5
+ exports.moshi = exports.zonos = exports.hezar = exports.threedtopia_xl = exports.whisperkit = exports.audiocraft = exports.anemoi = exports.qwen3_tts = exports.pythae = exports.pxia = exports.outetts = exports.nemo = exports.pruna = exports.mobilint = exports.model2vec = exports.mlx = exports.mlxim = exports.univa = exports.swarmformer = exports.supertonic = exports.nobg = exports.birefnet = exports.ultralytics = exports.chattts = exports.vui = exports.voxcpm = exports.voicecraft = exports.lvface = exports.vfimamba = void 0;
6
6
  const library_to_tasks_js_1 = require("./library-to-tasks.js");
7
7
  const inputs_js_1 = require("./snippets/inputs.js");
8
8
  const common_js_1 = require("./snippets/common.js");
@@ -17,7 +17,7 @@ const isValidIdentifier = (str) => /^[A-Za-z_]\w*$/.test(str);
17
17
  const adapters = (model) => [
18
18
  `from adapters import AutoAdapterModel
19
19
 
20
- model = AutoAdapterModel.from_pretrained("${escapeStringForJson(model.config?.adapter_transformers?.model_name ?? "fill-in-model-name")}")
20
+ model = AutoAdapterModel.from_pretrained("${escapeStringForJson(model.config?.adapter_transformers?.model_name ?? "<base-model-id>")}")
21
21
  model.load_adapter("${model.id}", set_active=True)`,
22
22
  ];
23
23
  exports.adapters = adapters;
@@ -74,7 +74,13 @@ result, message = detector.detect_watermark(watermarked_audio, sr)`;
74
74
  };
75
75
  exports.audioseal = audioseal;
76
76
  function get_base_diffusers_model(model) {
77
- return escapeStringForJson(model.cardData?.base_model?.toString() ?? "fill-in-base-model");
77
+ const baseModel = model.cardData?.base_model;
78
+ // several base models can be listed (e.g. a LoRA trained for a base and its turbo variant). When an original checkpoint
79
+ // and its Diffusers conversion are both listed (["Wan-AI/Wan2.1-I2V-14B-480P", "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers"]),
80
+ // only the conversion has a model_index.json that DiffusionPipeline can load; otherwise the first one is used
81
+ const candidates = Array.isArray(baseModel) ? baseModel : baseModel ? [baseModel] : [];
82
+ const chosen = candidates.find((id) => id.toLowerCase().endsWith("-diffusers")) ?? candidates[0];
83
+ return escapeStringForJson(chosen ?? "fill-in-base-model");
78
84
  }
79
85
  function get_prompt_from_diffusers_model(model) {
80
86
  const prompt = model.widgetData?.[0]?.text ?? model.cardData?.instance_prompt;
@@ -161,7 +167,7 @@ detector = cvg.NeuralCornerDetector(checkpoint)
161
167
  embedder = cvg.NeuralEmbedder(checkpoint)`,
162
168
  ];
163
169
  exports.collectorvision = collectorvision;
164
- const colipri = (model) => {
170
+ const colipri = () => {
165
171
  const installSnippet = `pip install colipri`;
166
172
  const exampleSnippet = `from colipri import get_model
167
173
  from colipri import get_processor
@@ -170,7 +176,7 @@ from colipri import ZeroShotImageClassificationPipeline
170
176
 
171
177
  model = get_model().cuda()
172
178
  processor = get_processor()
173
- pipeline = ZeroShotImageClassificationPipeline("${model.id}", processor)
179
+ pipeline = ZeroShotImageClassificationPipeline(model, processor)
174
180
 
175
181
  image = load_sample_ct()
176
182
 
@@ -291,7 +297,7 @@ const depth_anything_v2 = (model) => {
291
297
  else if (model.id === "depth-anything/Depth-Anything-V2-Large") {
292
298
  encoder = "vitl";
293
299
  features = "256";
294
- out_channels = "[256, 512, 1024, 1024";
300
+ out_channels = "[256, 512, 1024, 1024]";
295
301
  }
296
302
  return [
297
303
  `
@@ -300,6 +306,7 @@ const depth_anything_v2 = (model) => {
300
306
  # Load the model and infer depth from an image
301
307
  import cv2
302
308
  import torch
309
+ from huggingface_hub import hf_hub_download
303
310
 
304
311
  from depth_anything_v2.dpt import DepthAnythingV2
305
312
 
@@ -309,7 +316,8 @@ model = DepthAnythingV2(encoder="${encoder}", features=${features}, out_channels
309
316
  # load the weights
310
317
  filepath = hf_hub_download(repo_id="${model.id}", filename="depth_anything_v2_${encoder}.pth", repo_type="model")
311
318
  state_dict = torch.load(filepath, map_location="cpu")
312
- model.load_state_dict(state_dict).eval()
319
+ model.load_state_dict(state_dict)
320
+ model.eval()
313
321
 
314
322
  raw_img = cv2.imread("your/image/path")
315
323
  depth = model.infer_image(raw_img) # HxW raw depth map in numpy
@@ -319,8 +327,8 @@ depth = model.infer_image(raw_img) # HxW raw depth map in numpy
319
327
  exports.depth_anything_v2 = depth_anything_v2;
320
328
  const depth_pro = (model) => {
321
329
  const installSnippet = `# Download checkpoint
322
- pip install huggingface-hub
323
- huggingface-cli download --local-dir checkpoints ${model.id}`;
330
+ pip install huggingface_hub
331
+ hf download ${model.id} --local-dir checkpoints`;
324
332
  const inferenceSnippet = `import depth_pro
325
333
 
326
334
  # Load model and preprocessing transform
@@ -392,7 +400,7 @@ const describe_anything = (model) => [
392
400
  from huggingface_hub import snapshot_download
393
401
  from dam import DescribeAnythingModel
394
402
 
395
- snapshot_download(${model.id}, local_dir="checkpoints")
403
+ snapshot_download("${model.id}", local_dir="checkpoints")
396
404
 
397
405
  dam = DescribeAnythingModel(
398
406
  model_path="checkpoints",
@@ -504,7 +512,7 @@ pipe.load_lora_weights("${model.id}")
504
512
  prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersVideoDefaultPrompt}"
505
513
  input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png")
506
514
 
507
- image = pipe(image=input_image, prompt=prompt).frames[0]
515
+ output = pipe(image=input_image, prompt=prompt).frames[0]
508
516
  export_to_video(output, "output.mp4")`,
509
517
  ];
510
518
  const diffusers_textual_inversion = (model) => [
@@ -544,7 +552,7 @@ from diffusers import AutoPipelineForInpainting
544
552
  from diffusers.utils import load_image
545
553
 
546
554
  # switch to "mps" for apple devices
547
- pipe = AutoPipelineForInpainting.from_pretrained("${model.id}", dtype=torch.float16, variant="fp16", device_map="cuda")
555
+ pipe = AutoPipelineForInpainting.from_pretrained("${model.id}", dtype=torch.float16, device_map="cuda")
548
556
 
549
557
  img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
550
558
  mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
@@ -566,9 +574,12 @@ image = pipe(
566
574
  ).images[0]`,
567
575
  ];
568
576
  const diffusers = (model) => {
577
+ // the Hub emits pipeline class tags as `diffusers:<ClassName>`; bare names are kept for manually added tags
578
+ const hasPipelineClass = (className) => model.tags.includes(`diffusers:${className}`) ||
579
+ model.tags.includes(className) ||
580
+ model.config?.diffusers?._class_name === className;
569
581
  let codeSnippets;
570
- if (model.tags.includes("StableDiffusionInpaintPipeline") ||
571
- model.tags.includes("StableDiffusionXLInpaintPipeline")) {
582
+ if (hasPipelineClass("StableDiffusionInpaintPipeline") || hasPipelineClass("StableDiffusionXLInpaintPipeline")) {
572
583
  codeSnippets = diffusers_inpainting(model);
573
584
  }
574
585
  else if (model.tags.includes("controlnet")) {
@@ -591,7 +602,7 @@ const diffusers = (model) => {
591
602
  else if (model.tags.includes("textual_inversion")) {
592
603
  codeSnippets = diffusers_textual_inversion(model);
593
604
  }
594
- else if (model.tags.includes("FluxFillPipeline")) {
605
+ else if (hasPipelineClass("FluxFillPipeline")) {
595
606
  codeSnippets = diffusers_flux_fill(model);
596
607
  }
597
608
  else if (model.pipeline_tag === "image-to-video") {
@@ -613,7 +624,7 @@ from diffusionkit.mlx import DiffusionPipeline
613
624
  pipeline = DiffusionPipeline(
614
625
  shift=3.0,
615
626
  use_t5=False,
616
- model_version=${model.id},
627
+ model_version="${model.id}",
617
628
  low_memory_mode=True,
618
629
  a16=True,
619
630
  w16=True,
@@ -623,7 +634,7 @@ from diffusionkit.mlx import FluxPipeline
623
634
 
624
635
  pipeline = FluxPipeline(
625
636
  shift=1.0,
626
- model_version=${model.id},
637
+ model_version="${model.id}",
627
638
  low_memory_mode=True,
628
639
  a16=True,
629
640
  w16=True,
@@ -645,21 +656,22 @@ image, _ = pipeline.generate_image(
645
656
  };
646
657
  exports.diffusionkit = diffusionkit;
647
658
  const cartesia_pytorch = (model) => [
648
- `# pip install --no-binary :all: cartesia-pytorch
649
- from cartesia_pytorch import ReneLMHeadModel
659
+ `# The cartesia-pytorch package on PyPI ships no code: clone the repo and put its cartesia-pytorch folder on PYTHONPATH
660
+ # (it needs an Ampere or newer CUDA GPU, torch 2.4, mamba-ssm 2.2.2 and flash-attn 2.6.3)
661
+ # git clone https://github.com/cartesia-ai/edge && export PYTHONPATH="$PWD/edge/cartesia-pytorch:$PYTHONPATH"
662
+ from cartesia_pytorch.Rene import ReneLMHeadModel
650
663
  from transformers import AutoTokenizer
651
664
 
652
- model = ReneLMHeadModel.from_pretrained("${model.id}")
665
+ model = ReneLMHeadModel.from_pretrained("${model.id}").half().cuda()
653
666
  tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-1B-hf")
654
667
 
655
668
  in_message = ["Rene Descartes was"]
656
669
  inputs = tokenizer(in_message, return_tensors="pt")
657
670
 
658
- outputs = model.generate(inputs.input_ids, max_length=50, top_k=100, top_p=0.99)
671
+ outputs = model.generate(inputs.input_ids.cuda(), max_length=50, top_k=100, top_p=0.99)
659
672
  out_message = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
660
673
 
661
- print(out_message)
662
- )`,
674
+ print(out_message)`,
663
675
  ];
664
676
  exports.cartesia_pytorch = cartesia_pytorch;
665
677
  const cartesia_mlx = (model) => [
@@ -710,7 +722,8 @@ speech, *_ = model("text to generate speech from")`,
710
722
  ];
711
723
  exports.espnetTTS = espnetTTS;
712
724
  const espnetASR = (model) => [
713
- `from espnet2.bin.asr_inference import Speech2Text
725
+ `import soundfile
726
+ from espnet2.bin.asr_inference import Speech2Text
714
727
 
715
728
  model = Speech2Text.from_pretrained(
716
729
  "${model.id}"
@@ -740,9 +753,14 @@ models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
740
753
  ];
741
754
  exports.fairseq = fairseq;
742
755
  const flair = (model) => [
743
- `from flair.models import SequenceTagger
756
+ `from flair.data import Sentence
757
+ from flair.models import SequenceTagger
744
758
 
745
- tagger = SequenceTagger.load("${model.id}")`,
759
+ tagger = SequenceTagger.load("${model.id}")
760
+
761
+ sentence = Sentence("George Washington went to Washington.")
762
+ tagger.predict(sentence)
763
+ print(sentence)`,
746
764
  ];
747
765
  exports.flair = flair;
748
766
  const flexray = (model) => [
@@ -831,13 +849,20 @@ exports.gaussianformer = gaussianformer;
831
849
  const gliner = (model) => [
832
850
  `from gliner import GLiNER
833
851
 
834
- model = GLiNER.from_pretrained("${model.id}")`,
852
+ model = GLiNER.from_pretrained("${model.id}")
853
+
854
+ text = "Cristiano Ronaldo dos Santos Aveiro was born on 5 February 1985 in Funchal, Madeira, Portugal."
855
+ labels = ["person", "date", "location"]
856
+
857
+ entities = model.predict_entities(text, labels)
858
+ for entity in entities:
859
+ print(entity["text"], "=>", entity["label"])`,
835
860
  ];
836
861
  exports.gliner = gliner;
837
862
  const gliner2 = (model) => [
838
- `from gliner2 import GLiNER2
863
+ `from gliner2 import AutoExtractor
839
864
 
840
- model = GLiNER2.from_pretrained("${model.id}")
865
+ extractor = AutoExtractor.from_pretrained("${model.id}")
841
866
 
842
867
  # Extract entities
843
868
  text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday."
@@ -850,7 +875,7 @@ const indextts = (model) => [
850
875
  `# Download model
851
876
  from huggingface_hub import snapshot_download
852
877
 
853
- snapshot_download(${model.id}, local_dir="checkpoints")
878
+ snapshot_download("${model.id}", local_dir="checkpoints")
854
879
 
855
880
  from indextts.infer import IndexTTS
856
881
 
@@ -907,9 +932,11 @@ print(out["answers"]["team"]["choice"])`,
907
932
  };
908
933
  exports.jev_style = jev_style;
909
934
  const keras = (model) => [
910
- `# Available backend options are: "jax", "torch", "tensorflow".
935
+ `# !pip install -U keras tensorflow huggingface_hub
936
+ # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here;
937
+ # "jax" and "torch" also work for computation once TensorFlow is installed.
911
938
  import os
912
- os.environ["KERAS_BACKEND"] = "jax"
939
+ os.environ["KERAS_BACKEND"] = "tensorflow"
913
940
 
914
941
  import keras
915
942
 
@@ -1026,13 +1053,15 @@ const kernels = (model) => [
1026
1053
 
1027
1054
  from kernels import get_kernel
1028
1055
 
1029
- kernel = get_kernel("${model.id}")`,
1056
+ # a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones
1057
+ kernel = get_kernel("${model.id}", version=1)`,
1030
1058
  ];
1031
1059
  exports.kernels = kernels;
1032
1060
  const kimi_audio = (model) => [
1033
1061
  `# Example usage for KimiAudio
1034
- # pip install git+https://github.com/MoonshotAI/Kimi-Audio.git
1062
+ # pip install git+https://github.com/MoonshotAI/Kimi-Audio.git "transformers<5"
1035
1063
 
1064
+ import soundfile as sf
1036
1065
  from kimia_infer.api.kimia import KimiAudio
1037
1066
 
1038
1067
  model = KimiAudio(model_path="${model.id}", load_detokenizer=True)
@@ -1402,14 +1431,17 @@ pip install -U litert-lm
1402
1431
 
1403
1432
  # 2. Download and run this model locally:
1404
1433
  # See: https://ai.google.dev/edge/litert-lm/cli
1434
+ # A single .litertlm file in the repo is picked automatically; otherwise the CLI asks which one to run
1435
+ # (or pass its name right after the repo id).
1405
1436
  litert-lm run \\
1406
1437
  --from-huggingface-repo=${model.id} \\
1407
1438
  --prompt="Write me a poem"`,
1408
1439
  ];
1409
1440
  exports.litert_lm = litert_lm;
1410
1441
  const tf_keras = (model) => [
1411
- `# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
1442
+ `# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0.
1412
1443
  # See https://github.com/keras-team/tf-keras for more details.
1444
+ # !pip install "huggingface_hub<1.0" tf_keras
1413
1445
  from huggingface_hub import from_pretrained_keras
1414
1446
 
1415
1447
  model = from_pretrained_keras("${model.id}")
@@ -1461,6 +1493,17 @@ from MeshAnything.models.meshanything import MeshAnything
1461
1493
  model = MeshAnything(args)`,
1462
1494
  ];
1463
1495
  exports.mesh_anything = mesh_anything;
1496
+ const microduck = (model) => {
1497
+ // Model-card tag convention: tags: [microduck-slot:stand].
1498
+ const slots = ["walk", "stand", "sitstand", "ground_pick", "kick_left", "kick_right", "roulade"];
1499
+ const matchingSlots = slots.filter((slot) => model.tags.includes(`microduck-slot:${slot}`));
1500
+ const slot = matchingSlots.length === 1 ? matchingSlots[0] : "SLOT";
1501
+ const prefix = matchingSlots.length === 1
1502
+ ? ""
1503
+ : `# Replace SLOT with the slot specified in the model card (${slots.join(", ")}).\n`;
1504
+ return [`${prefix}sudo robotctl policy load ${slot} ${model.id}`];
1505
+ };
1506
+ exports.microduck = microduck;
1464
1507
  const multimolecule = (model) => {
1465
1508
  const widgetExample = model.widgetData?.[0];
1466
1509
  const exampleText = escapeStringForJson(widgetExample?.text ?? "");
@@ -1641,14 +1684,18 @@ model = pe.VisionTransformer.from_config("${model.id}", pretrained=True)`;
1641
1684
  exports.perception_encoder = perception_encoder;
1642
1685
  const phantom_wan = (model) => [
1643
1686
  `from huggingface_hub import snapshot_download
1644
- from phantom_wan import WANI2V, configs
1687
+ from phantom_wan import WanI2V, configs
1688
+ from PIL import Image
1645
1689
 
1646
1690
  checkpoint_dir = snapshot_download("${model.id}")
1647
1691
  wan_i2v = WanI2V(
1648
- config=configs.WAN_CONFIGS['i2v-14B'],
1649
- checkpoint_dir=checkpoint_dir,
1650
- )
1651
- video = wan_i2v.generate(text_prompt, image_prompt)`,
1692
+ config=configs.WAN_CONFIGS['i2v-14B'],
1693
+ checkpoint_dir=checkpoint_dir,
1694
+ )
1695
+
1696
+ text_prompt = "A cat playing with a ball of yarn"
1697
+ image_prompt = Image.open("path/to/image.jpg").convert("RGB")
1698
+ video = wan_i2v.generate(text_prompt, image_prompt)`,
1652
1699
  ];
1653
1700
  exports.phantom_wan = phantom_wan;
1654
1701
  const pocket_tts = (model) => [
@@ -1770,7 +1817,7 @@ exports.tensorflowtts = tensorflowtts;
1770
1817
  const timm = (model) => [
1771
1818
  `import timm
1772
1819
 
1773
- model = timm.create_model("hf_hub:${model.id}", pretrained=True)`,
1820
+ model = timm.create_model("hf-hub:${model.id}", pretrained=True)`,
1774
1821
  ];
1775
1822
  exports.timm = timm;
1776
1823
  const saelens = ( /* model: ModelData */) => [
@@ -1798,13 +1845,14 @@ seed_story_cfg = OmegaConf.load(seed_story_cfg_path)
1798
1845
  seed_story = hydra.utils.instantiate(seed_story_cfg, llm=llm) `,
1799
1846
  ];
1800
1847
  exports.seed_story = seed_story;
1801
- const skopsPickle = (model, modelFile) => {
1848
+ const SKLEARN_PICKLE_FILE = /\.(joblib|pkl|pickle)$/i;
1849
+ // skops.hub_utils was removed in skops 0.12, so files are downloaded with huggingface_hub
1850
+ const sklearnPickle = (model, modelFile) => {
1802
1851
  return [
1803
- `import joblib
1804
- from skops.hub_utils import download
1805
- download("${model.id}", "path_to_folder")
1852
+ `from huggingface_hub import hf_hub_download
1853
+ import joblib
1806
1854
  model = joblib.load(
1807
- "${escapeStringForJson(modelFile)}"
1855
+ hf_hub_download("${model.id}", "${escapeStringForJson(modelFile)}")
1808
1856
  )
1809
1857
  # only load pickle files from sources you trust
1810
1858
  # read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
@@ -1812,42 +1860,28 @@ model = joblib.load(
1812
1860
  };
1813
1861
  const skopsFormat = (model, modelFile) => {
1814
1862
  return [
1815
- `from skops.hub_utils import download
1863
+ `from huggingface_hub import hf_hub_download
1816
1864
  from skops.io import load
1817
- download("${model.id}", "path_to_folder")
1818
1865
  # make sure model file is in skops format
1819
1866
  # if model is a pickle file, make sure it's from a source you trust
1820
- model = load("path_to_folder/${escapeStringForJson(modelFile)}")`,
1821
- ];
1822
- };
1823
- const skopsJobLib = (model) => {
1824
- return [
1825
- `from huggingface_hub import hf_hub_download
1826
- import joblib
1827
- model = joblib.load(
1828
- hf_hub_download("${model.id}", "sklearn_model.joblib")
1829
- )
1830
- # only load pickle files from sources you trust
1831
- # read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
1867
+ model = load(hf_hub_download("${model.id}", "${escapeStringForJson(modelFile)}"))`,
1832
1868
  ];
1833
1869
  };
1834
1870
  const sklearn = (model) => {
1871
+ const declaredFile = model.config?.sklearn?.model?.file;
1835
1872
  if (model.tags.includes("skops")) {
1836
- const skopsmodelFile = model.config?.sklearn?.model?.file;
1837
- const skopssaveFormat = model.config?.sklearn?.model_format;
1838
- if (!skopsmodelFile) {
1873
+ if (!declaredFile) {
1839
1874
  return [`# ⚠️ Model filename not specified in config.json`];
1840
1875
  }
1841
- if (skopssaveFormat === "pickle") {
1842
- return skopsPickle(model, skopsmodelFile);
1843
- }
1844
- else {
1845
- return skopsFormat(model, skopsmodelFile);
1876
+ // some skops repos declare no model_format for a pickled file (e.g. julien-c/skops-digits), which skops.io cannot read
1877
+ if (model.config?.sklearn?.model_format === "pickle" || SKLEARN_PICKLE_FILE.test(declaredFile)) {
1878
+ return sklearnPickle(model, declaredFile);
1846
1879
  }
1880
+ return skopsFormat(model, declaredFile);
1847
1881
  }
1848
- else {
1849
- return skopsJobLib(model);
1850
- }
1882
+ // repos pushed without skops often still declare their filename in config.json; it is only trusted when it names a
1883
+ // pickle, since some hand-written configs carry typos (e.g. "sklean_model.jpblib" next to a real sklearn_model.joblib)
1884
+ return sklearnPickle(model, declaredFile && SKLEARN_PICKLE_FILE.test(declaredFile) ? declaredFile : "sklearn_model.joblib");
1851
1885
  };
1852
1886
  exports.sklearn = sklearn;
1853
1887
  const stable_audio_tools = (model) => [
@@ -1898,7 +1932,7 @@ const sam2 = (model) => {
1898
1932
  import torch
1899
1933
  from sam2.sam2_image_predictor import SAM2ImagePredictor
1900
1934
 
1901
- predictor = SAM2ImagePredictor.from_pretrained(${model.id})
1935
+ predictor = SAM2ImagePredictor.from_pretrained("${model.id}")
1902
1936
 
1903
1937
  with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
1904
1938
  predictor.set_image(<your_image>)
@@ -1907,13 +1941,13 @@ with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
1907
1941
  import torch
1908
1942
  from sam2.sam2_video_predictor import SAM2VideoPredictor
1909
1943
 
1910
- predictor = SAM2VideoPredictor.from_pretrained(${model.id})
1944
+ predictor = SAM2VideoPredictor.from_pretrained("${model.id}")
1911
1945
 
1912
1946
  with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
1913
1947
  state = predictor.init_state(<your_video>)
1914
1948
 
1915
1949
  # add new prompts and instantly get the output on the same frame
1916
- frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>):
1950
+ frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>)
1917
1951
 
1918
1952
  # propagate the prompts to get masklets throughout the video
1919
1953
  for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
@@ -1935,11 +1969,18 @@ output = inference(image, mask)`,
1935
1969
  ];
1936
1970
  exports.sam_3d_objects = sam_3d_objects;
1937
1971
  const sam_3d_body = (model) => [
1938
- `from notebook.utils import setup_sam_3d_body
1972
+ `import cv2
1973
+ import numpy as np
1974
+ from notebook.utils import setup_sam_3d_body
1975
+ from tools.vis_utils import visualize_sample_together
1939
1976
 
1940
- estimator = setup_sam_3d_body(${model.id})
1941
- outputs = estimator.process_one_image(image)
1942
- rend_img = visualize_sample_together(image, outputs, estimator.faces)`,
1977
+ estimator = setup_sam_3d_body("${model.id}")
1978
+
1979
+ img_bgr = cv2.imread("path/to/image.jpg")
1980
+ outputs = estimator.process_one_image(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
1981
+
1982
+ rend_img = visualize_sample_together(img_bgr, outputs, estimator.faces)
1983
+ cv2.imwrite("output.jpg", rend_img.astype(np.uint8))`,
1943
1984
  ];
1944
1985
  exports.sam_3d_body = sam_3d_body;
1945
1986
  const sampleFactory = (model) => [
@@ -2033,7 +2074,15 @@ queries_emb = model.encode(queries, is_query=True)
2033
2074
  docs_emb = model.encode(documents, is_query=False)`,
2034
2075
  ];
2035
2076
  }
2036
- if (model.tags.includes("cross-encoder") || model.pipeline_tag == "text-ranking") {
2077
+ // Rerankers saved in the CrossEncoder format are often tagged text-classification rather than text-ranking;
2078
+ // their architecture still identifies them (e.g. BAAI/bge-reranker-v2-m3). SetFit models can share that shape but
2079
+ // are bi-encoders with a separate head.
2080
+ const isCrossEncoder = model.tags.includes("cross-encoder") ||
2081
+ model.pipeline_tag == "text-ranking" ||
2082
+ (model.pipeline_tag === "text-classification" &&
2083
+ !model.tags.includes("setfit") &&
2084
+ (model.config?.architectures ?? []).some((arch) => arch.endsWith("ForSequenceClassification")));
2085
+ if (isCrossEncoder) {
2037
2086
  return [
2038
2087
  `from sentence_transformers import CrossEncoder
2039
2088
 
@@ -2051,6 +2100,33 @@ scores = model.predict([(query, passage) for passage in passages])
2051
2100
  print(scores)`,
2052
2101
  ];
2053
2102
  }
2103
+ // sentence-transformers tags SparseEncoder repos (SPLADE & co) with "sparse-encoder" and MultiVectorEncoder repos
2104
+ // (ColBERT & co) with "multi-vector" when pushing them; both encode queries and documents separately
2105
+ const retrievalEncoder = model.tags.includes("sparse-encoder")
2106
+ ? "SparseEncoder"
2107
+ : model.tags.includes("multi-vector")
2108
+ ? "MultiVectorEncoder"
2109
+ : undefined;
2110
+ if (retrievalEncoder) {
2111
+ return [
2112
+ `from sentence_transformers import ${retrievalEncoder}
2113
+
2114
+ model = ${retrievalEncoder}("${model.id}"${remote_code_snippet})
2115
+
2116
+ queries = ["Which planet is known as the Red Planet?"]
2117
+ documents = [
2118
+ "Venus is often called Earth's twin because of its similar size and proximity.",
2119
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
2120
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
2121
+ ]
2122
+
2123
+ query_embeddings = model.encode_query(queries)
2124
+ document_embeddings = model.encode_document(documents)
2125
+
2126
+ similarities = model.similarity(query_embeddings, document_embeddings)
2127
+ print(similarities)`,
2128
+ ];
2129
+ }
2054
2130
  const exampleSentences = get_widget_examples_from_st_model(model) ?? [
2055
2131
  "The weather is lovely today.",
2056
2132
  "It's so sunny outside!",
@@ -2073,7 +2149,10 @@ exports.sentenceTransformers = sentenceTransformers;
2073
2149
  const setfit = (model) => [
2074
2150
  `from setfit import SetFitModel
2075
2151
 
2076
- model = SetFitModel.from_pretrained("${model.id}")`,
2152
+ model = SetFitModel.from_pretrained("${model.id}")
2153
+
2154
+ preds = model.predict(["i loved the spiderman movie!", "pineapple on pizza is the worst"])
2155
+ print(preds)`,
2077
2156
  ];
2078
2157
  exports.setfit = setfit;
2079
2158
  const spacy = (model) => [
@@ -2091,7 +2170,10 @@ exports.spacy = spacy;
2091
2170
  const span_marker = (model) => [
2092
2171
  `from span_marker import SpanMarkerModel
2093
2172
 
2094
- model = SpanMarkerModel.from_pretrained("${model.id}")`,
2173
+ model = SpanMarkerModel.from_pretrained("${model.id}")
2174
+
2175
+ entities = model.predict("Amelia Earhart flew her single engine Lockheed Vega 5B across the Atlantic to Paris.")
2176
+ print(entities)`,
2095
2177
  ];
2096
2178
  exports.span_marker = span_marker;
2097
2179
  const stanza = (model) => [
@@ -2112,6 +2194,8 @@ const speechBrainMethod = (speechbrainInterface) => {
2112
2194
  return "enhance_file";
2113
2195
  case "SepformerSeparation":
2114
2196
  return "separate_file";
2197
+ case "SpeakerRecognition":
2198
+ return "verify_files";
2115
2199
  default:
2116
2200
  return undefined;
2117
2201
  }
@@ -2125,12 +2209,14 @@ const speechbrain = (model) => {
2125
2209
  if (speechbrainMethod === undefined) {
2126
2210
  return [`# interface in config.json invalid`];
2127
2211
  }
2212
+ // speaker verification compares two recordings
2213
+ const methodArgs = speechbrainMethod === "verify_files" ? '"speaker1.wav", "speaker2.wav"' : '"file.wav"';
2128
2214
  return [
2129
2215
  `from speechbrain.pretrained import ${speechbrainInterface}
2130
2216
  model = ${speechbrainInterface}.from_hparams(
2131
2217
  "${model.id}"
2132
2218
  )
2133
- model.${speechbrainMethod}("file.wav")`,
2219
+ model.${speechbrainMethod}(${methodArgs})`,
2134
2220
  ];
2135
2221
  };
2136
2222
  exports.speechbrain = speechbrain;
@@ -2162,7 +2248,7 @@ const transformers = (model) => {
2162
2248
  : info.processor === "AutoFeatureExtractor"
2163
2249
  ? "extractor"
2164
2250
  : "processor";
2165
- autoSnippet.push("# Load model directly", `from transformers import ${info.processor}, ${auto_model}`, "", `${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")", `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
2251
+ autoSnippet.push("# pip install -U transformers accelerate", "# Load model directly", `from transformers import ${info.processor}, ${auto_model}`, "", `${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")", `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
2166
2252
  if (model.tags.includes("conversational") && hasChatTemplate(model)) {
2167
2253
  if (model.tags.includes("image-text-to-text")) {
2168
2254
  autoSnippet.push("messages = [", [
@@ -2178,19 +2264,19 @@ const transformers = (model) => {
2178
2264
  else {
2179
2265
  autoSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]");
2180
2266
  }
2181
- autoSnippet.push(`inputs = ${processorVarName}.apply_chat_template(`, " messages,", " add_generation_prompt=True,", " tokenize=True,", " return_dict=True,", ' return_tensors="pt",', ").to(model.device)", "", "outputs = model.generate(**inputs, max_new_tokens=40)", `print(${processorVarName}.decode(outputs[0][inputs["input_ids"].shape[-1]:]))`);
2267
+ autoSnippet.push(`inputs = ${processorVarName}.apply_chat_template(`, " messages,", " add_generation_prompt=True,", " tokenize=True,", " return_dict=True,", ' return_tensors="pt",', ").to(model.device)", "", "outputs = model.generate(**inputs, max_new_tokens=256)", `print(${processorVarName}.decode(outputs[0][inputs["input_ids"].shape[-1]:]))`);
2182
2268
  }
2183
2269
  }
2184
2270
  else {
2185
- autoSnippet.push("# Load model directly", `from transformers import ${auto_model}`, `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
2271
+ autoSnippet.push("# pip install -U transformers accelerate", "# Load model directly", `from transformers import ${auto_model}`, `model = ${auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ', device_map="auto")');
2186
2272
  }
2187
2273
  if (model.pipeline_tag && library_to_tasks_js_1.LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
2188
2274
  const pipelineSnippet = ["# Use a pipeline as a high-level helper"];
2189
2275
  if (library_to_tasks_js_1.REMOVED_IN_V5_TRANSFORMERS_PIPELINES.includes(model.pipeline_tag)) {
2190
- pipelineSnippet.push(`# Warning: Pipeline type "${model.pipeline_tag}" is no longer supported in transformers v5.`, `# You must load the model directly (see below) or downgrade to v4.x with:`, `# 'pip install "transformers<5.0.0'`);
2276
+ pipelineSnippet.push(`# Warning: Pipeline type "${model.pipeline_tag}" is no longer supported in transformers v5.`, `# You must load the model directly (see below) or downgrade to v4.x with:`, `# pip install "transformers<5.0.0"`);
2191
2277
  }
2192
2278
  pipelineSnippet.push("from transformers import pipeline", "", `pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")");
2193
- if (model.tags.includes("conversational")) {
2279
+ if (model.tags.includes("conversational") && hasChatTemplate(model)) {
2194
2280
  if (model.tags.includes("image-text-to-text")) {
2195
2281
  pipelineSnippet.push("messages = [", [
2196
2282
  " {",
@@ -2219,48 +2305,119 @@ const transformers = (model) => {
2219
2305
  return [autoSnippet.join("\n")];
2220
2306
  };
2221
2307
  exports.transformers = transformers;
2308
+ // Hub tasks that transformers.js exposes under a different pipeline() task name
2309
+ const TRANSFORMERS_JS_TASK_ALIASES = {
2310
+ "sentence-similarity": "feature-extraction",
2311
+ };
2222
2312
  const transformersJS = (model) => {
2223
2313
  if (!model.pipeline_tag) {
2224
2314
  return [`// ⚠️ Unknown pipeline tag`];
2225
2315
  }
2226
2316
  const libName = "@huggingface/transformers";
2317
+ // Rerankers score (query, document) pairs. The text-classification pipeline cannot take pairs and applies a softmax
2318
+ // over their single logit, so every score comes out as 1; the model is called directly instead.
2319
+ if (model.pipeline_tag === "text-ranking") {
2320
+ return [
2321
+ `// npm i ${libName}
2322
+ import { AutoTokenizer, AutoModelForSequenceClassification } from '${libName}';
2323
+
2324
+ const tokenizer = await AutoTokenizer.from_pretrained('${model.id}');
2325
+ const model = await AutoModelForSequenceClassification.from_pretrained('${model.id}');
2326
+
2327
+ const query = 'Which planet is known as the Red Planet?';
2328
+ const documents = [
2329
+ 'Mars, known for its reddish appearance, is often referred to as the Red Planet.',
2330
+ 'Venus is often called the twin of Earth because of its similar size and proximity.',
2331
+ ];
2332
+
2333
+ const inputs = tokenizer(new Array(documents.length).fill(query), { text_pair: documents, padding: true, truncation: true });
2334
+ const { logits } = await model(inputs);
2335
+ console.log(logits.sigmoid().tolist()); // one relevance score per document`,
2336
+ ];
2337
+ }
2338
+ const task = TRANSFORMERS_JS_TASK_ALIASES[model.pipeline_tag] ?? model.pipeline_tag;
2227
2339
  return [
2228
2340
  `// npm i ${libName}
2229
2341
  import { pipeline } from '${libName}';
2230
2342
 
2231
2343
  // Allocate pipeline
2232
- const pipe = await pipeline('${model.pipeline_tag}', '${model.id}');`,
2344
+ const pipe = await pipeline('${task}', '${model.id}');`,
2233
2345
  ];
2234
2346
  };
2235
2347
  exports.transformersJS = transformersJS;
2236
- const peftTask = (peftTaskType) => {
2237
- switch (peftTaskType) {
2238
- case "CAUSAL_LM":
2239
- return "CausalLM";
2240
- case "SEQ_2_SEQ_LM":
2241
- return "Seq2SeqLM";
2242
- case "TOKEN_CLS":
2243
- return "TokenClassification";
2244
- case "SEQ_CLS":
2245
- return "SequenceClassification";
2246
- default:
2247
- return undefined;
2248
- }
2348
+ const PEFT_TASK_TYPE_TO_AUTO_CLASS = {
2349
+ CAUSAL_LM: "AutoModelForCausalLM",
2350
+ SEQ_2_SEQ_LM: "AutoModelForSeq2SeqLM",
2351
+ TOKEN_CLS: "AutoModelForTokenClassification",
2352
+ SEQ_CLS: "AutoModelForSequenceClassification",
2353
+ QUESTION_ANS: "AutoModelForQuestionAnswering",
2354
+ // transformers has no AutoModelForFeatureExtraction; PEFT's own AutoPeftModelForFeatureExtraction resolves to AutoModel
2355
+ FEATURE_EXTRACTION: "AutoModel",
2356
+ };
2357
+ // PEFT has no speech-specific task type: Whisper-style adapters are tagged SEQ_2_SEQ_LM, but transformers registers
2358
+ // Whisper and Speech2Text only under AutoModelForSpeechSeq2Seq (SeamlessM4T is under both seq2seq auto classes, SpeechT5
2359
+ // under the speech-to-text and text-to-spectrogram ones).
2360
+ // Other audio seq2seq models (Qwen2-Audio, GLM-ASR) stay under AutoModelForSeq2SeqLM, so the base model name is the
2361
+ // main signal. Matched against Hub repo ids, which are hyphenated (facebook/s2t-small-librispeech-asr,
2362
+ // facebook/seamless-m4t-v2-large), not against transformers model_type identifiers.
2363
+ const PEFT_SPEECH_TO_TEXT_BASE_MODEL = /whisper|\bs2t\b|speech[-_]to[-_]text/i;
2364
+ // SeamlessM4T also has a text-to-text head under AutoModelForSeq2SeqLM, which text translation adapters need; most
2365
+ // SeamlessM4T adapters on the Hub are speech ones, so the speech class stays the default when no text task is declared.
2366
+ const PEFT_SEAMLESS_M4T_BASE_MODEL = /seamless[-_]m4t/i;
2367
+ const PEFT_TEXT_TASKS = ["translation", "text2text-generation", "summarization"];
2368
+ // SpeechT5 checkpoints are overwhelmingly text-to-speech fine-tunes (often without "tts" in their name), which load
2369
+ // with AutoModelForTextToSpectrogram; AutoModelForSpeechSeq2Seq would silently load the speech-to-text head, so only
2370
+ // ASR bases or adapters get it.
2371
+ const PEFT_SPEECHT5_BASE_MODEL = /speecht5/i;
2372
+ const declaresTask = (model, task) => model.pipeline_tag === task || model.tags.includes(task);
2373
+ // the auto class a SEQ_2_SEQ_LM adapter needs when its base is a speech model, undefined for text seq2seq bases
2374
+ const peftSpeechAutoClass = (model, baseModel) => {
2375
+ if (PEFT_SPEECH_TO_TEXT_BASE_MODEL.test(baseModel)) {
2376
+ return "AutoModelForSpeechSeq2Seq";
2377
+ }
2378
+ if (PEFT_SEAMLESS_M4T_BASE_MODEL.test(baseModel)) {
2379
+ return PEFT_TEXT_TASKS.some((task) => declaresTask(model, task)) ? undefined : "AutoModelForSpeechSeq2Seq";
2380
+ }
2381
+ if (PEFT_SPEECHT5_BASE_MODEL.test(baseModel)) {
2382
+ const isAsr = /(?:^|[^a-z])asr(?:[^a-z]|$)/i.test(baseModel) || declaresTask(model, "automatic-speech-recognition");
2383
+ return isAsr ? "AutoModelForSpeechSeq2Seq" : "AutoModelForTextToSpectrogram";
2384
+ }
2385
+ return undefined;
2249
2386
  };
2250
2387
  const peft = (model) => {
2251
2388
  const { base_model_name_or_path: peftBaseModel, task_type: peftTaskType } = model.config?.peft ?? {};
2252
- const pefttask = peftTask(peftTaskType);
2253
- if (!pefttask) {
2389
+ let autoClass = peftTaskType ? PEFT_TASK_TYPE_TO_AUTO_CLASS[peftTaskType] : undefined;
2390
+ if (!autoClass) {
2254
2391
  return [`Task type is invalid.`];
2255
2392
  }
2256
- if (!peftBaseModel) {
2393
+ // adapter_config.json sometimes omits the base model; the model card's base_model is the next best source
2394
+ const cardBaseModel = Array.isArray(model.cardData?.base_model)
2395
+ ? model.cardData.base_model[0]
2396
+ : model.cardData?.base_model;
2397
+ const baseModel = peftBaseModel || cardBaseModel;
2398
+ if (!baseModel) {
2257
2399
  return [`Base model is not found.`];
2258
2400
  }
2401
+ if (peftTaskType === "SEQ_2_SEQ_LM") {
2402
+ autoClass = peftSpeechAutoClass(model, baseModel) ?? autoClass;
2403
+ }
2404
+ if (autoClass === "AutoModelForTextToSpectrogram") {
2405
+ return [
2406
+ `from peft import PeftConfig, PeftModel
2407
+ from transformers import AutoModelForTextToSpectrogram
2408
+
2409
+ base_model = AutoModelForTextToSpectrogram.from_pretrained("${escapeStringForJson(baseModel)}")
2410
+ # PEFT's seq2seq wrapper needs generate(), which SpeechT5's text-to-speech model lacks: load the adapter without its task type
2411
+ config = PeftConfig.from_pretrained("${model.id}")
2412
+ config.task_type = None
2413
+ model = PeftModel.from_pretrained(base_model, "${model.id}", config=config)`,
2414
+ ];
2415
+ }
2259
2416
  return [
2260
2417
  `from peft import PeftModel
2261
- from transformers import AutoModelFor${pefttask}
2418
+ from transformers import ${autoClass}
2262
2419
 
2263
- base_model = AutoModelFor${pefttask}.from_pretrained("${escapeStringForJson(peftBaseModel)}")
2420
+ base_model = ${autoClass}.from_pretrained("${escapeStringForJson(baseModel)}")
2264
2421
  model = PeftModel.from_pretrained(base_model, "${model.id}")`,
2265
2422
  ];
2266
2423
  };
@@ -2294,7 +2451,7 @@ transcriptions = asr_model.transcribe(["file.wav"])`,
2294
2451
  }
2295
2452
  };
2296
2453
  const mlAgents = (model) => [
2297
- `mlagents-load-from-hf --repo-id="${model.id}" --local-dir="./download: string[]s"`,
2454
+ `mlagents-load-from-hf --repo-id="${model.id}" --local-dir="./downloads"`,
2298
2455
  ];
2299
2456
  exports.mlAgents = mlAgents;
2300
2457
  const sentis = ( /* model: ModelData */) => [
@@ -2369,10 +2526,10 @@ model = Model.from_pretrained("${model.id}")`,
2369
2526
  exports.vfimamba = vfimamba;
2370
2527
  const lvface = (model) => [
2371
2528
  `from huggingface_hub import hf_hub_download
2372
- from inference_onnx import LVFaceONNXInferencer
2529
+ from inference_onnx import LVFaceONNXInferencer
2373
2530
 
2374
2531
  model_path = hf_hub_download("${model.id}", "LVFace-L_Glint360K/LVFace-L_Glint360K.onnx")
2375
- inferencer = LVFaceONNXInferencer(model_path, use_gpu=True, timeout=300)
2532
+ inferencer = LVFaceONNXInferencer(model_path, use_gpu=True)
2376
2533
  img_path = 'path/to/image1.jpg'
2377
2534
  embedding = inferencer.infer_from_image(img_path)`,
2378
2535
  ];
@@ -2411,8 +2568,7 @@ const vui = () => [
2411
2568
 
2412
2569
  import torchaudio
2413
2570
 
2414
- from vui.inference import render
2415
- from vui.model import Vui,
2571
+ from vui.legacy import Vui, render
2416
2572
 
2417
2573
  model = Vui.from_pretrained().cuda()
2418
2574
  waveform = render(
@@ -2420,16 +2576,17 @@ waveform = render(
2420
2576
  "Hey, here is some random stuff, usually something quite long as the shorter the text the less likely the model can cope!",
2421
2577
  )
2422
2578
  print(waveform.shape)
2423
- torchaudio.save("out.opus", waveform[0], 22050)
2579
+ torchaudio.save("out.wav", waveform[0], 22050)
2424
2580
  `,
2425
2581
  ];
2426
2582
  exports.vui = vui;
2427
2583
  const chattts = () => [
2428
2584
  `import ChatTTS
2585
+ import torch
2429
2586
  import torchaudio
2430
2587
 
2431
2588
  chat = ChatTTS.Chat()
2432
- chat.load_models(compile=False) # Set to True for better performance
2589
+ chat.load(compile=False) # Set to True for better performance
2433
2590
 
2434
2591
  texts = ["PUT YOUR TEXT HERE",]
2435
2592
 
@@ -2439,17 +2596,42 @@ torchaudio.save("output1.wav", torch.from_numpy(wavs[0]), 24000)`,
2439
2596
  ];
2440
2597
  exports.chattts = chattts;
2441
2598
  const ultralytics = (model) => {
2442
- // ultralytics models must have a version tag (e.g. `yolov8`)
2443
- const versionTag = model.tags.find((tag) => tag.match(/^yolov\d+$/));
2444
- const className = versionTag ? `YOLOv${versionTag.slice(4)}` : "YOLOvXX";
2445
- const prefix = versionTag
2446
- ? ""
2447
- : `# Couldn't find a valid YOLO version tag.\n# Replace XX with the correct version.\n`;
2599
+ // the YOLOv10 fork (library "yolov10") ships its own `YOLOv10` class with a `from_pretrained` helper that reads the
2600
+ // model.safetensors it pushes. Mainline ultralytics repos often list "yolov10" among their version tags
2601
+ // (e.g. Ultralytics/YOLOv8) but only ship .pt files, so an ultralytics tag alone keeps them on the mainline loader;
2602
+ // fork pushes still tagged ultralytics are recognized by their safetensors weights.
2603
+ const isYolov10Fork = model.library_name === "yolov10" ||
2604
+ (model.tags.includes("yolov10") && (!model.tags.includes("ultralytics") || model.tags.includes("safetensors")));
2605
+ if (isYolov10Fork) {
2606
+ // from_pretrained reads the model.safetensors that fork pushes ship; older fork repos only ship .pt weights
2607
+ if (model.tags.includes("safetensors")) {
2608
+ return [
2609
+ `from ultralytics import YOLOv10
2610
+
2611
+ model = YOLOv10.from_pretrained("${model.id}")
2612
+ source = 'http://images.cocodataset.org/val2017/000000039769.jpg'
2613
+ model.predict(source=source, save=True)`,
2614
+ ];
2615
+ }
2616
+ return [
2617
+ `from huggingface_hub import hf_hub_download
2618
+ from ultralytics import YOLOv10
2619
+
2620
+ # pick the weights file from this repo's "Files and versions" tab
2621
+ weights = hf_hub_download("${model.id}", "<weights>.pt")
2622
+ model = YOLOv10(weights)
2623
+ source = 'http://images.cocodataset.org/val2017/000000039769.jpg'
2624
+ model.predict(source=source, save=True)`,
2625
+ ];
2626
+ }
2627
+ // mainline ultralytics loads weights from a local file
2448
2628
  return [
2449
- prefix +
2450
- `from ultralytics import ${className}
2629
+ `from huggingface_hub import hf_hub_download
2630
+ from ultralytics import YOLO
2451
2631
 
2452
- model = ${className}.from_pretrained("${model.id}")
2632
+ # pick the weights file from this repo's "Files and versions" tab
2633
+ weights = hf_hub_download("${model.id}", "<weights>.pt")
2634
+ model = YOLO(weights)
2453
2635
  source = 'http://images.cocodataset.org/val2017/000000039769.jpg'
2454
2636
  model.predict(source=source, save=True)`,
2455
2637
  ];
@@ -2527,14 +2709,16 @@ model = SwarmFormerModel.from_pretrained("${model.id}")
2527
2709
  exports.swarmformer = swarmformer;
2528
2710
  const univa = (model) => [
2529
2711
  `# Follow installation instructions at https://github.com/PKU-YuanGroup/UniWorld-V1
2530
-
2712
+ import torch
2713
+ from transformers import AutoProcessor
2531
2714
  from univa.models.qwen2p5vl.modeling_univa_qwen2p5vl import UnivaQwen2p5VLForConditionalGeneration
2532
- model = UnivaQwen2p5VLForConditionalGeneration.from_pretrained(
2533
- "${model.id}",
2534
- torch_dtype=torch.bfloat16,
2535
- attn_implementation="flash_attention_2",
2536
- ).to("cuda")
2537
- processor = AutoProcessor.from_pretrained("${model.id}")
2715
+
2716
+ model = UnivaQwen2p5VLForConditionalGeneration.from_pretrained(
2717
+ "${model.id}",
2718
+ torch_dtype=torch.bfloat16,
2719
+ attn_implementation="flash_attention_2",
2720
+ ).to("cuda")
2721
+ processor = AutoProcessor.from_pretrained("${model.id}")
2538
2722
  `,
2539
2723
  ];
2540
2724
  exports.univa = univa;
@@ -2542,7 +2726,7 @@ const mlx_unknown = (model) => [
2542
2726
  `# Download the model from the Hub
2543
2727
  pip install huggingface_hub[hf_xet]
2544
2728
 
2545
- huggingface-cli download --local-dir ${nameWithoutNamespace(model.id)} ${model.id}`,
2729
+ hf download ${model.id} --local-dir ${nameWithoutNamespace(model.id)}`,
2546
2730
  ];
2547
2731
  const mlxlm = (model) => [
2548
2732
  `# Make sure mlx-lm is installed
@@ -2599,10 +2783,11 @@ formatted_prompt = apply_chat_template(
2599
2783
  output = generate(model, processor, formatted_prompt, image)
2600
2784
  print(output)`,
2601
2785
  ];
2786
+ // create_model() takes a name from the mlx-image registry, not a repo id; the weights live in "mlx-vision/<name>-mlxim"
2602
2787
  const mlxim = (model) => [
2603
2788
  `from mlxim.model import create_model
2604
2789
 
2605
- model = create_model(${model.id})`,
2790
+ model = create_model("${nameWithoutNamespace(model.id).replace(/-mlxim$/, "")}")`,
2606
2791
  ];
2607
2792
  exports.mlxim = mlxim;
2608
2793
  const mlx = (model) => {
@@ -2623,7 +2808,10 @@ exports.mlx = mlx;
2623
2808
  const model2vec = (model) => [
2624
2809
  `from model2vec import StaticModel
2625
2810
 
2626
- model = StaticModel.from_pretrained("${model.id}")`,
2811
+ model = StaticModel.from_pretrained("${model.id}")
2812
+
2813
+ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
2814
+ print(embeddings.shape)`,
2627
2815
  ];
2628
2816
  exports.model2vec = model2vec;
2629
2817
  const mobilint = (model) => {
@@ -2668,7 +2856,8 @@ const pruna = (model) => {
2668
2856
  };
2669
2857
  snippets = snippets.map(ensurePrunaModelImport);
2670
2858
  if (model.tags.includes("pruna_pro-ai")) {
2671
- return snippets.map((snippet) => snippet.replace(/\bpruna\b/g, "pruna_pro").replace(/\bPrunaModel\b/g, "PrunaProModel"));
2859
+ // only rewrite the import and the class name, never the repo id (an org name can contain "pruna")
2860
+ return snippets.map((snippet) => snippet.replace(/^from pruna import /gm, "from pruna_pro import ").replace(/\bPrunaModel\b/g, "PrunaProModel"));
2672
2861
  }
2673
2862
  return snippets;
2674
2863
  };
@@ -2728,21 +2917,19 @@ const outetts = (model) => {
2728
2917
  }
2729
2918
  // v1.0 HF → minimal runnable snippet
2730
2919
  return [
2731
- `
2732
- import outetts
2733
-
2734
- enum = outetts.Models("${model.id}".split("/", 1)[1]) # VERSION_1_0_SIZE_1B
2735
- cfg = outetts.ModelConfig.auto_config(enum, outetts.Backend.HF)
2736
- tts = outetts.Interface(cfg)
2737
-
2738
- speaker = tts.load_default_speaker("EN-FEMALE-1-NEUTRAL")
2739
- tts.generate(
2740
- outetts.GenerationConfig(
2741
- text="Hello there, how are you doing?",
2742
- speaker=speaker,
2743
- )
2744
- ).save("output.wav")
2745
- `,
2920
+ `import outetts
2921
+
2922
+ enum = outetts.Models("${model.id}".split("/", 1)[1]) # VERSION_1_0_SIZE_1B
2923
+ cfg = outetts.ModelConfig.auto_config(enum, outetts.Backend.HF)
2924
+ tts = outetts.Interface(cfg)
2925
+
2926
+ speaker = tts.load_default_speaker("EN-FEMALE-1-NEUTRAL")
2927
+ tts.generate(
2928
+ outetts.GenerationConfig(
2929
+ text="Hello there, how are you doing?",
2930
+ speaker=speaker,
2931
+ )
2932
+ ).save("output.wav")`,
2746
2933
  ];
2747
2934
  };
2748
2935
  exports.outetts = outetts;