MCPcopy Index your code
hub / github.com/tensorflow/tfjs-examples / setupTranslator

Function setupTranslator

translation/index.js:188–212  ·  view source on GitHub ↗

* Loads the pretrained model and metadata, and registers the translation * function with the UI.

()

Source from the content-addressed store, hash-verified

186 * function with the UI.
187 */
188async function setupTranslator() {
189 if (await loader.urlExists(HOSTED_URLS.model)) {
190 ui.status('Model available: ' + HOSTED_URLS.model);
191 const button = document.getElementById('load-pretrained-remote');
192 button.addEventListener('click', async () => {
193 const translator = await new Translator().init(HOSTED_URLS);
194 ui.setTranslationFunction(x => translator.translate(x));
195 ui.setEnglish('Go.', x => translator.translate(x));
196 });
197 button.style.display = 'inline-block';
198 }
199
200 if (await loader.urlExists(LOCAL_URLS.model)) {
201 ui.status('Model available: ' + LOCAL_URLS.model);
202 const button = document.getElementById('load-pretrained-local');
203 button.addEventListener('click', async () => {
204 const translator = await new Translator().init(LOCAL_URLS);
205 ui.setTranslationFunction(x => translator.translate(x));
206 ui.setEnglish('Go.', x => translator.translate(x));
207 });
208 button.style.display = 'inline-block';
209 }
210
211 ui.status('Standing by.');
212}
213
214setupTranslator();

Callers 1

index.jsFile · 0.85

Calls 2

translateMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected