@huggingface/tasks 0.21.53 → 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.
- 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 +345 -150
- package/dist/commonjs/model-libraries-snippets.spec.js +300 -0
- package/dist/commonjs/model-libraries.d.ts +18 -2
- package/dist/commonjs/model-libraries.d.ts.map +1 -1
- package/dist/commonjs/model-libraries.js +17 -1
- 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 +340 -147
- package/dist/esm/model-libraries-snippets.spec.js +301 -1
- package/dist/esm/model-libraries.d.ts +18 -2
- package/dist/esm/model-libraries.d.ts.map +1 -1
- package/dist/esm/model-libraries.js +17 -1
- package/package.json +1 -1
- package/src/library-to-tasks.ts +8 -1
- package/src/model-libraries-snippets.spec.ts +389 -0
- package/src/model-libraries-snippets.ts +360 -145
- package/src/model-libraries.ts +17 -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 = void 0;
|
|
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.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 ?? "
|
|
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
|
-
|
|
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 = (
|
|
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(
|
|
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)
|
|
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
|
|
323
|
-
|
|
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
|
-
|
|
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,
|
|
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 (
|
|
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 (
|
|
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
|
|
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
|
|
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
|
-
`#
|
|
649
|
-
|
|
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
|
-
`
|
|
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.
|
|
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) => [
|
|
@@ -820,16 +838,31 @@ print(f'Accuracy {accuracy_score(y_test, predictions):.2%}')
|
|
|
820
838
|
return [installSnippet, classificationSnippet, regressionsSnippet, matchingSnippet];
|
|
821
839
|
};
|
|
822
840
|
exports.flextab = flextab;
|
|
841
|
+
const gaussianformer = (model) => [
|
|
842
|
+
`# Install from https://github.com/SVLwoof/gaussianformer
|
|
843
|
+
|
|
844
|
+
from gaussianformer.pipelines.rendering_pipeline import GaussianFormerRenderingPipeline
|
|
845
|
+
|
|
846
|
+
pipeline = GaussianFormerRenderingPipeline.from_pretrained("${model.id}")`,
|
|
847
|
+
];
|
|
848
|
+
exports.gaussianformer = gaussianformer;
|
|
823
849
|
const gliner = (model) => [
|
|
824
850
|
`from gliner import GLiNER
|
|
825
851
|
|
|
826
|
-
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"])`,
|
|
827
860
|
];
|
|
828
861
|
exports.gliner = gliner;
|
|
829
862
|
const gliner2 = (model) => [
|
|
830
|
-
`from gliner2 import
|
|
863
|
+
`from gliner2 import AutoExtractor
|
|
831
864
|
|
|
832
|
-
|
|
865
|
+
extractor = AutoExtractor.from_pretrained("${model.id}")
|
|
833
866
|
|
|
834
867
|
# Extract entities
|
|
835
868
|
text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday."
|
|
@@ -842,7 +875,7 @@ const indextts = (model) => [
|
|
|
842
875
|
`# Download model
|
|
843
876
|
from huggingface_hub import snapshot_download
|
|
844
877
|
|
|
845
|
-
snapshot_download(${model.id}, local_dir="checkpoints")
|
|
878
|
+
snapshot_download("${model.id}", local_dir="checkpoints")
|
|
846
879
|
|
|
847
880
|
from indextts.infer import IndexTTS
|
|
848
881
|
|
|
@@ -899,9 +932,11 @@ print(out["answers"]["team"]["choice"])`,
|
|
|
899
932
|
};
|
|
900
933
|
exports.jev_style = jev_style;
|
|
901
934
|
const keras = (model) => [
|
|
902
|
-
`#
|
|
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.
|
|
903
938
|
import os
|
|
904
|
-
os.environ["KERAS_BACKEND"] = "
|
|
939
|
+
os.environ["KERAS_BACKEND"] = "tensorflow"
|
|
905
940
|
|
|
906
941
|
import keras
|
|
907
942
|
|
|
@@ -1018,13 +1053,15 @@ const kernels = (model) => [
|
|
|
1018
1053
|
|
|
1019
1054
|
from kernels import get_kernel
|
|
1020
1055
|
|
|
1021
|
-
|
|
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)`,
|
|
1022
1058
|
];
|
|
1023
1059
|
exports.kernels = kernels;
|
|
1024
1060
|
const kimi_audio = (model) => [
|
|
1025
1061
|
`# Example usage for KimiAudio
|
|
1026
|
-
# pip install git+https://github.com/MoonshotAI/Kimi-Audio.git
|
|
1062
|
+
# pip install git+https://github.com/MoonshotAI/Kimi-Audio.git "transformers<5"
|
|
1027
1063
|
|
|
1064
|
+
import soundfile as sf
|
|
1028
1065
|
from kimia_infer.api.kimia import KimiAudio
|
|
1029
1066
|
|
|
1030
1067
|
model = KimiAudio(model_path="${model.id}", load_detokenizer=True)
|
|
@@ -1394,14 +1431,17 @@ pip install -U litert-lm
|
|
|
1394
1431
|
|
|
1395
1432
|
# 2. Download and run this model locally:
|
|
1396
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).
|
|
1397
1436
|
litert-lm run \\
|
|
1398
1437
|
--from-huggingface-repo=${model.id} \\
|
|
1399
1438
|
--prompt="Write me a poem"`,
|
|
1400
1439
|
];
|
|
1401
1440
|
exports.litert_lm = litert_lm;
|
|
1402
1441
|
const tf_keras = (model) => [
|
|
1403
|
-
`# 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.
|
|
1404
1443
|
# See https://github.com/keras-team/tf-keras for more details.
|
|
1444
|
+
# !pip install "huggingface_hub<1.0" tf_keras
|
|
1405
1445
|
from huggingface_hub import from_pretrained_keras
|
|
1406
1446
|
|
|
1407
1447
|
model = from_pretrained_keras("${model.id}")
|
|
@@ -1453,6 +1493,17 @@ from MeshAnything.models.meshanything import MeshAnything
|
|
|
1453
1493
|
model = MeshAnything(args)`,
|
|
1454
1494
|
];
|
|
1455
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;
|
|
1456
1507
|
const multimolecule = (model) => {
|
|
1457
1508
|
const widgetExample = model.widgetData?.[0];
|
|
1458
1509
|
const exampleText = escapeStringForJson(widgetExample?.text ?? "");
|
|
@@ -1633,14 +1684,18 @@ model = pe.VisionTransformer.from_config("${model.id}", pretrained=True)`;
|
|
|
1633
1684
|
exports.perception_encoder = perception_encoder;
|
|
1634
1685
|
const phantom_wan = (model) => [
|
|
1635
1686
|
`from huggingface_hub import snapshot_download
|
|
1636
|
-
from phantom_wan import
|
|
1687
|
+
from phantom_wan import WanI2V, configs
|
|
1688
|
+
from PIL import Image
|
|
1637
1689
|
|
|
1638
1690
|
checkpoint_dir = snapshot_download("${model.id}")
|
|
1639
1691
|
wan_i2v = WanI2V(
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
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)`,
|
|
1644
1699
|
];
|
|
1645
1700
|
exports.phantom_wan = phantom_wan;
|
|
1646
1701
|
const pocket_tts = (model) => [
|
|
@@ -1762,7 +1817,7 @@ exports.tensorflowtts = tensorflowtts;
|
|
|
1762
1817
|
const timm = (model) => [
|
|
1763
1818
|
`import timm
|
|
1764
1819
|
|
|
1765
|
-
model = timm.create_model("
|
|
1820
|
+
model = timm.create_model("hf-hub:${model.id}", pretrained=True)`,
|
|
1766
1821
|
];
|
|
1767
1822
|
exports.timm = timm;
|
|
1768
1823
|
const saelens = ( /* model: ModelData */) => [
|
|
@@ -1790,13 +1845,14 @@ seed_story_cfg = OmegaConf.load(seed_story_cfg_path)
|
|
|
1790
1845
|
seed_story = hydra.utils.instantiate(seed_story_cfg, llm=llm) `,
|
|
1791
1846
|
];
|
|
1792
1847
|
exports.seed_story = seed_story;
|
|
1793
|
-
const
|
|
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) => {
|
|
1794
1851
|
return [
|
|
1795
|
-
`import
|
|
1796
|
-
|
|
1797
|
-
download("${model.id}", "path_to_folder")
|
|
1852
|
+
`from huggingface_hub import hf_hub_download
|
|
1853
|
+
import joblib
|
|
1798
1854
|
model = joblib.load(
|
|
1799
|
-
"${escapeStringForJson(modelFile)}"
|
|
1855
|
+
hf_hub_download("${model.id}", "${escapeStringForJson(modelFile)}")
|
|
1800
1856
|
)
|
|
1801
1857
|
# only load pickle files from sources you trust
|
|
1802
1858
|
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
|
|
@@ -1804,42 +1860,28 @@ model = joblib.load(
|
|
|
1804
1860
|
};
|
|
1805
1861
|
const skopsFormat = (model, modelFile) => {
|
|
1806
1862
|
return [
|
|
1807
|
-
`from
|
|
1863
|
+
`from huggingface_hub import hf_hub_download
|
|
1808
1864
|
from skops.io import load
|
|
1809
|
-
download("${model.id}", "path_to_folder")
|
|
1810
1865
|
# make sure model file is in skops format
|
|
1811
1866
|
# if model is a pickle file, make sure it's from a source you trust
|
|
1812
|
-
model = load("
|
|
1813
|
-
];
|
|
1814
|
-
};
|
|
1815
|
-
const skopsJobLib = (model) => {
|
|
1816
|
-
return [
|
|
1817
|
-
`from huggingface_hub import hf_hub_download
|
|
1818
|
-
import joblib
|
|
1819
|
-
model = joblib.load(
|
|
1820
|
-
hf_hub_download("${model.id}", "sklearn_model.joblib")
|
|
1821
|
-
)
|
|
1822
|
-
# only load pickle files from sources you trust
|
|
1823
|
-
# read more about it here https://skops.readthedocs.io/en/stable/persistence.html`,
|
|
1867
|
+
model = load(hf_hub_download("${model.id}", "${escapeStringForJson(modelFile)}"))`,
|
|
1824
1868
|
];
|
|
1825
1869
|
};
|
|
1826
1870
|
const sklearn = (model) => {
|
|
1871
|
+
const declaredFile = model.config?.sklearn?.model?.file;
|
|
1827
1872
|
if (model.tags.includes("skops")) {
|
|
1828
|
-
|
|
1829
|
-
const skopssaveFormat = model.config?.sklearn?.model_format;
|
|
1830
|
-
if (!skopsmodelFile) {
|
|
1873
|
+
if (!declaredFile) {
|
|
1831
1874
|
return [`# ⚠️ Model filename not specified in config.json`];
|
|
1832
1875
|
}
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
else {
|
|
1837
|
-
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);
|
|
1838
1879
|
}
|
|
1880
|
+
return skopsFormat(model, declaredFile);
|
|
1839
1881
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
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");
|
|
1843
1885
|
};
|
|
1844
1886
|
exports.sklearn = sklearn;
|
|
1845
1887
|
const stable_audio_tools = (model) => [
|
|
@@ -1890,7 +1932,7 @@ const sam2 = (model) => {
|
|
|
1890
1932
|
import torch
|
|
1891
1933
|
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
|
1892
1934
|
|
|
1893
|
-
predictor = SAM2ImagePredictor.from_pretrained(${model.id})
|
|
1935
|
+
predictor = SAM2ImagePredictor.from_pretrained("${model.id}")
|
|
1894
1936
|
|
|
1895
1937
|
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
|
1896
1938
|
predictor.set_image(<your_image>)
|
|
@@ -1899,13 +1941,13 @@ with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
|
|
1899
1941
|
import torch
|
|
1900
1942
|
from sam2.sam2_video_predictor import SAM2VideoPredictor
|
|
1901
1943
|
|
|
1902
|
-
predictor = SAM2VideoPredictor.from_pretrained(${model.id})
|
|
1944
|
+
predictor = SAM2VideoPredictor.from_pretrained("${model.id}")
|
|
1903
1945
|
|
|
1904
1946
|
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
|
1905
1947
|
state = predictor.init_state(<your_video>)
|
|
1906
1948
|
|
|
1907
1949
|
# add new prompts and instantly get the output on the same frame
|
|
1908
|
-
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>)
|
|
1909
1951
|
|
|
1910
1952
|
# propagate the prompts to get masklets throughout the video
|
|
1911
1953
|
for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
|
|
@@ -1927,11 +1969,18 @@ output = inference(image, mask)`,
|
|
|
1927
1969
|
];
|
|
1928
1970
|
exports.sam_3d_objects = sam_3d_objects;
|
|
1929
1971
|
const sam_3d_body = (model) => [
|
|
1930
|
-
`
|
|
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
|
|
1931
1976
|
|
|
1932
|
-
estimator = setup_sam_3d_body(${model.id})
|
|
1933
|
-
|
|
1934
|
-
|
|
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))`,
|
|
1935
1984
|
];
|
|
1936
1985
|
exports.sam_3d_body = sam_3d_body;
|
|
1937
1986
|
const sampleFactory = (model) => [
|
|
@@ -2025,7 +2074,15 @@ queries_emb = model.encode(queries, is_query=True)
|
|
|
2025
2074
|
docs_emb = model.encode(documents, is_query=False)`,
|
|
2026
2075
|
];
|
|
2027
2076
|
}
|
|
2028
|
-
|
|
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) {
|
|
2029
2086
|
return [
|
|
2030
2087
|
`from sentence_transformers import CrossEncoder
|
|
2031
2088
|
|
|
@@ -2043,6 +2100,33 @@ scores = model.predict([(query, passage) for passage in passages])
|
|
|
2043
2100
|
print(scores)`,
|
|
2044
2101
|
];
|
|
2045
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
|
+
}
|
|
2046
2130
|
const exampleSentences = get_widget_examples_from_st_model(model) ?? [
|
|
2047
2131
|
"The weather is lovely today.",
|
|
2048
2132
|
"It's so sunny outside!",
|
|
@@ -2065,7 +2149,10 @@ exports.sentenceTransformers = sentenceTransformers;
|
|
|
2065
2149
|
const setfit = (model) => [
|
|
2066
2150
|
`from setfit import SetFitModel
|
|
2067
2151
|
|
|
2068
|
-
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)`,
|
|
2069
2156
|
];
|
|
2070
2157
|
exports.setfit = setfit;
|
|
2071
2158
|
const spacy = (model) => [
|
|
@@ -2083,7 +2170,10 @@ exports.spacy = spacy;
|
|
|
2083
2170
|
const span_marker = (model) => [
|
|
2084
2171
|
`from span_marker import SpanMarkerModel
|
|
2085
2172
|
|
|
2086
|
-
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)`,
|
|
2087
2177
|
];
|
|
2088
2178
|
exports.span_marker = span_marker;
|
|
2089
2179
|
const stanza = (model) => [
|
|
@@ -2104,6 +2194,8 @@ const speechBrainMethod = (speechbrainInterface) => {
|
|
|
2104
2194
|
return "enhance_file";
|
|
2105
2195
|
case "SepformerSeparation":
|
|
2106
2196
|
return "separate_file";
|
|
2197
|
+
case "SpeakerRecognition":
|
|
2198
|
+
return "verify_files";
|
|
2107
2199
|
default:
|
|
2108
2200
|
return undefined;
|
|
2109
2201
|
}
|
|
@@ -2117,12 +2209,14 @@ const speechbrain = (model) => {
|
|
|
2117
2209
|
if (speechbrainMethod === undefined) {
|
|
2118
2210
|
return [`# interface in config.json invalid`];
|
|
2119
2211
|
}
|
|
2212
|
+
// speaker verification compares two recordings
|
|
2213
|
+
const methodArgs = speechbrainMethod === "verify_files" ? '"speaker1.wav", "speaker2.wav"' : '"file.wav"';
|
|
2120
2214
|
return [
|
|
2121
2215
|
`from speechbrain.pretrained import ${speechbrainInterface}
|
|
2122
2216
|
model = ${speechbrainInterface}.from_hparams(
|
|
2123
2217
|
"${model.id}"
|
|
2124
2218
|
)
|
|
2125
|
-
model.${speechbrainMethod}(
|
|
2219
|
+
model.${speechbrainMethod}(${methodArgs})`,
|
|
2126
2220
|
];
|
|
2127
2221
|
};
|
|
2128
2222
|
exports.speechbrain = speechbrain;
|
|
@@ -2154,7 +2248,7 @@ const transformers = (model) => {
|
|
|
2154
2248
|
: info.processor === "AutoFeatureExtractor"
|
|
2155
2249
|
? "extractor"
|
|
2156
2250
|
: "processor";
|
|
2157
|
-
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")');
|
|
2158
2252
|
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
2159
2253
|
if (model.tags.includes("image-text-to-text")) {
|
|
2160
2254
|
autoSnippet.push("messages = [", [
|
|
@@ -2170,19 +2264,19 @@ const transformers = (model) => {
|
|
|
2170
2264
|
else {
|
|
2171
2265
|
autoSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]");
|
|
2172
2266
|
}
|
|
2173
|
-
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=
|
|
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]:]))`);
|
|
2174
2268
|
}
|
|
2175
2269
|
}
|
|
2176
2270
|
else {
|
|
2177
|
-
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")');
|
|
2178
2272
|
}
|
|
2179
2273
|
if (model.pipeline_tag && library_to_tasks_js_1.LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) {
|
|
2180
2274
|
const pipelineSnippet = ["# Use a pipeline as a high-level helper"];
|
|
2181
2275
|
if (library_to_tasks_js_1.REMOVED_IN_V5_TRANSFORMERS_PIPELINES.includes(model.pipeline_tag)) {
|
|
2182
|
-
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:`, `#
|
|
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"`);
|
|
2183
2277
|
}
|
|
2184
2278
|
pipelineSnippet.push("from transformers import pipeline", "", `pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")");
|
|
2185
|
-
if (model.tags.includes("conversational")) {
|
|
2279
|
+
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
|
|
2186
2280
|
if (model.tags.includes("image-text-to-text")) {
|
|
2187
2281
|
pipelineSnippet.push("messages = [", [
|
|
2188
2282
|
" {",
|
|
@@ -2211,48 +2305,119 @@ const transformers = (model) => {
|
|
|
2211
2305
|
return [autoSnippet.join("\n")];
|
|
2212
2306
|
};
|
|
2213
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
|
+
};
|
|
2214
2312
|
const transformersJS = (model) => {
|
|
2215
2313
|
if (!model.pipeline_tag) {
|
|
2216
2314
|
return [`// ⚠️ Unknown pipeline tag`];
|
|
2217
2315
|
}
|
|
2218
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;
|
|
2219
2339
|
return [
|
|
2220
2340
|
`// npm i ${libName}
|
|
2221
2341
|
import { pipeline } from '${libName}';
|
|
2222
2342
|
|
|
2223
2343
|
// Allocate pipeline
|
|
2224
|
-
const pipe = await pipeline('${
|
|
2344
|
+
const pipe = await pipeline('${task}', '${model.id}');`,
|
|
2225
2345
|
];
|
|
2226
2346
|
};
|
|
2227
2347
|
exports.transformersJS = transformersJS;
|
|
2228
|
-
const
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
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;
|
|
2241
2386
|
};
|
|
2242
2387
|
const peft = (model) => {
|
|
2243
2388
|
const { base_model_name_or_path: peftBaseModel, task_type: peftTaskType } = model.config?.peft ?? {};
|
|
2244
|
-
|
|
2245
|
-
if (!
|
|
2389
|
+
let autoClass = peftTaskType ? PEFT_TASK_TYPE_TO_AUTO_CLASS[peftTaskType] : undefined;
|
|
2390
|
+
if (!autoClass) {
|
|
2246
2391
|
return [`Task type is invalid.`];
|
|
2247
2392
|
}
|
|
2248
|
-
|
|
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) {
|
|
2249
2399
|
return [`Base model is not found.`];
|
|
2250
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
|
+
}
|
|
2251
2416
|
return [
|
|
2252
2417
|
`from peft import PeftModel
|
|
2253
|
-
from transformers import
|
|
2418
|
+
from transformers import ${autoClass}
|
|
2254
2419
|
|
|
2255
|
-
base_model =
|
|
2420
|
+
base_model = ${autoClass}.from_pretrained("${escapeStringForJson(baseModel)}")
|
|
2256
2421
|
model = PeftModel.from_pretrained(base_model, "${model.id}")`,
|
|
2257
2422
|
];
|
|
2258
2423
|
};
|
|
@@ -2286,7 +2451,7 @@ transcriptions = asr_model.transcribe(["file.wav"])`,
|
|
|
2286
2451
|
}
|
|
2287
2452
|
};
|
|
2288
2453
|
const mlAgents = (model) => [
|
|
2289
|
-
`mlagents-load-from-hf --repo-id="${model.id}" --local-dir="./
|
|
2454
|
+
`mlagents-load-from-hf --repo-id="${model.id}" --local-dir="./downloads"`,
|
|
2290
2455
|
];
|
|
2291
2456
|
exports.mlAgents = mlAgents;
|
|
2292
2457
|
const sentis = ( /* model: ModelData */) => [
|
|
@@ -2361,10 +2526,10 @@ model = Model.from_pretrained("${model.id}")`,
|
|
|
2361
2526
|
exports.vfimamba = vfimamba;
|
|
2362
2527
|
const lvface = (model) => [
|
|
2363
2528
|
`from huggingface_hub import hf_hub_download
|
|
2364
|
-
|
|
2529
|
+
from inference_onnx import LVFaceONNXInferencer
|
|
2365
2530
|
|
|
2366
2531
|
model_path = hf_hub_download("${model.id}", "LVFace-L_Glint360K/LVFace-L_Glint360K.onnx")
|
|
2367
|
-
inferencer = LVFaceONNXInferencer(model_path, use_gpu=True
|
|
2532
|
+
inferencer = LVFaceONNXInferencer(model_path, use_gpu=True)
|
|
2368
2533
|
img_path = 'path/to/image1.jpg'
|
|
2369
2534
|
embedding = inferencer.infer_from_image(img_path)`,
|
|
2370
2535
|
];
|
|
@@ -2403,8 +2568,7 @@ const vui = () => [
|
|
|
2403
2568
|
|
|
2404
2569
|
import torchaudio
|
|
2405
2570
|
|
|
2406
|
-
from vui.
|
|
2407
|
-
from vui.model import Vui,
|
|
2571
|
+
from vui.legacy import Vui, render
|
|
2408
2572
|
|
|
2409
2573
|
model = Vui.from_pretrained().cuda()
|
|
2410
2574
|
waveform = render(
|
|
@@ -2412,16 +2576,17 @@ waveform = render(
|
|
|
2412
2576
|
"Hey, here is some random stuff, usually something quite long as the shorter the text the less likely the model can cope!",
|
|
2413
2577
|
)
|
|
2414
2578
|
print(waveform.shape)
|
|
2415
|
-
torchaudio.save("out.
|
|
2579
|
+
torchaudio.save("out.wav", waveform[0], 22050)
|
|
2416
2580
|
`,
|
|
2417
2581
|
];
|
|
2418
2582
|
exports.vui = vui;
|
|
2419
2583
|
const chattts = () => [
|
|
2420
2584
|
`import ChatTTS
|
|
2585
|
+
import torch
|
|
2421
2586
|
import torchaudio
|
|
2422
2587
|
|
|
2423
2588
|
chat = ChatTTS.Chat()
|
|
2424
|
-
chat.
|
|
2589
|
+
chat.load(compile=False) # Set to True for better performance
|
|
2425
2590
|
|
|
2426
2591
|
texts = ["PUT YOUR TEXT HERE",]
|
|
2427
2592
|
|
|
@@ -2431,17 +2596,42 @@ torchaudio.save("output1.wav", torch.from_numpy(wavs[0]), 24000)`,
|
|
|
2431
2596
|
];
|
|
2432
2597
|
exports.chattts = chattts;
|
|
2433
2598
|
const ultralytics = (model) => {
|
|
2434
|
-
//
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
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
|
|
2440
2628
|
return [
|
|
2441
|
-
|
|
2442
|
-
|
|
2629
|
+
`from huggingface_hub import hf_hub_download
|
|
2630
|
+
from ultralytics import YOLO
|
|
2443
2631
|
|
|
2444
|
-
|
|
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)
|
|
2445
2635
|
source = 'http://images.cocodataset.org/val2017/000000039769.jpg'
|
|
2446
2636
|
model.predict(source=source, save=True)`,
|
|
2447
2637
|
];
|
|
@@ -2519,14 +2709,16 @@ model = SwarmFormerModel.from_pretrained("${model.id}")
|
|
|
2519
2709
|
exports.swarmformer = swarmformer;
|
|
2520
2710
|
const univa = (model) => [
|
|
2521
2711
|
`# Follow installation instructions at https://github.com/PKU-YuanGroup/UniWorld-V1
|
|
2522
|
-
|
|
2712
|
+
import torch
|
|
2713
|
+
from transformers import AutoProcessor
|
|
2523
2714
|
from univa.models.qwen2p5vl.modeling_univa_qwen2p5vl import UnivaQwen2p5VLForConditionalGeneration
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
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}")
|
|
2530
2722
|
`,
|
|
2531
2723
|
];
|
|
2532
2724
|
exports.univa = univa;
|
|
@@ -2534,7 +2726,7 @@ const mlx_unknown = (model) => [
|
|
|
2534
2726
|
`# Download the model from the Hub
|
|
2535
2727
|
pip install huggingface_hub[hf_xet]
|
|
2536
2728
|
|
|
2537
|
-
|
|
2729
|
+
hf download ${model.id} --local-dir ${nameWithoutNamespace(model.id)}`,
|
|
2538
2730
|
];
|
|
2539
2731
|
const mlxlm = (model) => [
|
|
2540
2732
|
`# Make sure mlx-lm is installed
|
|
@@ -2591,10 +2783,11 @@ formatted_prompt = apply_chat_template(
|
|
|
2591
2783
|
output = generate(model, processor, formatted_prompt, image)
|
|
2592
2784
|
print(output)`,
|
|
2593
2785
|
];
|
|
2786
|
+
// create_model() takes a name from the mlx-image registry, not a repo id; the weights live in "mlx-vision/<name>-mlxim"
|
|
2594
2787
|
const mlxim = (model) => [
|
|
2595
2788
|
`from mlxim.model import create_model
|
|
2596
2789
|
|
|
2597
|
-
model = create_model(${model.id})`,
|
|
2790
|
+
model = create_model("${nameWithoutNamespace(model.id).replace(/-mlxim$/, "")}")`,
|
|
2598
2791
|
];
|
|
2599
2792
|
exports.mlxim = mlxim;
|
|
2600
2793
|
const mlx = (model) => {
|
|
@@ -2615,7 +2808,10 @@ exports.mlx = mlx;
|
|
|
2615
2808
|
const model2vec = (model) => [
|
|
2616
2809
|
`from model2vec import StaticModel
|
|
2617
2810
|
|
|
2618
|
-
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)`,
|
|
2619
2815
|
];
|
|
2620
2816
|
exports.model2vec = model2vec;
|
|
2621
2817
|
const mobilint = (model) => {
|
|
@@ -2660,7 +2856,8 @@ const pruna = (model) => {
|
|
|
2660
2856
|
};
|
|
2661
2857
|
snippets = snippets.map(ensurePrunaModelImport);
|
|
2662
2858
|
if (model.tags.includes("pruna_pro-ai")) {
|
|
2663
|
-
|
|
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"));
|
|
2664
2861
|
}
|
|
2665
2862
|
return snippets;
|
|
2666
2863
|
};
|
|
@@ -2720,21 +2917,19 @@ const outetts = (model) => {
|
|
|
2720
2917
|
}
|
|
2721
2918
|
// v1.0 HF → minimal runnable snippet
|
|
2722
2919
|
return [
|
|
2723
|
-
`
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
).save("output.wav")
|
|
2737
|
-
`,
|
|
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")`,
|
|
2738
2933
|
];
|
|
2739
2934
|
};
|
|
2740
2935
|
exports.outetts = outetts;
|