@huggingface/tasks 0.21.54 → 0.21.56
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/commonjs/hardware-amd.d.ts.map +1 -1
- package/dist/commonjs/hardware-amd.js +48 -0
- package/dist/commonjs/hardware-nvidia.d.ts +1 -0
- package/dist/commonjs/hardware-nvidia.d.ts.map +1 -1
- package/dist/commonjs/hardware-nvidia.js +122 -0
- package/dist/commonjs/library-to-tasks.d.ts.map +1 -1
- package/dist/commonjs/library-to-tasks.js +8 -1
- package/dist/commonjs/model-libraries-snippets.d.ts +3 -1
- package/dist/commonjs/model-libraries-snippets.d.ts.map +1 -1
- package/dist/commonjs/model-libraries-snippets.js +349 -154
- package/dist/commonjs/model-libraries-snippets.spec.js +300 -0
- package/dist/commonjs/model-libraries.d.ts +11 -2
- package/dist/commonjs/model-libraries.d.ts.map +1 -1
- package/dist/commonjs/model-libraries.js +10 -1
- package/dist/esm/hardware-amd.d.ts.map +1 -1
- package/dist/esm/hardware-amd.js +48 -0
- package/dist/esm/hardware-nvidia.d.ts +1 -0
- package/dist/esm/hardware-nvidia.d.ts.map +1 -1
- package/dist/esm/hardware-nvidia.js +122 -0
- package/dist/esm/library-to-tasks.d.ts.map +1 -1
- package/dist/esm/library-to-tasks.js +8 -1
- package/dist/esm/model-libraries-snippets.d.ts +3 -1
- package/dist/esm/model-libraries-snippets.d.ts.map +1 -1
- package/dist/esm/model-libraries-snippets.js +344 -151
- package/dist/esm/model-libraries-snippets.spec.js +301 -1
- package/dist/esm/model-libraries.d.ts +11 -2
- package/dist/esm/model-libraries.d.ts.map +1 -1
- package/dist/esm/model-libraries.js +10 -1
- package/package.json +1 -1
- package/src/hardware-amd.ts +48 -0
- package/src/hardware-nvidia.ts +122 -0
- package/src/library-to-tasks.ts +8 -1
- package/src/model-libraries-snippets.spec.ts +389 -0
- package/src/model-libraries-snippets.ts +364 -149
- package/src/model-libraries.ts +10 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
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;
|
|
3
|
+
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.asimov = exports.araclip = exports.allennlp = exports.adapters = void 0;
|
|
4
|
+
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 = exports.litert_lm = 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 = exports.videoprism = 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 ?? "
|
|
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;
|
|
@@ -48,6 +48,14 @@ const araclip = (model) => [
|
|
|
48
48
|
model = AraClip.from_pretrained("${model.id}")`,
|
|
49
49
|
];
|
|
50
50
|
exports.araclip = araclip;
|
|
51
|
+
const asimov = (model) => [
|
|
52
|
+
`# Run the policy in a browser simulation of the Asimov 1 humanoid (no GPU needed)
|
|
53
|
+
git clone https://github.com/menloresearch/humanoid-policy-viewer
|
|
54
|
+
cd humanoid-policy-viewer
|
|
55
|
+
npm install
|
|
56
|
+
npm run hf ${model.id}`,
|
|
57
|
+
];
|
|
58
|
+
exports.asimov = asimov;
|
|
51
59
|
const asteroid = (model) => [
|
|
52
60
|
`from asteroid.models import BaseModel
|
|
53
61
|
|
|
@@ -74,7 +82,13 @@ result, message = detector.detect_watermark(watermarked_audio, sr)`;
|
|
|
74
82
|
};
|
|
75
83
|
exports.audioseal = audioseal;
|
|
76
84
|
function get_base_diffusers_model(model) {
|
|
77
|
-
|
|
85
|
+
const baseModel = model.cardData?.base_model;
|
|
86
|
+
// several base models can be listed (e.g. a LoRA trained for a base and its turbo variant). When an original checkpoint
|
|
87
|
+
// and its Diffusers conversion are both listed (["Wan-AI/Wan2.1-I2V-14B-480P", "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers"]),
|
|
88
|
+
// only the conversion has a model_index.json that DiffusionPipeline can load; otherwise the first one is used
|
|
89
|
+
const candidates = Array.isArray(baseModel) ? baseModel : baseModel ? [baseModel] : [];
|
|
90
|
+
const chosen = candidates.find((id) => id.toLowerCase().endsWith("-diffusers")) ?? candidates[0];
|
|
91
|
+
return escapeStringForJson(chosen ?? "fill-in-base-model");
|
|
78
92
|
}
|
|
79
93
|
function get_prompt_from_diffusers_model(model) {
|
|
80
94
|
const prompt = model.widgetData?.[0]?.text ?? model.cardData?.instance_prompt;
|
|
@@ -161,7 +175,7 @@ detector = cvg.NeuralCornerDetector(checkpoint)
|
|
|
161
175
|
embedder = cvg.NeuralEmbedder(checkpoint)`,
|
|
162
176
|
];
|
|
163
177
|
exports.collectorvision = collectorvision;
|
|
164
|
-
const colipri = (
|
|
178
|
+
const colipri = () => {
|
|
165
179
|
const installSnippet = `pip install colipri`;
|
|
166
180
|
const exampleSnippet = `from colipri import get_model
|
|
167
181
|
from colipri import get_processor
|
|
@@ -170,7 +184,7 @@ from colipri import ZeroShotImageClassificationPipeline
|
|
|
170
184
|
|
|
171
185
|
model = get_model().cuda()
|
|
172
186
|
processor = get_processor()
|
|
173
|
-
pipeline = ZeroShotImageClassificationPipeline(
|
|
187
|
+
pipeline = ZeroShotImageClassificationPipeline(model, processor)
|
|
174
188
|
|
|
175
189
|
image = load_sample_ct()
|
|
176
190
|
|
|
@@ -291,7 +305,7 @@ const depth_anything_v2 = (model) => {
|
|
|
291
305
|
else if (model.id === "depth-anything/Depth-Anything-V2-Large") {
|
|
292
306
|
encoder = "vitl";
|
|
293
307
|
features = "256";
|
|
294
|
-
out_channels = "[256, 512, 1024, 1024";
|
|
308
|
+
out_channels = "[256, 512, 1024, 1024]";
|
|
295
309
|
}
|
|
296
310
|
return [
|
|
297
311
|
`
|
|
@@ -300,6 +314,7 @@ const depth_anything_v2 = (model) => {
|
|
|
300
314
|
# Load the model and infer depth from an image
|
|
301
315
|
import cv2
|
|
302
316
|
import torch
|
|
317
|
+
from huggingface_hub import hf_hub_download
|
|
303
318
|
|
|
304
319
|
from depth_anything_v2.dpt import DepthAnythingV2
|
|
305
320
|
|
|
@@ -309,7 +324,8 @@ model = DepthAnythingV2(encoder="${encoder}", features=${features}, out_channels
|
|
|
309
324
|
# load the weights
|
|
310
325
|
filepath = hf_hub_download(repo_id="${model.id}", filename="depth_anything_v2_${encoder}.pth", repo_type="model")
|
|
311
326
|
state_dict = torch.load(filepath, map_location="cpu")
|
|
312
|
-
model.load_state_dict(state_dict)
|
|
327
|
+
model.load_state_dict(state_dict)
|
|
328
|
+
model.eval()
|
|
313
329
|
|
|
314
330
|
raw_img = cv2.imread("your/image/path")
|
|
315
331
|
depth = model.infer_image(raw_img) # HxW raw depth map in numpy
|
|
@@ -319,8 +335,8 @@ depth = model.infer_image(raw_img) # HxW raw depth map in numpy
|
|
|
319
335
|
exports.depth_anything_v2 = depth_anything_v2;
|
|
320
336
|
const depth_pro = (model) => {
|
|
321
337
|
const installSnippet = `# Download checkpoint
|
|
322
|
-
pip install
|
|
323
|
-
|
|
338
|
+
pip install huggingface_hub
|
|
339
|
+
hf download ${model.id} --local-dir checkpoints`;
|
|
324
340
|
const inferenceSnippet = `import depth_pro
|
|
325
341
|
|
|
326
342
|
# Load model and preprocessing transform
|
|
@@ -392,7 +408,7 @@ const describe_anything = (model) => [
|
|
|
392
408
|
from huggingface_hub import snapshot_download
|
|
393
409
|
from dam import DescribeAnythingModel
|
|
394
410
|
|
|
395
|
-
snapshot_download(${model.id}, local_dir="checkpoints")
|
|
411
|
+
snapshot_download("${model.id}", local_dir="checkpoints")
|
|
396
412
|
|
|
397
413
|
dam = DescribeAnythingModel(
|
|
398
414
|
model_path="checkpoints",
|
|
@@ -504,7 +520,7 @@ pipe.load_lora_weights("${model.id}")
|
|
|
504
520
|
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersVideoDefaultPrompt}"
|
|
505
521
|
input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png")
|
|
506
522
|
|
|
507
|
-
|
|
523
|
+
output = pipe(image=input_image, prompt=prompt).frames[0]
|
|
508
524
|
export_to_video(output, "output.mp4")`,
|
|
509
525
|
];
|
|
510
526
|
const diffusers_textual_inversion = (model) => [
|
|
@@ -544,7 +560,7 @@ from diffusers import AutoPipelineForInpainting
|
|
|
544
560
|
from diffusers.utils import load_image
|
|
545
561
|
|
|
546
562
|
# switch to "mps" for apple devices
|
|
547
|
-
pipe = AutoPipelineForInpainting.from_pretrained("${model.id}", dtype=torch.float16,
|
|
563
|
+
pipe = AutoPipelineForInpainting.from_pretrained("${model.id}", dtype=torch.float16, device_map="cuda")
|
|
548
564
|
|
|
549
565
|
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
|
|
550
566
|
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
|
|
@@ -566,9 +582,12 @@ image = pipe(
|
|
|
566
582
|
).images[0]`,
|
|
567
583
|
];
|
|
568
584
|
const diffusers = (model) => {
|
|
585
|
+
// the Hub emits pipeline class tags as `diffusers:<ClassName>`; bare names are kept for manually added tags
|
|
586
|
+
const hasPipelineClass = (className) => model.tags.includes(`diffusers:${className}`) ||
|
|
587
|
+
model.tags.includes(className) ||
|
|
588
|
+
model.config?.diffusers?._class_name === className;
|
|
569
589
|
let codeSnippets;
|
|
570
|
-
if (
|
|
571
|
-
model.tags.includes("StableDiffusionXLInpaintPipeline")) {
|
|
590
|
+
if (hasPipelineClass("StableDiffusionInpaintPipeline") || hasPipelineClass("StableDiffusionXLInpaintPipeline")) {
|
|
572
591
|
codeSnippets = diffusers_inpainting(model);
|
|
573
592
|
}
|
|
574
593
|
else if (model.tags.includes("controlnet")) {
|
|
@@ -591,7 +610,7 @@ const diffusers = (model) => {
|
|
|
591
610
|
else if (model.tags.includes("textual_inversion")) {
|
|
592
611
|
codeSnippets = diffusers_textual_inversion(model);
|
|
593
612
|
}
|
|
594
|
-
else if (
|
|
613
|
+
else if (hasPipelineClass("FluxFillPipeline")) {
|
|
595
614
|
codeSnippets = diffusers_flux_fill(model);
|
|
596
615
|
}
|
|
597
616
|
else if (model.pipeline_tag === "image-to-video") {
|
|
@@ -613,7 +632,7 @@ from diffusionkit.mlx import DiffusionPipeline
|
|
|
613
632
|
pipeline = DiffusionPipeline(
|
|
614
633
|
shift=3.0,
|
|
615
634
|
use_t5=False,
|
|
616
|
-
model_version
|
|
635
|
+
model_version="${model.id}",
|
|
617
636
|
low_memory_mode=True,
|
|
618
637
|
a16=True,
|
|
619
638
|
w16=True,
|
|
@@ -623,7 +642,7 @@ from diffusionkit.mlx import FluxPipeline
|
|
|
623
642
|
|
|
624
643
|
pipeline = FluxPipeline(
|
|
625
644
|
shift=1.0,
|
|
626
|
-
model_version
|
|
645
|
+
model_version="${model.id}",
|
|
627
646
|
low_memory_mode=True,
|
|
628
647
|
a16=True,
|
|
629
648
|
w16=True,
|
|
@@ -645,21 +664,22 @@ image, _ = pipeline.generate_image(
|
|
|
645
664
|
};
|
|
646
665
|
exports.diffusionkit = diffusionkit;
|
|
647
666
|
const cartesia_pytorch = (model) => [
|
|
648
|
-
`#
|
|
649
|
-
|
|
667
|
+
`# The cartesia-pytorch package on PyPI ships no code: clone the repo and put its cartesia-pytorch folder on PYTHONPATH
|
|
668
|
+
# (it needs an Ampere or newer CUDA GPU, torch 2.4, mamba-ssm 2.2.2 and flash-attn 2.6.3)
|
|
669
|
+
# git clone https://github.com/cartesia-ai/edge && export PYTHONPATH="$PWD/edge/cartesia-pytorch:$PYTHONPATH"
|
|
670
|
+
from cartesia_pytorch.Rene import ReneLMHeadModel
|
|
650
671
|
from transformers import AutoTokenizer
|
|
651
672
|
|
|
652
|
-
model = ReneLMHeadModel.from_pretrained("${model.id}")
|
|
673
|
+
model = ReneLMHeadModel.from_pretrained("${model.id}").half().cuda()
|
|
653
674
|
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-1B-hf")
|
|
654
675
|
|
|
655
676
|
in_message = ["Rene Descartes was"]
|
|
656
677
|
inputs = tokenizer(in_message, return_tensors="pt")
|
|
657
678
|
|
|
658
|
-
outputs = model.generate(inputs.input_ids, max_length=50, top_k=100, top_p=0.99)
|
|
679
|
+
outputs = model.generate(inputs.input_ids.cuda(), max_length=50, top_k=100, top_p=0.99)
|
|
659
680
|
out_message = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
|
660
681
|
|
|
661
|
-
print(out_message)
|
|
662
|
-
)`,
|
|
682
|
+
print(out_message)`,
|
|
663
683
|
];
|
|
664
684
|
exports.cartesia_pytorch = cartesia_pytorch;
|
|
665
685
|
const cartesia_mlx = (model) => [
|
|
@@ -710,7 +730,8 @@ speech, *_ = model("text to generate speech from")`,
|
|
|
710
730
|
];
|
|
711
731
|
exports.espnetTTS = espnetTTS;
|
|
712
732
|
const espnetASR = (model) => [
|
|
713
|
-
`
|
|
733
|
+
`import soundfile
|
|
734
|
+
from espnet2.bin.asr_inference import Speech2Text
|
|
714
735
|
|
|
715
736
|
model = Speech2Text.from_pretrained(
|
|
716
737
|
"${model.id}"
|
|
@@ -740,9 +761,14 @@ models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
|
|
|
740
761
|
];
|
|
741
762
|
exports.fairseq = fairseq;
|
|
742
763
|
const flair = (model) => [
|
|
743
|
-
`from flair.
|
|
764
|
+
`from flair.data import Sentence
|
|
765
|
+
from flair.models import SequenceTagger
|
|
744
766
|
|
|
745
|
-
tagger = SequenceTagger.load("${model.id}")
|
|
767
|
+
tagger = SequenceTagger.load("${model.id}")
|
|
768
|
+
|
|
769
|
+
sentence = Sentence("George Washington went to Washington.")
|
|
770
|
+
tagger.predict(sentence)
|
|
771
|
+
print(sentence)`,
|
|
746
772
|
];
|
|
747
773
|
exports.flair = flair;
|
|
748
774
|
const flexray = (model) => [
|
|
@@ -821,23 +847,30 @@ print(f'Accuracy {accuracy_score(y_test, predictions):.2%}')
|
|
|
821
847
|
};
|
|
822
848
|
exports.flextab = flextab;
|
|
823
849
|
const gaussianformer = (model) => [
|
|
824
|
-
`#
|
|
825
|
-
|
|
826
|
-
from gaussianformer.pipelines.rendering_pipeline import GaussianFormerRenderingPipeline
|
|
850
|
+
`# pip install "gaussianformer @ git+https://github.com/SVLwoof/gaussianformer"
|
|
851
|
+
from gaussianformer import GaussianFormerRenderingPipeline, load_ply
|
|
827
852
|
|
|
828
|
-
pipeline = GaussianFormerRenderingPipeline.from_pretrained("${model.id}")
|
|
853
|
+
pipeline = GaussianFormerRenderingPipeline.from_pretrained("${model.id}").to("cuda")
|
|
854
|
+
gaussians = load_ply("object.ply") # 3D Gaussian Splatting PLY -> [N, 14]`,
|
|
829
855
|
];
|
|
830
856
|
exports.gaussianformer = gaussianformer;
|
|
831
857
|
const gliner = (model) => [
|
|
832
858
|
`from gliner import GLiNER
|
|
833
859
|
|
|
834
|
-
model = GLiNER.from_pretrained("${model.id}")
|
|
860
|
+
model = GLiNER.from_pretrained("${model.id}")
|
|
861
|
+
|
|
862
|
+
text = "Cristiano Ronaldo dos Santos Aveiro was born on 5 February 1985 in Funchal, Madeira, Portugal."
|
|
863
|
+
labels = ["person", "date", "location"]
|
|
864
|
+
|
|
865
|
+
entities = model.predict_entities(text, labels)
|
|
866
|
+
for entity in entities:
|
|
867
|
+
print(entity["text"], "=>", entity["label"])`,
|
|
835
868
|
];
|
|
836
869
|
exports.gliner = gliner;
|
|
837
870
|
const gliner2 = (model) => [
|
|
838
|
-
`from gliner2 import
|
|
871
|
+
`from gliner2 import AutoExtractor
|
|
839
872
|
|
|
840
|
-
|
|
873
|
+
extractor = AutoExtractor.from_pretrained("${model.id}")
|
|
841
874
|
|
|
842
875
|
# Extract entities
|
|
843
876
|
text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday."
|
|
@@ -850,7 +883,7 @@ const indextts = (model) => [
|
|
|
850
883
|
`# Download model
|
|
851
884
|
from huggingface_hub import snapshot_download
|
|
852
885
|
|
|
853
|
-
snapshot_download(${model.id}, local_dir="checkpoints")
|
|
886
|
+
snapshot_download("${model.id}", local_dir="checkpoints")
|
|
854
887
|
|
|
855
888
|
from indextts.infer import IndexTTS
|
|
856
889
|
|
|
@@ -907,9 +940,11 @@ print(out["answers"]["team"]["choice"])`,
|
|
|
907
940
|
};
|
|
908
941
|
exports.jev_style = jev_style;
|
|
909
942
|
const keras = (model) => [
|
|
910
|
-
`#
|
|
943
|
+
`# !pip install -U keras tensorflow huggingface_hub
|
|
944
|
+
# Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here;
|
|
945
|
+
# "jax" and "torch" also work for computation once TensorFlow is installed.
|
|
911
946
|
import os
|
|
912
|
-
os.environ["KERAS_BACKEND"] = "
|
|
947
|
+
os.environ["KERAS_BACKEND"] = "tensorflow"
|
|
913
948
|
|
|
914
949
|
import keras
|
|
915
950
|
|
|
@@ -1026,13 +1061,15 @@ const kernels = (model) => [
|
|
|
1026
1061
|
|
|
1027
1062
|
from kernels import get_kernel
|
|
1028
1063
|
|
|
1029
|
-
|
|
1064
|
+
# a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones
|
|
1065
|
+
kernel = get_kernel("${model.id}", version=1)`,
|
|
1030
1066
|
];
|
|
1031
1067
|
exports.kernels = kernels;
|
|
1032
1068
|
const kimi_audio = (model) => [
|
|
1033
1069
|
`# Example usage for KimiAudio
|
|
1034
|
-
# pip install git+https://github.com/MoonshotAI/Kimi-Audio.git
|
|
1070
|
+
# pip install git+https://github.com/MoonshotAI/Kimi-Audio.git "transformers<5"
|
|
1035
1071
|
|
|
1072
|
+
import soundfile as sf
|
|
1036
1073
|
from kimia_infer.api.kimia import KimiAudio
|
|
1037
1074
|
|
|
1038
1075
|
model = KimiAudio(model_path="${model.id}", load_detokenizer=True)
|
|
@@ -1402,14 +1439,17 @@ pip install -U litert-lm
|
|
|
1402
1439
|
|
|
1403
1440
|
# 2. Download and run this model locally:
|
|
1404
1441
|
# See: https://ai.google.dev/edge/litert-lm/cli
|
|
1442
|
+
# A single .litertlm file in the repo is picked automatically; otherwise the CLI asks which one to run
|
|
1443
|
+
# (or pass its name right after the repo id).
|
|
1405
1444
|
litert-lm run \\
|
|
1406
1445
|
--from-huggingface-repo=${model.id} \\
|
|
1407
1446
|
--prompt="Write me a poem"`,
|
|
1408
1447
|
];
|
|
1409
1448
|
exports.litert_lm = litert_lm;
|
|
1410
1449
|
const tf_keras = (model) => [
|
|
1411
|
-
`# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
|
|
1450
|
+
`# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0.
|
|
1412
1451
|
# See https://github.com/keras-team/tf-keras for more details.
|
|
1452
|
+
# !pip install "huggingface_hub<1.0" tf_keras
|
|
1413
1453
|
from huggingface_hub import from_pretrained_keras
|
|
1414
1454
|
|
|
1415
1455
|
model = from_pretrained_keras("${model.id}")
|
|
@@ -1461,6 +1501,17 @@ from MeshAnything.models.meshanything import MeshAnything
|
|
|
1461
1501
|
model = MeshAnything(args)`,
|
|
1462
1502
|
];
|
|
1463
1503
|
exports.mesh_anything = mesh_anything;
|
|
1504
|
+
const microduck = (model) => {
|
|
1505
|
+
// Model-card tag convention: tags: [microduck-slot:stand].
|
|
1506
|
+
const slots = ["walk", "stand", "sitstand", "ground_pick", "kick_left", "kick_right", "roulade"];
|
|
1507
|
+
const matchingSlots = slots.filter((slot) => model.tags.includes(`microduck-slot:${slot}`));
|
|
1508
|
+
const slot = matchingSlots.length === 1 ? matchingSlots[0] : "SLOT";
|
|
1509
|
+
const prefix = matchingSlots.length === 1
|
|
1510
|
+
? ""
|
|
1511
|
+
: `# Replace SLOT with the slot specified in the model card (${slots.join(", ")}).\n`;
|
|
1512
|
+
return [`${prefix}sudo robotctl policy load ${slot} ${model.id}`];
|
|
1513
|
+
};
|
|
1514
|
+
exports.microduck = microduck;
|
|
1464
1515
|
const multimolecule = (model) => {
|
|
1465
1516
|
const widgetExample = model.widgetData?.[0];
|
|
1466
1517
|
const exampleText = escapeStringForJson(widgetExample?.text ?? "");
|
|
@@ -1641,14 +1692,18 @@ model = pe.VisionTransformer.from_config("${model.id}", pretrained=True)`;
|
|
|
1641
1692
|
exports.perception_encoder = perception_encoder;
|
|
1642
1693
|
const phantom_wan = (model) => [
|
|
1643
1694
|
`from huggingface_hub import snapshot_download
|
|
1644
|
-
from phantom_wan import
|
|
1695
|
+
from phantom_wan import WanI2V, configs
|
|
1696
|
+
from PIL import Image
|
|
1645
1697
|
|
|
1646
1698
|
checkpoint_dir = snapshot_download("${model.id}")
|
|
1647
1699
|
wan_i2v = WanI2V(
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1700
|
+
config=configs.WAN_CONFIGS['i2v-14B'],
|
|
1701
|
+
checkpoint_dir=checkpoint_dir,
|
|
1702
|
+
)
|
|
1703
|
+
|
|
1704
|
+
text_prompt = "A cat playing with a ball of yarn"
|
|
1705
|
+
image_prompt = Image.open("path/to/image.jpg").convert("RGB")
|
|
1706
|
+
video = wan_i2v.generate(text_prompt, image_prompt)`,
|
|
1652
1707
|
];
|
|
1653
1708
|
exports.phantom_wan = phantom_wan;
|
|
1654
1709
|
const pocket_tts = (model) => [
|
|
@@ -1770,7 +1825,7 @@ exports.tensorflowtts = tensorflowtts;
|
|
|
1770
1825
|
const timm = (model) => [
|
|
1771
1826
|
`import timm
|
|
1772
1827
|
|
|
1773
|
-
model = timm.create_model("
|
|
1828
|
+
model = timm.create_model("hf-hub:${model.id}", pretrained=True)`,
|
|
1774
1829
|
];
|
|
1775
1830
|
exports.timm = timm;
|
|
1776
1831
|
const saelens = ( /* model: ModelData */) => [
|
|
@@ -1798,13 +1853,14 @@ seed_story_cfg = OmegaConf.load(seed_story_cfg_path)
|
|
|
1798
1853
|
seed_story = hydra.utils.instantiate(seed_story_cfg, llm=llm) `,
|
|
1799
1854
|
];
|
|
1800
1855
|
exports.seed_story = seed_story;
|
|
1801
|
-
const
|
|
1856
|
+
const SKLEARN_PICKLE_FILE = /\.(joblib|pkl|pickle)$/i;
|
|
1857
|
+
// skops.hub_utils was removed in skops 0.12, so files are downloaded with huggingface_hub
|
|
1858
|
+
const sklearnPickle = (model, modelFile) => {
|
|
1802
1859
|
return [
|
|
1803
|
-
`import
|
|
1804
|
-
|
|
1805
|
-
download("${model.id}", "path_to_folder")
|
|
1860
|
+
`from huggingface_hub import hf_hub_download
|
|
1861
|
+
import joblib
|
|
1806
1862
|
model = joblib.load(
|
|
1807
|
-
"${escapeStringForJson(modelFile)}"
|
|
1863
|
+
hf_hub_download("${model.id}", "${escapeStringForJson(modelFile)}")
|
|
1808
1864
|
)
|
|
1809
1865
|
# only load pickle files from sources you trust
|
|
1810
1866
|
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
|
|
@@ -1812,42 +1868,28 @@ model = joblib.load(
|
|
|
1812
1868
|
};
|
|
1813
1869
|
const skopsFormat = (model, modelFile) => {
|
|
1814
1870
|
return [
|
|
1815
|
-
`from
|
|
1871
|
+
`from huggingface_hub import hf_hub_download
|
|
1816
1872
|
from skops.io import load
|
|
1817
|
-
download("${model.id}", "path_to_folder")
|
|
1818
1873
|
# make sure model file is in skops format
|
|
1819
1874
|
# if model is a pickle file, make sure it's from a source you trust
|
|
1820
|
-
model = load("
|
|
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`,
|
|
1875
|
+
model = load(hf_hub_download("${model.id}", "${escapeStringForJson(modelFile)}"))`,
|
|
1832
1876
|
];
|
|
1833
1877
|
};
|
|
1834
1878
|
const sklearn = (model) => {
|
|
1879
|
+
const declaredFile = model.config?.sklearn?.model?.file;
|
|
1835
1880
|
if (model.tags.includes("skops")) {
|
|
1836
|
-
|
|
1837
|
-
const skopssaveFormat = model.config?.sklearn?.model_format;
|
|
1838
|
-
if (!skopsmodelFile) {
|
|
1881
|
+
if (!declaredFile) {
|
|
1839
1882
|
return [`# ⚠️ Model filename not specified in config.json`];
|
|
1840
1883
|
}
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
else {
|
|
1845
|
-
return skopsFormat(model, skopsmodelFile);
|
|
1884
|
+
// some skops repos declare no model_format for a pickled file (e.g. julien-c/skops-digits), which skops.io cannot read
|
|
1885
|
+
if (model.config?.sklearn?.model_format === "pickle" || SKLEARN_PICKLE_FILE.test(declaredFile)) {
|
|
1886
|
+
return sklearnPickle(model, declaredFile);
|
|
1846
1887
|
}
|
|
1888
|
+
return skopsFormat(model, declaredFile);
|
|
1847
1889
|
}
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1890
|
+
// repos pushed without skops often still declare their filename in config.json; it is only trusted when it names a
|
|
1891
|
+
// pickle, since some hand-written configs carry typos (e.g. "sklean_model.jpblib" next to a real sklearn_model.joblib)
|
|
1892
|
+
return sklearnPickle(model, declaredFile && SKLEARN_PICKLE_FILE.test(declaredFile) ? declaredFile : "sklearn_model.joblib");
|
|
1851
1893
|
};
|
|
1852
1894
|
exports.sklearn = sklearn;
|
|
1853
1895
|
const stable_audio_tools = (model) => [
|
|
@@ -1898,7 +1940,7 @@ const sam2 = (model) => {
|
|
|
1898
1940
|
import torch
|
|
1899
1941
|
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
|
1900
1942
|
|
|
1901
|
-
predictor = SAM2ImagePredictor.from_pretrained(${model.id})
|
|
1943
|
+
predictor = SAM2ImagePredictor.from_pretrained("${model.id}")
|
|
1902
1944
|
|
|
1903
1945
|
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
|
1904
1946
|
predictor.set_image(<your_image>)
|
|
@@ -1907,13 +1949,13 @@ with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
|
|
1907
1949
|
import torch
|
|
1908
1950
|
from sam2.sam2_video_predictor import SAM2VideoPredictor
|
|
1909
1951
|
|
|
1910
|
-
predictor = SAM2VideoPredictor.from_pretrained(${model.id})
|
|
1952
|
+
predictor = SAM2VideoPredictor.from_pretrained("${model.id}")
|
|
1911
1953
|
|
|
1912
1954
|
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
|
1913
1955
|
state = predictor.init_state(<your_video>)
|
|
1914
1956
|
|
|
1915
1957
|
# 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>)
|
|
1958
|
+
frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>)
|
|
1917
1959
|
|
|
1918
1960
|
# propagate the prompts to get masklets throughout the video
|
|
1919
1961
|
for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
|
|
@@ -1935,11 +1977,18 @@ output = inference(image, mask)`,
|
|
|
1935
1977
|
];
|
|
1936
1978
|
exports.sam_3d_objects = sam_3d_objects;
|
|
1937
1979
|
const sam_3d_body = (model) => [
|
|
1938
|
-
`
|
|
1980
|
+
`import cv2
|
|
1981
|
+
import numpy as np
|
|
1982
|
+
from notebook.utils import setup_sam_3d_body
|
|
1983
|
+
from tools.vis_utils import visualize_sample_together
|
|
1984
|
+
|
|
1985
|
+
estimator = setup_sam_3d_body("${model.id}")
|
|
1986
|
+
|
|
1987
|
+
img_bgr = cv2.imread("path/to/image.jpg")
|
|
1988
|
+
outputs = estimator.process_one_image(cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB))
|
|
1939
1989
|
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
rend_img = visualize_sample_together(image, outputs, estimator.faces)`,
|
|
1990
|
+
rend_img = visualize_sample_together(img_bgr, outputs, estimator.faces)
|
|
1991
|
+
cv2.imwrite("output.jpg", rend_img.astype(np.uint8))`,
|
|
1943
1992
|
];
|
|
1944
1993
|
exports.sam_3d_body = sam_3d_body;
|
|
1945
1994
|
const sampleFactory = (model) => [
|
|
@@ -2033,7 +2082,15 @@ queries_emb = model.encode(queries, is_query=True)
|
|
|
2033
2082
|
docs_emb = model.encode(documents, is_query=False)`,
|
|
2034
2083
|
];
|
|
2035
2084
|
}
|
|
2036
|
-
|
|
2085
|
+
// Rerankers saved in the CrossEncoder format are often tagged text-classification rather than text-ranking;
|
|
2086
|
+
// their architecture still identifies them (e.g. BAAI/bge-reranker-v2-m3). SetFit models can share that shape but
|
|
2087
|
+
// are bi-encoders with a separate head.
|
|
2088
|
+
const isCrossEncoder = model.tags.includes("cross-encoder") ||
|
|
2089
|
+
model.pipeline_tag == "text-ranking" ||
|
|
2090
|
+
(model.pipeline_tag === "text-classification" &&
|
|
2091
|
+
!model.tags.includes("setfit") &&
|
|
2092
|
+
(model.config?.architectures ?? []).some((arch) => arch.endsWith("ForSequenceClassification")));
|
|
2093
|
+
if (isCrossEncoder) {
|
|
2037
2094
|
return [
|
|
2038
2095
|
`from sentence_transformers import CrossEncoder
|
|
2039
2096
|
|
|
@@ -2051,6 +2108,33 @@ scores = model.predict([(query, passage) for passage in passages])
|
|
|
2051
2108
|
print(scores)`,
|
|
2052
2109
|
];
|
|
2053
2110
|
}
|
|
2111
|
+
// sentence-transformers tags SparseEncoder repos (SPLADE & co) with "sparse-encoder" and MultiVectorEncoder repos
|
|
2112
|
+
// (ColBERT & co) with "multi-vector" when pushing them; both encode queries and documents separately
|
|
2113
|
+
const retrievalEncoder = model.tags.includes("sparse-encoder")
|
|
2114
|
+
? "SparseEncoder"
|
|
2115
|
+
: model.tags.includes("multi-vector")
|
|
2116
|
+
? "MultiVectorEncoder"
|
|
2117
|
+
: undefined;
|
|
2118
|
+
if (retrievalEncoder) {
|
|
2119
|
+
return [
|
|
2120
|
+
`from sentence_transformers import ${retrievalEncoder}
|
|
2121
|
+
|
|
2122
|
+
model = ${retrievalEncoder}("${model.id}"${remote_code_snippet})
|
|
2123
|
+
|
|
2124
|
+
queries = ["Which planet is known as the Red Planet?"]
|
|
2125
|
+
documents = [
|
|
2126
|
+
"Venus is often called Earth's twin because of its similar size and proximity.",
|
|
2127
|
+
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
|
|
2128
|
+
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
|
|
2129
|
+
]
|
|
2130
|
+
|
|
2131
|
+
query_embeddings = model.encode_query(queries)
|
|
2132
|
+
document_embeddings = model.encode_document(documents)
|
|
2133
|
+
|
|
2134
|
+
similarities = model.similarity(query_embeddings, document_embeddings)
|
|
2135
|
+
print(similarities)`,
|
|
2136
|
+
];
|
|
2137
|
+
}
|
|
2054
2138
|
const exampleSentences = get_widget_examples_from_st_model(model) ?? [
|
|
2055
2139
|
"The weather is lovely today.",
|
|
2056
2140
|
"It's so sunny outside!",
|
|
@@ -2073,7 +2157,10 @@ exports.sentenceTransformers = sentenceTransformers;
|
|
|
2073
2157
|
const setfit = (model) => [
|
|
2074
2158
|
`from setfit import SetFitModel
|
|
2075
2159
|
|
|
2076
|
-
model = SetFitModel.from_pretrained("${model.id}")
|
|
2160
|
+
model = SetFitModel.from_pretrained("${model.id}")
|
|
2161
|
+
|
|
2162
|
+
preds = model.predict(["i loved the spiderman movie!", "pineapple on pizza is the worst"])
|
|
2163
|
+
print(preds)`,
|
|
2077
2164
|
];
|
|
2078
2165
|
exports.setfit = setfit;
|
|
2079
2166
|
const spacy = (model) => [
|
|
@@ -2091,7 +2178,10 @@ exports.spacy = spacy;
|
|
|
2091
2178
|
const span_marker = (model) => [
|
|
2092
2179
|
`from span_marker import SpanMarkerModel
|
|
2093
2180
|
|
|
2094
|
-
model = SpanMarkerModel.from_pretrained("${model.id}")
|
|
2181
|
+
model = SpanMarkerModel.from_pretrained("${model.id}")
|
|
2182
|
+
|
|
2183
|
+
entities = model.predict("Amelia Earhart flew her single engine Lockheed Vega 5B across the Atlantic to Paris.")
|
|
2184
|
+
print(entities)`,
|
|
2095
2185
|
];
|
|
2096
2186
|
exports.span_marker = span_marker;
|
|
2097
2187
|
const stanza = (model) => [
|
|
@@ -2112,6 +2202,8 @@ const speechBrainMethod = (speechbrainInterface) => {
|
|
|
2112
2202
|
return "enhance_file";
|
|
2113
2203
|
case "SepformerSeparation":
|
|
2114
2204
|
return "separate_file";
|
|
2205
|
+
case "SpeakerRecognition":
|
|
2206
|
+
return "verify_files";
|
|
2115
2207
|
default:
|
|
2116
2208
|
return undefined;
|
|
2117
2209
|
}
|
|
@@ -2125,12 +2217,14 @@ const speechbrain = (model) => {
|
|
|
2125
2217
|
if (speechbrainMethod === undefined) {
|
|
2126
2218
|
return [`# interface in config.json invalid`];
|
|
2127
2219
|
}
|
|
2220
|
+
// speaker verification compares two recordings
|
|
2221
|
+
const methodArgs = speechbrainMethod === "verify_files" ? '"speaker1.wav", "speaker2.wav"' : '"file.wav"';
|
|
2128
2222
|
return [
|
|
2129
2223
|
`from speechbrain.pretrained import ${speechbrainInterface}
|
|
2130
2224
|
model = ${speechbrainInterface}.from_hparams(
|
|
2131
2225
|
"${model.id}"
|
|
2132
2226
|
)
|
|
2133
|
-
model.${speechbrainMethod}(
|
|
2227
|
+
model.${speechbrainMethod}(${methodArgs})`,
|
|
2134
2228
|
];
|
|
2135
2229
|
};
|
|
2136
2230
|
exports.speechbrain = speechbrain;
|
|
@@ -2162,7 +2256,7 @@ const transformers = (model) => {
|
|
|
2162
2256
|
: info.processor === "AutoFeatureExtractor"
|
|
2163
2257
|
? "extractor"
|
|
2164
2258
|
: "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")');
|
|
2259
|
+
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
2260
|
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
2167
2261
|
if (model.tags.includes("image-text-to-text")) {
|
|
2168
2262
|
autoSnippet.push("messages = [", [
|
|
@@ -2178,19 +2272,19 @@ const transformers = (model) => {
|
|
|
2178
2272
|
else {
|
|
2179
2273
|
autoSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]");
|
|
2180
2274
|
}
|
|
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=
|
|
2275
|
+
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
2276
|
}
|
|
2183
2277
|
}
|
|
2184
2278
|
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")');
|
|
2279
|
+
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
2280
|
}
|
|
2187
2281
|
if (model.pipeline_tag && library_to_tasks_js_1.LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
|
|
2188
2282
|
const pipelineSnippet = ["# Use a pipeline as a high-level helper"];
|
|
2189
2283
|
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:`, `#
|
|
2284
|
+
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
2285
|
}
|
|
2192
2286
|
pipelineSnippet.push("from transformers import pipeline", "", `pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")");
|
|
2193
|
-
if (model.tags.includes("conversational")) {
|
|
2287
|
+
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
2194
2288
|
if (model.tags.includes("image-text-to-text")) {
|
|
2195
2289
|
pipelineSnippet.push("messages = [", [
|
|
2196
2290
|
" {",
|
|
@@ -2219,48 +2313,119 @@ const transformers = (model) => {
|
|
|
2219
2313
|
return [autoSnippet.join("\n")];
|
|
2220
2314
|
};
|
|
2221
2315
|
exports.transformers = transformers;
|
|
2316
|
+
// Hub tasks that transformers.js exposes under a different pipeline() task name
|
|
2317
|
+
const TRANSFORMERS_JS_TASK_ALIASES = {
|
|
2318
|
+
"sentence-similarity": "feature-extraction",
|
|
2319
|
+
};
|
|
2222
2320
|
const transformersJS = (model) => {
|
|
2223
2321
|
if (!model.pipeline_tag) {
|
|
2224
2322
|
return [`// ⚠️ Unknown pipeline tag`];
|
|
2225
2323
|
}
|
|
2226
2324
|
const libName = "@huggingface/transformers";
|
|
2325
|
+
// Rerankers score (query, document) pairs. The text-classification pipeline cannot take pairs and applies a softmax
|
|
2326
|
+
// over their single logit, so every score comes out as 1; the model is called directly instead.
|
|
2327
|
+
if (model.pipeline_tag === "text-ranking") {
|
|
2328
|
+
return [
|
|
2329
|
+
`// npm i ${libName}
|
|
2330
|
+
import { AutoTokenizer, AutoModelForSequenceClassification } from '${libName}';
|
|
2331
|
+
|
|
2332
|
+
const tokenizer = await AutoTokenizer.from_pretrained('${model.id}');
|
|
2333
|
+
const model = await AutoModelForSequenceClassification.from_pretrained('${model.id}');
|
|
2334
|
+
|
|
2335
|
+
const query = 'Which planet is known as the Red Planet?';
|
|
2336
|
+
const documents = [
|
|
2337
|
+
'Mars, known for its reddish appearance, is often referred to as the Red Planet.',
|
|
2338
|
+
'Venus is often called the twin of Earth because of its similar size and proximity.',
|
|
2339
|
+
];
|
|
2340
|
+
|
|
2341
|
+
const inputs = tokenizer(new Array(documents.length).fill(query), { text_pair: documents, padding: true, truncation: true });
|
|
2342
|
+
const { logits } = await model(inputs);
|
|
2343
|
+
console.log(logits.sigmoid().tolist()); // one relevance score per document`,
|
|
2344
|
+
];
|
|
2345
|
+
}
|
|
2346
|
+
const task = TRANSFORMERS_JS_TASK_ALIASES[model.pipeline_tag] ?? model.pipeline_tag;
|
|
2227
2347
|
return [
|
|
2228
2348
|
`// npm i ${libName}
|
|
2229
2349
|
import { pipeline } from '${libName}';
|
|
2230
2350
|
|
|
2231
2351
|
// Allocate pipeline
|
|
2232
|
-
const pipe = await pipeline('${
|
|
2352
|
+
const pipe = await pipeline('${task}', '${model.id}');`,
|
|
2233
2353
|
];
|
|
2234
2354
|
};
|
|
2235
2355
|
exports.transformersJS = transformersJS;
|
|
2236
|
-
const
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2356
|
+
const PEFT_TASK_TYPE_TO_AUTO_CLASS = {
|
|
2357
|
+
CAUSAL_LM: "AutoModelForCausalLM",
|
|
2358
|
+
SEQ_2_SEQ_LM: "AutoModelForSeq2SeqLM",
|
|
2359
|
+
TOKEN_CLS: "AutoModelForTokenClassification",
|
|
2360
|
+
SEQ_CLS: "AutoModelForSequenceClassification",
|
|
2361
|
+
QUESTION_ANS: "AutoModelForQuestionAnswering",
|
|
2362
|
+
// transformers has no AutoModelForFeatureExtraction; PEFT's own AutoPeftModelForFeatureExtraction resolves to AutoModel
|
|
2363
|
+
FEATURE_EXTRACTION: "AutoModel",
|
|
2364
|
+
};
|
|
2365
|
+
// PEFT has no speech-specific task type: Whisper-style adapters are tagged SEQ_2_SEQ_LM, but transformers registers
|
|
2366
|
+
// Whisper and Speech2Text only under AutoModelForSpeechSeq2Seq (SeamlessM4T is under both seq2seq auto classes, SpeechT5
|
|
2367
|
+
// under the speech-to-text and text-to-spectrogram ones).
|
|
2368
|
+
// Other audio seq2seq models (Qwen2-Audio, GLM-ASR) stay under AutoModelForSeq2SeqLM, so the base model name is the
|
|
2369
|
+
// main signal. Matched against Hub repo ids, which are hyphenated (facebook/s2t-small-librispeech-asr,
|
|
2370
|
+
// facebook/seamless-m4t-v2-large), not against transformers model_type identifiers.
|
|
2371
|
+
const PEFT_SPEECH_TO_TEXT_BASE_MODEL = /whisper|\bs2t\b|speech[-_]to[-_]text/i;
|
|
2372
|
+
// SeamlessM4T also has a text-to-text head under AutoModelForSeq2SeqLM, which text translation adapters need; most
|
|
2373
|
+
// SeamlessM4T adapters on the Hub are speech ones, so the speech class stays the default when no text task is declared.
|
|
2374
|
+
const PEFT_SEAMLESS_M4T_BASE_MODEL = /seamless[-_]m4t/i;
|
|
2375
|
+
const PEFT_TEXT_TASKS = ["translation", "text2text-generation", "summarization"];
|
|
2376
|
+
// SpeechT5 checkpoints are overwhelmingly text-to-speech fine-tunes (often without "tts" in their name), which load
|
|
2377
|
+
// with AutoModelForTextToSpectrogram; AutoModelForSpeechSeq2Seq would silently load the speech-to-text head, so only
|
|
2378
|
+
// ASR bases or adapters get it.
|
|
2379
|
+
const PEFT_SPEECHT5_BASE_MODEL = /speecht5/i;
|
|
2380
|
+
const declaresTask = (model, task) => model.pipeline_tag === task || model.tags.includes(task);
|
|
2381
|
+
// the auto class a SEQ_2_SEQ_LM adapter needs when its base is a speech model, undefined for text seq2seq bases
|
|
2382
|
+
const peftSpeechAutoClass = (model, baseModel) => {
|
|
2383
|
+
if (PEFT_SPEECH_TO_TEXT_BASE_MODEL.test(baseModel)) {
|
|
2384
|
+
return "AutoModelForSpeechSeq2Seq";
|
|
2385
|
+
}
|
|
2386
|
+
if (PEFT_SEAMLESS_M4T_BASE_MODEL.test(baseModel)) {
|
|
2387
|
+
return PEFT_TEXT_TASKS.some((task) => declaresTask(model, task)) ? undefined : "AutoModelForSpeechSeq2Seq";
|
|
2388
|
+
}
|
|
2389
|
+
if (PEFT_SPEECHT5_BASE_MODEL.test(baseModel)) {
|
|
2390
|
+
const isAsr = /(?:^|[^a-z])asr(?:[^a-z]|$)/i.test(baseModel) || declaresTask(model, "automatic-speech-recognition");
|
|
2391
|
+
return isAsr ? "AutoModelForSpeechSeq2Seq" : "AutoModelForTextToSpectrogram";
|
|
2392
|
+
}
|
|
2393
|
+
return undefined;
|
|
2249
2394
|
};
|
|
2250
2395
|
const peft = (model) => {
|
|
2251
2396
|
const { base_model_name_or_path: peftBaseModel, task_type: peftTaskType } = model.config?.peft ?? {};
|
|
2252
|
-
|
|
2253
|
-
if (!
|
|
2397
|
+
let autoClass = peftTaskType ? PEFT_TASK_TYPE_TO_AUTO_CLASS[peftTaskType] : undefined;
|
|
2398
|
+
if (!autoClass) {
|
|
2254
2399
|
return [`Task type is invalid.`];
|
|
2255
2400
|
}
|
|
2256
|
-
|
|
2401
|
+
// adapter_config.json sometimes omits the base model; the model card's base_model is the next best source
|
|
2402
|
+
const cardBaseModel = Array.isArray(model.cardData?.base_model)
|
|
2403
|
+
? model.cardData.base_model[0]
|
|
2404
|
+
: model.cardData?.base_model;
|
|
2405
|
+
const baseModel = peftBaseModel || cardBaseModel;
|
|
2406
|
+
if (!baseModel) {
|
|
2257
2407
|
return [`Base model is not found.`];
|
|
2258
2408
|
}
|
|
2409
|
+
if (peftTaskType === "SEQ_2_SEQ_LM") {
|
|
2410
|
+
autoClass = peftSpeechAutoClass(model, baseModel) ?? autoClass;
|
|
2411
|
+
}
|
|
2412
|
+
if (autoClass === "AutoModelForTextToSpectrogram") {
|
|
2413
|
+
return [
|
|
2414
|
+
`from peft import PeftConfig, PeftModel
|
|
2415
|
+
from transformers import AutoModelForTextToSpectrogram
|
|
2416
|
+
|
|
2417
|
+
base_model = AutoModelForTextToSpectrogram.from_pretrained("${escapeStringForJson(baseModel)}")
|
|
2418
|
+
# PEFT's seq2seq wrapper needs generate(), which SpeechT5's text-to-speech model lacks: load the adapter without its task type
|
|
2419
|
+
config = PeftConfig.from_pretrained("${model.id}")
|
|
2420
|
+
config.task_type = None
|
|
2421
|
+
model = PeftModel.from_pretrained(base_model, "${model.id}", config=config)`,
|
|
2422
|
+
];
|
|
2423
|
+
}
|
|
2259
2424
|
return [
|
|
2260
2425
|
`from peft import PeftModel
|
|
2261
|
-
from transformers import
|
|
2426
|
+
from transformers import ${autoClass}
|
|
2262
2427
|
|
|
2263
|
-
base_model =
|
|
2428
|
+
base_model = ${autoClass}.from_pretrained("${escapeStringForJson(baseModel)}")
|
|
2264
2429
|
model = PeftModel.from_pretrained(base_model, "${model.id}")`,
|
|
2265
2430
|
];
|
|
2266
2431
|
};
|
|
@@ -2294,7 +2459,7 @@ transcriptions = asr_model.transcribe(["file.wav"])`,
|
|
|
2294
2459
|
}
|
|
2295
2460
|
};
|
|
2296
2461
|
const mlAgents = (model) => [
|
|
2297
|
-
`mlagents-load-from-hf --repo-id="${model.id}" --local-dir="./
|
|
2462
|
+
`mlagents-load-from-hf --repo-id="${model.id}" --local-dir="./downloads"`,
|
|
2298
2463
|
];
|
|
2299
2464
|
exports.mlAgents = mlAgents;
|
|
2300
2465
|
const sentis = ( /* model: ModelData */) => [
|
|
@@ -2369,10 +2534,10 @@ model = Model.from_pretrained("${model.id}")`,
|
|
|
2369
2534
|
exports.vfimamba = vfimamba;
|
|
2370
2535
|
const lvface = (model) => [
|
|
2371
2536
|
`from huggingface_hub import hf_hub_download
|
|
2372
|
-
|
|
2537
|
+
from inference_onnx import LVFaceONNXInferencer
|
|
2373
2538
|
|
|
2374
2539
|
model_path = hf_hub_download("${model.id}", "LVFace-L_Glint360K/LVFace-L_Glint360K.onnx")
|
|
2375
|
-
inferencer = LVFaceONNXInferencer(model_path, use_gpu=True
|
|
2540
|
+
inferencer = LVFaceONNXInferencer(model_path, use_gpu=True)
|
|
2376
2541
|
img_path = 'path/to/image1.jpg'
|
|
2377
2542
|
embedding = inferencer.infer_from_image(img_path)`,
|
|
2378
2543
|
];
|
|
@@ -2411,8 +2576,7 @@ const vui = () => [
|
|
|
2411
2576
|
|
|
2412
2577
|
import torchaudio
|
|
2413
2578
|
|
|
2414
|
-
from vui.
|
|
2415
|
-
from vui.model import Vui,
|
|
2579
|
+
from vui.legacy import Vui, render
|
|
2416
2580
|
|
|
2417
2581
|
model = Vui.from_pretrained().cuda()
|
|
2418
2582
|
waveform = render(
|
|
@@ -2420,16 +2584,17 @@ waveform = render(
|
|
|
2420
2584
|
"Hey, here is some random stuff, usually something quite long as the shorter the text the less likely the model can cope!",
|
|
2421
2585
|
)
|
|
2422
2586
|
print(waveform.shape)
|
|
2423
|
-
torchaudio.save("out.
|
|
2587
|
+
torchaudio.save("out.wav", waveform[0], 22050)
|
|
2424
2588
|
`,
|
|
2425
2589
|
];
|
|
2426
2590
|
exports.vui = vui;
|
|
2427
2591
|
const chattts = () => [
|
|
2428
2592
|
`import ChatTTS
|
|
2593
|
+
import torch
|
|
2429
2594
|
import torchaudio
|
|
2430
2595
|
|
|
2431
2596
|
chat = ChatTTS.Chat()
|
|
2432
|
-
chat.
|
|
2597
|
+
chat.load(compile=False) # Set to True for better performance
|
|
2433
2598
|
|
|
2434
2599
|
texts = ["PUT YOUR TEXT HERE",]
|
|
2435
2600
|
|
|
@@ -2439,17 +2604,42 @@ torchaudio.save("output1.wav", torch.from_numpy(wavs[0]), 24000)`,
|
|
|
2439
2604
|
];
|
|
2440
2605
|
exports.chattts = chattts;
|
|
2441
2606
|
const ultralytics = (model) => {
|
|
2442
|
-
//
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2607
|
+
// the YOLOv10 fork (library "yolov10") ships its own `YOLOv10` class with a `from_pretrained` helper that reads the
|
|
2608
|
+
// model.safetensors it pushes. Mainline ultralytics repos often list "yolov10" among their version tags
|
|
2609
|
+
// (e.g. Ultralytics/YOLOv8) but only ship .pt files, so an ultralytics tag alone keeps them on the mainline loader;
|
|
2610
|
+
// fork pushes still tagged ultralytics are recognized by their safetensors weights.
|
|
2611
|
+
const isYolov10Fork = model.library_name === "yolov10" ||
|
|
2612
|
+
(model.tags.includes("yolov10") && (!model.tags.includes("ultralytics") || model.tags.includes("safetensors")));
|
|
2613
|
+
if (isYolov10Fork) {
|
|
2614
|
+
// from_pretrained reads the model.safetensors that fork pushes ship; older fork repos only ship .pt weights
|
|
2615
|
+
if (model.tags.includes("safetensors")) {
|
|
2616
|
+
return [
|
|
2617
|
+
`from ultralytics import YOLOv10
|
|
2618
|
+
|
|
2619
|
+
model = YOLOv10.from_pretrained("${model.id}")
|
|
2620
|
+
source = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
|
2621
|
+
model.predict(source=source, save=True)`,
|
|
2622
|
+
];
|
|
2623
|
+
}
|
|
2624
|
+
return [
|
|
2625
|
+
`from huggingface_hub import hf_hub_download
|
|
2626
|
+
from ultralytics import YOLOv10
|
|
2627
|
+
|
|
2628
|
+
# pick the weights file from this repo's "Files and versions" tab
|
|
2629
|
+
weights = hf_hub_download("${model.id}", "<weights>.pt")
|
|
2630
|
+
model = YOLOv10(weights)
|
|
2631
|
+
source = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
|
2632
|
+
model.predict(source=source, save=True)`,
|
|
2633
|
+
];
|
|
2634
|
+
}
|
|
2635
|
+
// mainline ultralytics loads weights from a local file
|
|
2448
2636
|
return [
|
|
2449
|
-
|
|
2450
|
-
|
|
2637
|
+
`from huggingface_hub import hf_hub_download
|
|
2638
|
+
from ultralytics import YOLO
|
|
2451
2639
|
|
|
2452
|
-
|
|
2640
|
+
# pick the weights file from this repo's "Files and versions" tab
|
|
2641
|
+
weights = hf_hub_download("${model.id}", "<weights>.pt")
|
|
2642
|
+
model = YOLO(weights)
|
|
2453
2643
|
source = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
|
2454
2644
|
model.predict(source=source, save=True)`,
|
|
2455
2645
|
];
|
|
@@ -2527,14 +2717,16 @@ model = SwarmFormerModel.from_pretrained("${model.id}")
|
|
|
2527
2717
|
exports.swarmformer = swarmformer;
|
|
2528
2718
|
const univa = (model) => [
|
|
2529
2719
|
`# Follow installation instructions at https://github.com/PKU-YuanGroup/UniWorld-V1
|
|
2530
|
-
|
|
2720
|
+
import torch
|
|
2721
|
+
from transformers import AutoProcessor
|
|
2531
2722
|
from univa.models.qwen2p5vl.modeling_univa_qwen2p5vl import UnivaQwen2p5VLForConditionalGeneration
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2723
|
+
|
|
2724
|
+
model = UnivaQwen2p5VLForConditionalGeneration.from_pretrained(
|
|
2725
|
+
"${model.id}",
|
|
2726
|
+
torch_dtype=torch.bfloat16,
|
|
2727
|
+
attn_implementation="flash_attention_2",
|
|
2728
|
+
).to("cuda")
|
|
2729
|
+
processor = AutoProcessor.from_pretrained("${model.id}")
|
|
2538
2730
|
`,
|
|
2539
2731
|
];
|
|
2540
2732
|
exports.univa = univa;
|
|
@@ -2542,7 +2734,7 @@ const mlx_unknown = (model) => [
|
|
|
2542
2734
|
`# Download the model from the Hub
|
|
2543
2735
|
pip install huggingface_hub[hf_xet]
|
|
2544
2736
|
|
|
2545
|
-
|
|
2737
|
+
hf download ${model.id} --local-dir ${nameWithoutNamespace(model.id)}`,
|
|
2546
2738
|
];
|
|
2547
2739
|
const mlxlm = (model) => [
|
|
2548
2740
|
`# Make sure mlx-lm is installed
|
|
@@ -2599,10 +2791,11 @@ formatted_prompt = apply_chat_template(
|
|
|
2599
2791
|
output = generate(model, processor, formatted_prompt, image)
|
|
2600
2792
|
print(output)`,
|
|
2601
2793
|
];
|
|
2794
|
+
// create_model() takes a name from the mlx-image registry, not a repo id; the weights live in "mlx-vision/<name>-mlxim"
|
|
2602
2795
|
const mlxim = (model) => [
|
|
2603
2796
|
`from mlxim.model import create_model
|
|
2604
2797
|
|
|
2605
|
-
model = create_model(${model.id})`,
|
|
2798
|
+
model = create_model("${nameWithoutNamespace(model.id).replace(/-mlxim$/, "")}")`,
|
|
2606
2799
|
];
|
|
2607
2800
|
exports.mlxim = mlxim;
|
|
2608
2801
|
const mlx = (model) => {
|
|
@@ -2623,7 +2816,10 @@ exports.mlx = mlx;
|
|
|
2623
2816
|
const model2vec = (model) => [
|
|
2624
2817
|
`from model2vec import StaticModel
|
|
2625
2818
|
|
|
2626
|
-
model = StaticModel.from_pretrained("${model.id}")
|
|
2819
|
+
model = StaticModel.from_pretrained("${model.id}")
|
|
2820
|
+
|
|
2821
|
+
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
2822
|
+
print(embeddings.shape)`,
|
|
2627
2823
|
];
|
|
2628
2824
|
exports.model2vec = model2vec;
|
|
2629
2825
|
const mobilint = (model) => {
|
|
@@ -2668,7 +2864,8 @@ const pruna = (model) => {
|
|
|
2668
2864
|
};
|
|
2669
2865
|
snippets = snippets.map(ensurePrunaModelImport);
|
|
2670
2866
|
if (model.tags.includes("pruna_pro-ai")) {
|
|
2671
|
-
|
|
2867
|
+
// only rewrite the import and the class name, never the repo id (an org name can contain "pruna")
|
|
2868
|
+
return snippets.map((snippet) => snippet.replace(/^from pruna import /gm, "from pruna_pro import ").replace(/\bPrunaModel\b/g, "PrunaProModel"));
|
|
2672
2869
|
}
|
|
2673
2870
|
return snippets;
|
|
2674
2871
|
};
|
|
@@ -2728,21 +2925,19 @@ const outetts = (model) => {
|
|
|
2728
2925
|
}
|
|
2729
2926
|
// v1.0 HF → minimal runnable snippet
|
|
2730
2927
|
return [
|
|
2731
|
-
`
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
).save("output.wav")
|
|
2745
|
-
`,
|
|
2928
|
+
`import outetts
|
|
2929
|
+
|
|
2930
|
+
enum = outetts.Models("${model.id}".split("/", 1)[1]) # VERSION_1_0_SIZE_1B
|
|
2931
|
+
cfg = outetts.ModelConfig.auto_config(enum, outetts.Backend.HF)
|
|
2932
|
+
tts = outetts.Interface(cfg)
|
|
2933
|
+
|
|
2934
|
+
speaker = tts.load_default_speaker("EN-FEMALE-1-NEUTRAL")
|
|
2935
|
+
tts.generate(
|
|
2936
|
+
outetts.GenerationConfig(
|
|
2937
|
+
text="Hello there, how are you doing?",
|
|
2938
|
+
speaker=speaker,
|
|
2939
|
+
)
|
|
2940
|
+
).save("output.wav")`,
|
|
2746
2941
|
];
|
|
2747
2942
|
};
|
|
2748
2943
|
exports.outetts = outetts;
|