Created
July 11, 2024 10:54
-
-
Save JohnRSim/2bda44ab6596c25d513445eda776bf93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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