Skip to content

Instantly share code, notes, and snippets.

@JohnRSim
Created July 11, 2024 10:54
Show Gist options
  • Save JohnRSim/2bda44ab6596c25d513445eda776bf93 to your computer and use it in GitHub Desktop.
Save JohnRSim/2bda44ab6596c25d513445eda776bf93 to your computer and use it in GitHub Desktop.
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.0';
env.allowLocalModels = false;
const status = document.getElementById('status');
status.textContent = 'Loading model...';
const translator = await pipeline('translation', 'Xenova/nllb-200-distilled-600M');
status.textContent = 'Ready';
let output = await translator('Hello World', {
tgt_lang: 'eng_Latn',
src_lang: 'fra_Latn',
// Allows for partial output
callback_function: x => {
console.log('partial output: ', translator.tokenizer.decode(x[0].output_token_ids, { skip_special_tokens: true }))
}
});
console.log('output: ', output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment