@huggingface/tasks
Version:
List of ML tasks for huggingface.co/tasks
1,434 lines (1,247 loc) • 85.3 kB
JavaScript
import { LIBRARY_TASK_MAPPING, REMOVED_IN_V5_TRANSFORMERS_PIPELINES } from "./library-to-tasks.js";
import { getModelInputSnippet } from "./snippets/inputs.js";
import { stringifyMessages } from "./snippets/common.js";
const TAG_CUSTOM_CODE = "custom_code";
function nameWithoutNamespace(modelId) {
const splitted = modelId.split("/");
return splitted.length === 1 ? splitted[0] : splitted[1];
}
const escapeStringForJson = (str) => JSON.stringify(str).slice(1, -1); // slice is needed to remove surrounding quotes added by JSON.stringify
//#region snippets
export const adapters = (model) => [
`from adapters import AutoAdapterModel
model = AutoAdapterModel.from_pretrained("${model.config?.adapter_transformers?.model_name}")
model.load_adapter("${model.id}", set_active=True)`,
];
const allennlpUnknown = (model) => [
`import allennlp_models
from allennlp.predictors.predictor import Predictor
predictor = Predictor.from_path("hf://${model.id}")`,
];
const allennlpQuestionAnswering = (model) => [
`import allennlp_models
from allennlp.predictors.predictor import Predictor
predictor = Predictor.from_path("hf://${model.id}")
predictor_input = {"passage": "My name is Wolfgang and I live in Berlin", "question": "Where do I live?"}
predictions = predictor.predict_json(predictor_input)`,
];
export const allennlp = (model) => {
if (model.tags.includes("question-answering")) {
return allennlpQuestionAnswering(model);
}
return allennlpUnknown(model);
};
export const araclip = (model) => [
`from araclip import AraClip
model = AraClip.from_pretrained("${model.id}")`,
];
export const asteroid = (model) => [
`from asteroid.models import BaseModel
model = BaseModel.from_pretrained("${model.id}")`,
];
export const audioseal = (model) => {
const watermarkSnippet = `# Watermark Generator
from audioseal import AudioSeal
model = AudioSeal.load_generator("${model.id}")
# pass a tensor (tensor_wav) of shape (batch, channels, samples) and a sample rate
wav, sr = tensor_wav, 16000
watermark = model.get_watermark(wav, sr)
watermarked_audio = wav + watermark`;
const detectorSnippet = `# Watermark Detector
from audioseal import AudioSeal
detector = AudioSeal.load_detector("${model.id}")
result, message = detector.detect_watermark(watermarked_audio, sr)`;
return [watermarkSnippet, detectorSnippet];
};
function get_base_diffusers_model(model) {
return model.cardData?.base_model?.toString() ?? "fill-in-base-model";
}
function get_prompt_from_diffusers_model(model) {
const prompt = model.widgetData?.[0]?.text ?? model.cardData?.instance_prompt;
if (prompt) {
return escapeStringForJson(prompt);
}
}
export const ben2 = (model) => [
`import requests
from PIL import Image
from ben2 import AutoModel
url = "https://huggingface.co/datasets/mishig/sample_images/resolve/main/teapot.jpg"
image = Image.open(requests.get(url, stream=True).raw)
model = AutoModel.from_pretrained("${model.id}")
model.to("cuda").eval()
foreground = model.inference(image)
`,
];
export const bertopic = (model) => [
`from bertopic import BERTopic
model = BERTopic.load("${model.id}")`,
];
export const bm25s = (model) => [
`from bm25s.hf import BM25HF
retriever = BM25HF.load_from_hub("${model.id}")`,
];
export const chatterbox = () => [
`# pip install chatterbox-tts
import torchaudio as ta
from chatterbox.tts import ChatterboxTTS
model = ChatterboxTTS.from_pretrained(device="cuda")
text = "Ezreal and Jinx teamed up with Ahri, Yasuo, and Teemo to take down the enemy's Nexus in an epic late-game pentakill."
wav = model.generate(text)
ta.save("test-1.wav", wav, model.sr)
# If you want to synthesize with a different voice, specify the audio prompt
AUDIO_PROMPT_PATH="YOUR_FILE.wav"
wav = model.generate(text, audio_prompt_path=AUDIO_PROMPT_PATH)
ta.save("test-2.wav", wav, model.sr)`,
];
export const chronos_forecasting = (model) => {
const installSnippet = `pip install chronos-forecasting`;
const exampleSnippet = `import pandas as pd
from chronos import BaseChronosPipeline
pipeline = BaseChronosPipeline.from_pretrained("${model.id}", device_map="cuda")
# Load historical data
context_df = pd.read_csv("https://autogluon.s3.us-west-2.amazonaws.com/datasets/timeseries/misc/AirPassengers.csv")
# Generate predictions
pred_df = pipeline.predict_df(
context_df,
prediction_length=36, # Number of steps to forecast
quantile_levels=[0.1, 0.5, 0.9], # Quantiles for probabilistic forecast
id_column="item_id", # Column identifying different time series
timestamp_column="Month", # Column with datetime information
target="#Passengers", # Column(s) with time series values to predict
)`;
return [installSnippet, exampleSnippet];
};
export const collectorvision = (model) => [
`pip install git+https://github.com/HanClinto/CollectorVision huggingface_hub`,
`from huggingface_hub import hf_hub_download
import collector_vision as cvg
checkpoint = hf_hub_download(repo_id="${model.id}", filename="model.onnx")
# Detector models, such as Cornelius:
detector = cvg.NeuralCornerDetector(checkpoint)
# Embedder models, such as Milo:
embedder = cvg.NeuralEmbedder(checkpoint)`,
];
export const colipri = (model) => {
const installSnippet = `pip install colipri`;
const exampleSnippet = `from colipri import get_model
from colipri import get_processor
from colipri import load_sample_ct
from colipri import ZeroShotImageClassificationPipeline
model = get_model().cuda()
processor = get_processor()
pipeline = ZeroShotImageClassificationPipeline("${model.id}", processor)
image = load_sample_ct()
pipeline(image, ["No lung nodules", "Lung nodules"])
`;
return [installSnippet, exampleSnippet];
};
export const sap_rpt_one_oss = () => {
const installSnippet = `pip install git+https://github.com/SAP-samples/sap-rpt-1-oss`;
const classificationSnippet = `# Run a classification task
from sklearn.datasets import load_breast_cancer
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sap_rpt_oss import SAP_RPT_OSS_Classifier
# Load sample data
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Initialize a classifier, 8k context and 8-fold bagging gives best performance, reduce if running out of memory
clf = SAP_RPT_OSS_Classifier(max_context_size=8192, bagging=8)
clf.fit(X_train, y_train)
# Predict probabilities
prediction_probabilities = clf.predict_proba(X_test)
# Predict labels
predictions = clf.predict(X_test)
print("Accuracy", accuracy_score(y_test, predictions))`;
const regressionsSnippet = `# Run a regression task
from sklearn.datasets import fetch_openml
from sklearn.metrics import r2_score
from sklearn.model_selection import train_test_split
from sap_rpt_oss import SAP_RPT_OSS_Regressor
# Load sample data
df = fetch_openml(data_id=531, as_frame=True)
X = df.data
y = df.target.astype(float)
# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Initialize the regressor, 8k context and 8-fold bagging gives best performance, reduce if running out of memory
regressor = SAP_RPT_OSS_Regressor(max_context_size=8192, bagging=8)
regressor.fit(X_train, y_train)
# Predict on the test set
predictions = regressor.predict(X_test)
r2 = r2_score(y_test, predictions)
print("R² Score:", r2)`;
return [installSnippet, classificationSnippet, regressionsSnippet];
};
export const cxr_foundation = () => [
`# pip install git+https://github.com/Google-Health/cxr-foundation.git#subdirectory=python
# Load image as grayscale (Stillwaterising, CC0, via Wikimedia Commons)
import requests
from PIL import Image
from io import BytesIO
image_url = "https://upload.wikimedia.org/wikipedia/commons/c/c8/Chest_Xray_PA_3-8-2010.png"
img = Image.open(requests.get(image_url, headers={'User-Agent': 'Demo'}, stream=True).raw).convert('L')
# Run inference
from clientside.clients import make_hugging_face_client
cxr_client = make_hugging_face_client('cxr_model')
print(cxr_client.get_image_embeddings_from_images([img]))`,
];
export const depth_anything_v2 = (model) => {
let encoder;
let features;
let out_channels;
encoder = "<ENCODER>";
features = "<NUMBER_OF_FEATURES>";
out_channels = "<OUT_CHANNELS>";
if (model.id === "depth-anything/Depth-Anything-V2-Small") {
encoder = "vits";
features = "64";
out_channels = "[48, 96, 192, 384]";
}
else if (model.id === "depth-anything/Depth-Anything-V2-Base") {
encoder = "vitb";
features = "128";
out_channels = "[96, 192, 384, 768]";
}
else if (model.id === "depth-anything/Depth-Anything-V2-Large") {
encoder = "vitl";
features = "256";
out_channels = "[256, 512, 1024, 1024";
}
return [
`
# Install from https://github.com/DepthAnything/Depth-Anything-V2
# Load the model and infer depth from an image
import cv2
import torch
from depth_anything_v2.dpt import DepthAnythingV2
# instantiate the model
model = DepthAnythingV2(encoder="${encoder}", features=${features}, out_channels=${out_channels})
# load the weights
filepath = hf_hub_download(repo_id="${model.id}", filename="depth_anything_v2_${encoder}.pth", repo_type="model")
state_dict = torch.load(filepath, map_location="cpu")
model.load_state_dict(state_dict).eval()
raw_img = cv2.imread("your/image/path")
depth = model.infer_image(raw_img) # HxW raw depth map in numpy
`,
];
};
export const depth_pro = (model) => {
const installSnippet = `# Download checkpoint
pip install huggingface-hub
huggingface-cli download --local-dir checkpoints ${model.id}`;
const inferenceSnippet = `import depth_pro
# Load model and preprocessing transform
model, transform = depth_pro.create_model_and_transforms()
model.eval()
# Load and preprocess an image.
image, _, f_px = depth_pro.load_rgb("example.png")
image = transform(image)
# Run inference.
prediction = model.infer(image, f_px=f_px)
# Results: 1. Depth in meters
depth = prediction["depth"]
# Results: 2. Focal length in pixels
focallength_px = prediction["focallength_px"]`;
return [installSnippet, inferenceSnippet];
};
export const derm_foundation = () => [
`from huggingface_hub import from_pretrained_keras
import tensorflow as tf, requests
# Load and format input
IMAGE_URL = "https://storage.googleapis.com/dx-scin-public-data/dataset/images/3445096909671059178.png"
input_tensor = tf.train.Example(
features=tf.train.Features(
feature={
"image/encoded": tf.train.Feature(
bytes_list=tf.train.BytesList(value=[requests.get(IMAGE_URL, stream=True).content])
)
}
)
).SerializeToString()
# Load model and run inference
loaded_model = from_pretrained_keras("google/derm-foundation")
infer = loaded_model.signatures["serving_default"]
print(infer(inputs=tf.constant([input_tensor])))`,
];
export const dia = (model) => [
`import soundfile as sf
from dia.model import Dia
model = Dia.from_pretrained("${model.id}")
text = "[S1] Dia is an open weights text to dialogue model. [S2] You get full control over scripts and voices. [S1] Wow. Amazing. (laughs) [S2] Try it now on Git hub or Hugging Face."
output = model.generate(text)
sf.write("simple.mp3", output, 44100)`,
];
export const dia2 = (model) => [
`from dia2 import Dia2, GenerationConfig, SamplingConfig
dia = Dia2.from_repo("${model.id}", device="cuda", dtype="bfloat16")
config = GenerationConfig(
cfg_scale=2.0,
audio=SamplingConfig(temperature=0.8, top_k=50),
use_cuda_graph=True,
)
result = dia.generate("[S1] Hello Dia2!", config=config, output_wav="hello.wav", verbose=True)
`,
];
export const describe_anything = (model) => [
`# pip install git+https://github.com/NVlabs/describe-anything
from huggingface_hub import snapshot_download
from dam import DescribeAnythingModel
snapshot_download(${model.id}, local_dir="checkpoints")
dam = DescribeAnythingModel(
model_path="checkpoints",
conv_mode="v1",
prompt_mode="focal_prompt",
)`,
];
const diffusers_install = "pip install -U diffusers transformers accelerate";
const diffusersDefaultPrompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k";
const diffusersImg2ImgDefaultPrompt = "Turn this cat into a dog";
const diffusersVideoDefaultPrompt = "A man with short gray hair plays a red electric guitar.";
const diffusers_default = (model) => [
`import torch
from diffusers import DiffusionPipeline
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${model.id}", torch_dtype=torch.bfloat16, device_map="cuda")
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersDefaultPrompt}"
image = pipe(prompt).images[0]`,
];
const diffusers_image_to_image = (model) => [
`import torch
from diffusers import DiffusionPipeline
from diffusers.utils import load_image
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${model.id}", torch_dtype=torch.bfloat16, device_map="cuda")
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersImg2ImgDefaultPrompt}"
input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")
image = pipe(image=input_image, prompt=prompt).images[0]`,
];
const diffusers_image_to_video = (model) => [
`import torch
from diffusers import DiffusionPipeline
from diffusers.utils import load_image, export_to_video
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${model.id}", torch_dtype=torch.bfloat16, device_map="cuda")
pipe.to("cuda")
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersVideoDefaultPrompt}"
image = load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png"
)
output = pipe(image=image, prompt=prompt).frames[0]
export_to_video(output, "output.mp4")`,
];
const diffusers_controlnet = (model) => [
`from diffusers import ControlNetModel, StableDiffusionControlNetPipeline
controlnet = ControlNetModel.from_pretrained("${model.id}")
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"${get_base_diffusers_model(model)}", controlnet=controlnet
)`,
];
const diffusers_lora = (model) => [
`import torch
from diffusers import DiffusionPipeline
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${get_base_diffusers_model(model)}", torch_dtype=torch.bfloat16, device_map="cuda")
pipe.load_lora_weights("${model.id}")
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersDefaultPrompt}"
image = pipe(prompt).images[0]`,
];
const diffusers_lora_image_to_image = (model) => [
`import torch
from diffusers import DiffusionPipeline
from diffusers.utils import load_image
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${get_base_diffusers_model(model)}", torch_dtype=torch.bfloat16, device_map="cuda")
pipe.load_lora_weights("${model.id}")
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersImg2ImgDefaultPrompt}"
input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cat.png")
image = pipe(image=input_image, prompt=prompt).images[0]`,
];
const diffusers_lora_text_to_video = (model) => [
`import torch
from diffusers import DiffusionPipeline
from diffusers.utils import export_to_video
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${get_base_diffusers_model(model)}", torch_dtype=torch.bfloat16, device_map="cuda")
pipe.load_lora_weights("${model.id}")
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersVideoDefaultPrompt}"
output = pipe(prompt=prompt).frames[0]
export_to_video(output, "output.mp4")`,
];
const diffusers_lora_image_to_video = (model) => [
`import torch
from diffusers import DiffusionPipeline
from diffusers.utils import load_image, export_to_video
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${get_base_diffusers_model(model)}", torch_dtype=torch.bfloat16, device_map="cuda")
pipe.load_lora_weights("${model.id}")
prompt = "${get_prompt_from_diffusers_model(model) ?? diffusersVideoDefaultPrompt}"
input_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png")
image = pipe(image=input_image, prompt=prompt).frames[0]
export_to_video(output, "output.mp4")`,
];
const diffusers_textual_inversion = (model) => [
`import torch
from diffusers import DiffusionPipeline
# switch to "mps" for apple devices
pipe = DiffusionPipeline.from_pretrained("${get_base_diffusers_model(model)}", torch_dtype=torch.bfloat16, device_map="cuda")
pipe.load_textual_inversion("${model.id}")`,
];
const diffusers_flux_fill = (model) => [
`import torch
from diffusers import FluxFillPipeline
from diffusers.utils import load_image
image = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup.png")
mask = load_image("https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/cup_mask.png")
# switch to "mps" for apple devices
pipe = FluxFillPipeline.from_pretrained("${model.id}", torch_dtype=torch.bfloat16, device_map="cuda")
image = pipe(
prompt="a white paper cup",
image=image,
mask_image=mask,
height=1632,
width=1232,
guidance_scale=30,
num_inference_steps=50,
max_sequence_length=512,
generator=torch.Generator("cpu").manual_seed(0)
).images[0]
image.save(f"flux-fill-dev.png")`,
];
const diffusers_inpainting = (model) => [
`import torch
from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image
# switch to "mps" for apple devices
pipe = AutoPipelineForInpainting.from_pretrained("${model.id}", torch_dtype=torch.float16, variant="fp16", device_map="cuda")
img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
image = load_image(img_url).resize((1024, 1024))
mask_image = load_image(mask_url).resize((1024, 1024))
prompt = "a tiger sitting on a park bench"
generator = torch.Generator(device="cuda").manual_seed(0)
image = pipe(
prompt=prompt,
image=image,
mask_image=mask_image,
guidance_scale=8.0,
num_inference_steps=20, # steps between 15 and 30 work well for us
strength=0.99, # make sure to use \`strength\` below 1.0
generator=generator,
).images[0]`,
];
export const diffusers = (model) => {
let codeSnippets;
if (model.tags.includes("StableDiffusionInpaintPipeline") ||
model.tags.includes("StableDiffusionXLInpaintPipeline")) {
codeSnippets = diffusers_inpainting(model);
}
else if (model.tags.includes("controlnet")) {
codeSnippets = diffusers_controlnet(model);
}
else if (model.tags.includes("lora")) {
if (model.pipeline_tag === "image-to-image") {
codeSnippets = diffusers_lora_image_to_image(model);
}
else if (model.pipeline_tag === "image-to-video") {
codeSnippets = diffusers_lora_image_to_video(model);
}
else if (model.pipeline_tag === "text-to-video") {
codeSnippets = diffusers_lora_text_to_video(model);
}
else {
codeSnippets = diffusers_lora(model);
}
}
else if (model.tags.includes("textual_inversion")) {
codeSnippets = diffusers_textual_inversion(model);
}
else if (model.tags.includes("FluxFillPipeline")) {
codeSnippets = diffusers_flux_fill(model);
}
else if (model.pipeline_tag === "image-to-video") {
codeSnippets = diffusers_image_to_video(model);
}
else if (model.pipeline_tag === "image-to-image") {
codeSnippets = diffusers_image_to_image(model);
}
else {
codeSnippets = diffusers_default(model);
}
return [diffusers_install, ...codeSnippets];
};
export const diffusionkit = (model) => {
const sd3Snippet = `# Pipeline for Stable Diffusion 3
from diffusionkit.mlx import DiffusionPipeline
pipeline = DiffusionPipeline(
shift=3.0,
use_t5=False,
model_version=${model.id},
low_memory_mode=True,
a16=True,
w16=True,
)`;
const fluxSnippet = `# Pipeline for Flux
from diffusionkit.mlx import FluxPipeline
pipeline = FluxPipeline(
shift=1.0,
model_version=${model.id},
low_memory_mode=True,
a16=True,
w16=True,
)`;
const generateSnippet = `# Image Generation
HEIGHT = 512
WIDTH = 512
NUM_STEPS = ${model.tags.includes("flux") ? 4 : 50}
CFG_WEIGHT = ${model.tags.includes("flux") ? 0 : 5}
image, _ = pipeline.generate_image(
"a photo of a cat",
cfg_weight=CFG_WEIGHT,
num_steps=NUM_STEPS,
latent_size=(HEIGHT // 8, WIDTH // 8),
)`;
const pipelineSnippet = model.tags.includes("flux") ? fluxSnippet : sd3Snippet;
return [pipelineSnippet, generateSnippet];
};
export const cartesia_pytorch = (model) => [
`# pip install --no-binary :all: cartesia-pytorch
from cartesia_pytorch import ReneLMHeadModel
from transformers import AutoTokenizer
model = ReneLMHeadModel.from_pretrained("${model.id}")
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-1B-hf")
in_message = ["Rene Descartes was"]
inputs = tokenizer(in_message, return_tensors="pt")
outputs = model.generate(inputs.input_ids, max_length=50, top_k=100, top_p=0.99)
out_message = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
print(out_message)
)`,
];
export const cartesia_mlx = (model) => [
`import mlx.core as mx
import cartesia_mlx as cmx
model = cmx.from_pretrained("${model.id}")
model.set_dtype(mx.float32)
prompt = "Rene Descartes was"
for text in model.generate(
prompt,
max_tokens=500,
eval_every_n=5,
verbose=True,
top_p=0.99,
temperature=0.85,
):
print(text, end="", flush=True)
`,
];
export const edsnlp = (model) => {
const packageName = nameWithoutNamespace(model.id).replaceAll("-", "_");
return [
`# Load it from the Hub directly
import edsnlp
nlp = edsnlp.load("${model.id}")
`,
`# Or install it as a package
!pip install git+https://huggingface.co/${model.id}
# and import it as a module
import ${packageName}
nlp = ${packageName}.load() # or edsnlp.load("${packageName}")
`,
];
};
export const espnetTTS = (model) => [
`from espnet2.bin.tts_inference import Text2Speech
model = Text2Speech.from_pretrained("${model.id}")
speech, *_ = model("text to generate speech from")`,
];
export const espnetASR = (model) => [
`from espnet2.bin.asr_inference import Speech2Text
model = Speech2Text.from_pretrained(
"${model.id}"
)
speech, rate = soundfile.read("speech.wav")
text, *_ = model(speech)[0]`,
];
const espnetUnknown = () => [`unknown model type (must be text-to-speech or automatic-speech-recognition)`];
export const espnet = (model) => {
if (model.tags.includes("text-to-speech")) {
return espnetTTS(model);
}
else if (model.tags.includes("automatic-speech-recognition")) {
return espnetASR(model);
}
return espnetUnknown();
};
export const fairseq = (model) => [
`from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
"${model.id}"
)`,
];
export const flair = (model) => [
`from flair.models import SequenceTagger
tagger = SequenceTagger.load("${model.id}")`,
];
export const flextab = () => {
const installSnippet = `pip install git+https://github.com/SAP-samples/flextab`;
const classificationSnippet = `# Run a classification task
from sklearn.datasets import load_breast_cancer
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from flextab import FlexTabClassifier
# Load sample data
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Initialize a classifier, 8k context and 8-fold bagging gives best performance, reduce if running out of memory
clf = FlexTabClassifier(max_context_size=8192, bagging=8)
clf.fit(X_train, y_train)
# Predict probabilities
prediction_probabilities = clf.predict_proba(X_test)
# Predict labels
predictions = clf.predict(X_test)
print("Accuracy", accuracy_score(y_test, predictions))`;
const regressionsSnippet = `# Run a regression task
from sklearn.datasets import fetch_openml
from sklearn.metrics import r2_score
from sklearn.model_selection import train_test_split
from flextab import FlexTabRegressor
# Load sample data
df = fetch_openml(data_id=531, as_frame=True)
X = df.data
y = df.target.astype(float)
# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5, random_state=42)
# Initialize the regressor, 8k context and 8-fold bagging gives best performance, reduce if running out of memory
regressor = FlexTabRegressor(max_context_size=8192, bagging=8)
regressor.fit(X_train, y_train)
# Predict on the test set
predictions = regressor.predict(X_test)
r2 = r2_score(y_test, predictions)
print("R² Score:", r2)`;
const matchingSnippet = `# Run a matching task
from sklearn.metrics import accuracy_score, roc_auc_score
from flextab import FlexTabMatcher
from flextab.utils.test_utils import load_febrl4
left_train, left_test, right_train, right_test, y_train, y_test = load_febrl4()
matcher = FlexTabMatcher(max_context_size=8192, bagging=1)
matcher.fit(left_train, right_train, y_train)
predictions = matcher.predict(left_test, right_test)
print(f'Accuracy {accuracy_score(y_test, predictions):.2%}')
# Probabilities (e.g. for thresholding or AUROC):
# probas = matcher.predict_proba_matching(left_test, right_test)
# print(f'AUROC {roc_auc_score(y_test, probas[:, 1]):.2%}')`;
return [installSnippet, classificationSnippet, regressionsSnippet, matchingSnippet];
};
export const gliner = (model) => [
`from gliner import GLiNER
model = GLiNER.from_pretrained("${model.id}")`,
];
export const gliner2 = (model) => [
`from gliner2 import GLiNER2
model = GLiNER2.from_pretrained("${model.id}")
# Extract entities
text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday."
result = extractor.extract_entities(text, ["company", "person", "product", "location"])
print(result)`,
];
export const indextts = (model) => [
`# Download model
from huggingface_hub import snapshot_download
snapshot_download(${model.id}, local_dir="checkpoints")
from indextts.infer import IndexTTS
# Ensure config.yaml is present in the checkpoints directory
tts = IndexTTS(model_dir="checkpoints", cfg_path="checkpoints/config.yaml")
voice = "path/to/your/reference_voice.wav" # Path to the voice reference audio file
text = "Hello, how are you?"
output_path = "output_index.wav"
tts.infer(voice, text, output_path)`,
];
export const htrflow = (model) => [
`# CLI usage
# see docs: https://ai-riksarkivet.github.io/htrflow/latest/getting_started/quick_start.html
htrflow pipeline <path/to/pipeline.yaml> <path/to/image>`,
`# Python usage
from htrflow.pipeline.pipeline import Pipeline
from htrflow.pipeline.steps import Task
from htrflow.models.framework.model import ModelClass
pipeline = Pipeline(
[
Task(
ModelClass, {"model": "${model.id}"}, {}
),
])`,
];
export const keras = (model) => [
`# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://${model.id}")
`,
];
const _keras_hub_causal_lm = (modelId) => `
import keras_hub
# Load CausalLM model (optional: use half precision for inference)
causal_lm = keras_hub.models.CausalLM.from_preset("hf://${modelId}", dtype="bfloat16")
causal_lm.compile(sampler="greedy") # (optional) specify a sampler
# Generate text
causal_lm.generate("Keras: deep learning for", max_length=64)
`;
const _keras_hub_text_to_image = (modelId) => `
import keras_hub
# Load TextToImage model (optional: use half precision for inference)
text_to_image = keras_hub.models.TextToImage.from_preset("hf://${modelId}", dtype="bfloat16")
# Generate images with a TextToImage model.
text_to_image.generate("Astronaut in a jungle")
`;
const _keras_hub_text_classifier = (modelId) => `
import keras_hub
# Load TextClassifier model
text_classifier = keras_hub.models.TextClassifier.from_preset(
"hf://${modelId}",
num_classes=2,
)
# Fine-tune
text_classifier.fit(x=["Thilling adventure!", "Total snoozefest."], y=[1, 0])
# Classify text
text_classifier.predict(["Not my cup of tea."])
`;
const _keras_hub_image_classifier = (modelId) => `
import keras_hub
import keras
# Load ImageClassifier model
image_classifier = keras_hub.models.ImageClassifier.from_preset(
"hf://${modelId}",
num_classes=2,
)
# Fine-tune
image_classifier.fit(
x=keras.random.randint((32, 64, 64, 3), 0, 256),
y=keras.random.randint((32, 1), 0, 2),
)
# Classify image
image_classifier.predict(keras.random.randint((1, 64, 64, 3), 0, 256))
`;
const _keras_hub_tasks_with_example = {
CausalLM: _keras_hub_causal_lm,
TextToImage: _keras_hub_text_to_image,
TextClassifier: _keras_hub_text_classifier,
ImageClassifier: _keras_hub_image_classifier,
};
const _keras_hub_task_without_example = (task, modelId) => `
import keras_hub
# Create a ${task} model
task = keras_hub.models.${task}.from_preset("hf://${modelId}")
`;
const _keras_hub_generic_backbone = (modelId) => `
import keras_hub
# Create a Backbone model unspecialized for any task
backbone = keras_hub.models.Backbone.from_preset("hf://${modelId}")
`;
export const keras_hub = (model) => {
const modelId = model.id;
const tasks = model.config?.keras_hub?.tasks ?? [];
const snippets = [];
// First, generate tasks with examples
for (const [task, snippet] of Object.entries(_keras_hub_tasks_with_example)) {
if (tasks.includes(task)) {
snippets.push(snippet(modelId));
}
}
// Then, add remaining tasks
for (const task of tasks) {
if (!Object.keys(_keras_hub_tasks_with_example).includes(task)) {
snippets.push(_keras_hub_task_without_example(task, modelId));
}
}
// Finally, add generic backbone snippet
snippets.push(_keras_hub_generic_backbone(modelId));
return snippets;
};
export const kernels = (model) => [
`# !pip install kernels
from kernels import get_kernel
kernel = get_kernel("${model.id}")`,
];
export const kimi_audio = (model) => [
`# Example usage for KimiAudio
# pip install git+https://github.com/MoonshotAI/Kimi-Audio.git
from kimia_infer.api.kimia import KimiAudio
model = KimiAudio(model_path="${model.id}", load_detokenizer=True)
sampling_params = {
"audio_temperature": 0.8,
"audio_top_k": 10,
"text_temperature": 0.0,
"text_top_k": 5,
}
# For ASR
asr_audio = "asr_example.wav"
messages_asr = [
{"role": "user", "message_type": "text", "content": "Please transcribe the following audio:"},
{"role": "user", "message_type": "audio", "content": asr_audio}
]
_, text = model.generate(messages_asr, **sampling_params, output_type="text")
print(text)
# For Q&A
qa_audio = "qa_example.wav"
messages_conv = [{"role": "user", "message_type": "audio", "content": qa_audio}]
wav, text = model.generate(messages_conv, **sampling_params, output_type="both")
sf.write("output_audio.wav", wav.cpu().view(-1).numpy(), 24000)
print(text)
`,
];
export const kittentts = (model) => [
`from kittentts import KittenTTS
m = KittenTTS("${model.id}")
audio = m.generate("This high quality TTS model works without a GPU")
# Save the audio
import soundfile as sf
sf.write('output.wav', audio, 24000)`,
];
export const ltx = (model) => {
const localDir = `models/${nameWithoutNamespace(model.id)}`;
const install = `# Install the LTX-2 pipelines
git clone https://github.com/Lightricks/LTX-2.git
cd LTX-2
uv sync --frozen`;
// Every pipeline needs the Gemma text encoder, which lives in a separate repo.
const download = `# Download the weights from this repo, plus the Gemma text encoder
hf download ${model.id} --local-dir ${localDir}
hf download google/gemma-3-12b-it-qat-q4_0-unquantized --local-dir models/gemma-3-12b`;
// Add "--image <path> <frame_idx> <strength>" to any command below to condition on
// an image (e.g. "--image image.jpg 0 0.8"), turning text-to-video into image-to-video.
const imageToVideoHint = `# For image-to-video, add: --image path/to/image.jpg 0 0.8`;
const tags = model.tags ?? [];
// IC-LoRA: video-to-video / image-to-video with a control (reference) signal.
// Checked before "lora" because an IC-LoRA repo may carry both tags.
if (tags.includes("ic-lora")) {
return [
install,
download,
`# Video-to-video with the IC-LoRA (runs on the distilled base model)
uv run python -m ltx_pipelines.ic_lora \\
--distilled-checkpoint-path path/to/distilled_checkpoint.safetensors \\
--spatial-upsampler-path path/to/spatial_upsampler.safetensors \\
--gemma-root models/gemma-3-12b \\
--lora ${localDir}/<weights>.safetensors 1.0 \\
--video-conditioning reference.mp4 1.0 \\
--prompt "your prompt here" \\
--output-path output.mp4`,
];
}
// Standard LoRA applied on top of the base pipeline.
if (tags.includes("lora")) {
return [
install,
download,
`# Text/image-to-video with the LoRA on the HQ two-stage base pipeline
uv run python -m ltx_pipelines.ti2vid_two_stages_hq \\
--checkpoint-path path/to/checkpoint.safetensors \\
--distilled-lora path/to/distilled_lora.safetensors 0.8 \\
--spatial-upsampler-path path/to/spatial_upsampler.safetensors \\
--gemma-root models/gemma-3-12b \\
--lora ${localDir}/<weights>.safetensors 1.0 \\
--prompt "your prompt here" \\
--output-path output.mp4
${imageToVideoHint}`,
];
}
// Base model: the fast (distilled) and HQ (two-stage) pipelines. Substitute the
// .safetensors filenames with the ones listed under this repo's "Files and versions".
return [
install,
download,
`# Fast pipeline (distilled model, no distilled LoRA needed)
uv run python -m ltx_pipelines.distilled \\
--distilled-checkpoint-path ${localDir}/<distilled-checkpoint>.safetensors \\
--spatial-upsampler-path ${localDir}/<spatial-upsampler>.safetensors \\
--gemma-root models/gemma-3-12b \\
--prompt "A beautiful sunset over the ocean" \\
--output-path output.mp4
${imageToVideoHint}`,
`# HQ pipeline (two-stage, higher quality)
uv run python -m ltx_pipelines.ti2vid_two_stages_hq \\
--checkpoint-path ${localDir}/<checkpoint>.safetensors \\
--distilled-lora ${localDir}/<distilled-lora>.safetensors 0.8 \\
--spatial-upsampler-path ${localDir}/<spatial-upsampler>.safetensors \\
--gemma-root models/gemma-3-12b \\
--prompt "A beautiful sunset over the ocean" \\
--output-path output.mp4
${imageToVideoHint}`,
];
};
export const lightning_ir = (model) => {
if (model.tags.includes("bi-encoder")) {
return [
`#install from https://github.com/webis-de/lightning-ir
from lightning_ir import BiEncoderModule
model = BiEncoderModule("${model.id}")
model.score("query", ["doc1", "doc2", "doc3"])`,
];
}
else if (model.tags.includes("cross-encoder")) {
return [
`#install from https://github.com/webis-de/lightning-ir
from lightning_ir import CrossEncoderModule
model = CrossEncoderModule("${model.id}")
model.score("query", ["doc1", "doc2", "doc3"])`,
];
}
return [
`#install from https://github.com/webis-de/lightning-ir
from lightning_ir import BiEncoderModule, CrossEncoderModule
# depending on the model type, use either BiEncoderModule or CrossEncoderModule
model = BiEncoderModule("${model.id}")
# model = CrossEncoderModule("${model.id}")
model.score("query", ["doc1", "doc2", "doc3"])`,
];
};
export const llama_cpp_python = (model) => {
const snippets = [
`# !pip install llama-cpp-python
from llama_cpp import Llama
llm = Llama.from_pretrained(
repo_id="${model.id}",
filename="{{GGUF_FILE}}",
)
`,
];
if (model.tags.includes("conversational")) {
const messages = getModelInputSnippet(model);
snippets.push(`llm.create_chat_completion(
messages = ${stringifyMessages(messages, { attributeKeyQuotes: true, indent: "\t" })}
)`);
}
else {
snippets.push(`output = llm(
"Once upon a time,",
max_tokens=512,
echo=True
)
print(output)`);
}
return snippets;
};
export const lerobot = (model) => {
if (model.tags.includes("smolvla")) {
const smolvlaSnippets = [
// Installation snippet
`# See https://github.com/huggingface/lerobot?tab=readme-ov-file#installation for more details
git clone https://github.com/huggingface/lerobot.git
cd lerobot
pip install -e .[smolvla]`,
// Finetune snippet
`# Launch finetuning on your dataset
python lerobot/scripts/train.py \\
--policy.path=${model.id} \\
--dataset.repo_id=lerobot/svla_so101_pickplace \\
--batch_size=64 \\
--steps=20000 \\
--output_dir=outputs/train/my_smolvla \\
--job_name=my_smolvla_training \\
--policy.device=cuda \\
--wandb.enable=true`,
];
if (model.id !== "lerobot/smolvla_base") {
// Inference snippet (only if not base model)
smolvlaSnippets.push(`# Run the policy using the record function
python -m lerobot.record \\
--robot.type=so101_follower \\
--robot.port=/dev/ttyACM0 \\ # <- Use your port
--robot.id=my_blue_follower_arm \\ # <- Use your robot id
--robot.cameras="{ front: {type: opencv, index_or_path: 8, width: 640, height: 480, fps: 30}}" \\ # <- Use your cameras
--dataset.single_task="Grasp a lego block and put it in the bin." \\ # <- Use the same task description you used in your dataset recording
--dataset.repo_id=HF_USER/dataset_name \\ # <- This will be the dataset name on HF Hub
--dataset.episode_time_s=50 \\
--dataset.num_episodes=10 \\
--policy.path=${model.id}`);
}
return smolvlaSnippets;
}
return [];
};
export const litert_lm = (model) => [
`# LiteRT-LM runs on various platforms (Android, iOS, Windows, Linux, macOS, IoT, Web/WASM)
# and supports many APIs (C++, Python, Kotlin, Swift, JavaScript, Flutter).
# For platform-specific integration guides, please refer to the official developer website:
# https://ai.google.dev/edge/litert-lm
# To try LiteRT-LM, the easiest way is to use our CLI tool.
# 1. Install the LiteRT-LM CLI tool:
pip install -U litert-lm
# 2. Download and run this model locally:
# See: https://ai.google.dev/edge/litert-lm/cli
litert-lm run \\
--from-huggingface-repo=${model.id} \\
--prompt="Write me a poem"`,
];
export const tf_keras = (model) => [
`# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy)
# See https://github.com/keras-team/tf-keras for more details.
from huggingface_hub import from_pretrained_keras
model = from_pretrained_keras("${model.id}")
`,
];
export const mamba_ssm = (model) => [
`from mamba_ssm import MambaLMHeadModel
model = MambaLMHeadModel.from_pretrained("${model.id}")`,
];
export const mars5_tts = (model) => [
`# Install from https://github.com/Camb-ai/MARS5-TTS
from inference import Mars5TTS
mars5 = Mars5TTS.from_pretrained("${model.id}")`,
];
export const matanyone = (model) => [
`# Install from https://github.com/pq-yang/MatAnyone.git
from matanyone.model.matanyone import MatAnyone
model = MatAnyone.from_pretrained("${model.id}")`,
`
from matanyone import InferenceCore
processor = InferenceCore("${model.id}")`,
];
export const mesh_anything = () => [
`# Install from https://github.com/buaacyw/MeshAnything.git
from MeshAnything.models.meshanything import MeshAnything
# refer to https://github.com/buaacyw/MeshAnything/blob/main/main.py#L91 on how to define args
# and https://github.com/buaacyw/MeshAnything/blob/main/app.py regarding usage
model = MeshAnything(args)`,
];
export const multimolecule = (model) => {
const widgetExample = model.widgetData?.[0];
const exampleText = widgetExample?.text;
const maskToken = model.mask_token ?? "<mask>";
const sequence = exampleText?.replace(maskToken, "A");
const snippets = [`pip install multimolecule`];
if (sequence) {
snippets.push(`from multimolecule import AutoModel, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("${model.id}")
model = AutoModel.from_pretrained("${model.id}")
inputs = tokenizer("${sequence}", return_tensors="pt")
outputs = model(**inputs)
embeddings = outputs.last_hidden_state`);
}
else {
snippets.push(`from multimolecule import AutoModel, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("${model.id}")
model = AutoModel.from_pretrained("${model.id}")`);
}
if (model.tags.includes("rna-secondary-structure") && exampleText) {
snippets.push(`import multimolecule
from transformers import pipeline
predictor = pipeline("rna-secondary-structure", model="${model.id}")
output = predictor("${exampleText}")
print(output["secondary_structure"])`);
}
else if (model.pipeline_tag === "fill-mask" && exampleText) {
snippets.push(`import multimolecule
from transformers import pipeline
predictor = pipeline("fill-mask", model="${model.id}")
output = predictor("${exampleText}")`);
}
return snippets;
};
export const open_clip = (model) => [
`import open_clip
model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:${model.id}')
tokenizer = open_clip.get_tokenizer('hf-hub:${model.id}')`,
];
export const openasr = (model) => {
// OpenASR's local model registry keys packs by their short id (the final path segment
// of the Hub repo id, e.g. "xasr-zh-en" for "OpenASR/xasr-zh-en"), not the full
// "org/repo" reference, so the CLI commands below use that short id.
const modelId = model.id.split("/").pop() ?? model.id;
return [
`# Install the openasr CLI: https://github.com/QuintinShaw/openasr/releases
openasr pull ${modelId}
openasr transcribe audio.wav --model ${modelId}`,
];
};
export const paddlenlp = (model) => {
if (model.config?.architectures?.[0]) {
const architecture = model.config.architectures[0];
return [
[
`from paddlenlp.transformers import AutoTokenizer, ${architecture}`,
"",
`tokenizer = AutoTokenizer.from_pretrained("${model.id}", from_hf_hub=True)`,
`model = ${architecture}.from_pretrained("${model.id}", from_hf_hub=True)`,
].join("\n"),
];
}
else {
return [
[
`# ⚠️ Type of model unknown`,
`from paddlenlp.transformers import AutoTokenizer, AutoModel`,
"",
`tokenizer = AutoTokenizer.from_pretrained("${model.id}", from_hf_hub=True)`,
`model = AutoModel.from_pretrained("${model.id}", from_hf_hub=True)`,
].join("\n"),
];
}
};
export const paddleocr = (model) => {
const mapping = {
textline_detection: { className: "TextDetection" },
textline_recognition: { className: "TextRecognition" },
seal_text_detection: { className: "SealTextDetection" },
doc_img_unwarping: { className: "TextImageUnwarping" },
doc_img_orientation_classification: { className: "DocImgOrientationClassification" },
textline_orientation_classification: { className: "TextLineOrientationClassification" },
chart_parsing: { className: "ChartParsing" },
formula_recognition: { className: "FormulaRecognition" },
layout_detection: { className: "LayoutDetection" },
table_cells_detection: { className: "TableCellsDetection" },
wired_table_classification: { className: "TableClassification" },
table_structure_recognition: { className: "TableStructureRecognition" },
};
if (model.tags.includes("doc_vlm")) {
return [
`# 1. See https://www.paddlepaddle.org.cn/en/install to install paddlepaddle
# 2. pip install paddleocr
from paddleocr import DocVLM
model = DocVLM(model_name="${nameWithoutNamespace(model.id)}")
output = model.predict(
input={"image": "path/to/image.png", "query": "Parsing this image and output the content in Markdown format."},
batch_size=1
)
for res in output:
res.print()
res.save_to_json(save_path="./output/res.json")`,
];
}
if (model.tags.includes("document-parse")) {
const rawVersion = model.id.replace("PaddlePaddle/PaddleOCR-VL-", "v");
const version = rawVersion === "PaddlePaddle/PaddleOCR-VL" ? "v1" : rawVersion;
return [
`# See https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html to installation
from paddleocr import PaddleOCRVL
pipeline = PaddleOCRVL(pipeline_version="${version}")
output = pipeline.predict("path/to/document_image.png")
for res in output:
res.print()
res.save_to_json(save_path="output")
res.save_to_markdown(save_path="output")`,
];
}
for (const tag of model.tags) {
if (tag in mapping) {
const { className } = mapping[tag];
return [
`# 1. See https://www.paddlepaddle.org.cn/en/install to install paddlepaddle
# 2. pip install paddleocr
from paddleocr import ${className}
model = ${className}(model_name="${nameWithoutNamespace(model.id)}")
output = model.predict(input="path/to/image.png", batch_size=1)
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")`,
];
}
}
return [
`# Please refer to the document for information on how to use the model.
# https://paddlepaddle.github.io/PaddleOCR/latest/en/version3.x/module_usage/module_overview.html`,
];
};
export const perception_encoder = (model) => {
const clip_model = `# Use PE-Core models as CLIP models
import core.vision_encoder.pe as pe
model = pe.CLIP.from_config("${model.id}", pretrained=True)`;
const vision_encoder = `# Use any PE model as a vision encoder
import core.vision_encoder.pe as pe
model = pe.VisionTransformer.from_config("${model.id}", pretrained=True)`;
if (model.id.includes("Core")) {
return [clip_model, vision_encoder];
}
else {
return [vision_encoder];
}
};
export const phantom_wan = (model) => [
`from huggingface_hub import snapshot_download
from phantom_wan import WANI2V, configs
checkpoint_dir = snapshot_download("${model.id}")
wan_i2v = WanI2V(
config=configs.WAN_CONFIGS['i2v-14B'],
checkpoint_dir=checkpoint_dir,
)
video = wan_i2v.generate(text_prompt, image_prompt)`,
];
export const pocket_tts = (model) => [
`from pocket_tts import TTSModel
import scipy.io.wavfile
tts_model = TTSModel.load_model("${model.id}")
voice_state = tts_model.get_state_for_audio_prompt(
"hf://kyutai/tts-voices/alba-mackenna/casual.wav"
)
audio = tts_model.generate_audio(voice_state, "Hello world, this is a test.")
# Audio is a 1D torch tensor containing PCM data.
scipy.io.wavfile.write("output.wav", tts_model.sample_rate, audio.numpy())`,
];
export const pyannote_audio_pipeline = (model) => [
`from pyannote.audio import Pipeline
pipeline = Pipeline.from_pretrained("${model.id}")
# inference on the whole file
pipeline("file.wav")
# inference on an excerpt
from pyannote.core import Segment
excerpt = Segment(start=2.0, end=5.0)
from pyannote.audio import Audio
waveform, sample_rate = Audio().crop("file.wav", excerpt)
pipeline({"waveform": waveform, "sample_rate": sample_rate})`,
];
const pyannote_audio_model = (model) => [
`from pyannote.audio import Model, Inference
model = Model.from_pretrained("${model.id}")
inference = Inference(model)
# inference on the whole file
inference("file.wav")
# inference on an excerpt
from pyannote.core import Segment
excerpt = Segment(start=2.0, end=5.0)
inference.crop("file.wav", excerpt)`,
];
export const pyannote_audio = (model) => {
if (model.tags.includes("pyannote-audio-pipeline")) {
return pyannote_audio_pipeline(model);
}
return pyannote_audio_model(model);
};
export const relik = (model) => [
`from relik import Relik
relik = Relik.from_pretrained("${model.id}")`,
];
export const renderformer = (model) => [
`# Install from https://github.com/microsoft/renderformer
from renderformer import RenderFormerRenderingPipeline
pipeline = RenderFormerRenderingPipeline.from_pretrained("${model.id}")`,
];
const tensorflowttsTextToMel = (model) => [
`from tensorflow_tts.inference import AutoProcessor, TFAutoModel
processor = AutoProcessor.from_pretrained("${model.id}")
model = TFAutoModel.from_pretrained("${model.id}")
`,
];
const tensorflowttsMelToWav = (model) => [
`from tensorflow_tts.inference import TFAutoModel
model = TFAutoModel.from_pretrained("${model.id}")
audios = model.inference(mels)
`,
];
const tensorflowttsUnknown = (model) => [
`from tensorflow_tts.inference import TFAutoModel
model = TFAutoModel.from_pretrained("${model.id}")
`,
];
export const tensorflowtts = (model) => {
if (model.tags.includes("text-to-mel")) {
return tensorflowttsTextToMel(model);
}
else if (model.tags.includes("mel-to-wav")) {
return tensorflowttsMelToWav(model);
}
return tensorflowttsUnknown(model);
};
export const timm = (model) =>