* Loads the pretrained model and metadata, and registers the translation * function with the UI.
()
| 186 | * function with the UI. |
| 187 | */ |
| 188 | async 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 | |
| 214 | setupTranslator(); |