Update demo site imports
This commit is contained in:
parent
0172cf85c1
commit
55dac3e96c
|
@ -2,7 +2,9 @@
|
|||
// Scripts.js - handles link between DOM and worker
|
||||
|
||||
// Initialise worker
|
||||
const worker = new Worker('./assets/js/worker.js');
|
||||
const worker = new Worker('./assets/js/worker.js', {
|
||||
type: 'module',
|
||||
});
|
||||
|
||||
// Define elements
|
||||
const TASK_SELECTOR = document.getElementById('task');
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Worker.js file for doing all transformer-based computations
|
||||
// Needed to ensure the UI thread is not blocked when running
|
||||
///////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Get dist directory relative to location of worker script.
|
||||
const DIST_DIR = location.pathname.split('/').slice(0, -1 - 2).join('/') + '/dist/';
|
||||
|
||||
// Import transformers.js library
|
||||
importScripts(DIST_DIR + 'transformers.min.js');
|
||||
import { pipeline, env } from '/dist/transformers.js';
|
||||
|
||||
// Set paths to wasm files. In this case, we use the .wasm files present in `DIST_DIR`.
|
||||
env.backends.onnx.wasm.wasmPaths = DIST_DIR;
|
||||
// Detect whether running locally or remotely (e.g., GitHub pages)
|
||||
const RUNNING_REMOTE = location.hostname !== '127.0.0.1' && location.hostname !== 'localhost';
|
||||
|
||||
// If we are running locally, we should use the local model files (speeds up development)
|
||||
// Otherwise, we should use the remote files
|
||||
env.remoteModels = location.hostname !== '127.0.0.1' && location.hostname !== 'localhost';
|
||||
// To speed up development when running locally, we should:
|
||||
// 1. use the local model files (instead of remote files)
|
||||
// 2. load the wasm files from the local dist folder (instead of wasm files from CDN)
|
||||
env.remoteModels = RUNNING_REMOTE;
|
||||
|
||||
if (RUNNING_REMOTE) {
|
||||
env.backends.onnx.wasm.wasmPaths = DIST_DIR;
|
||||
}
|
||||
|
||||
// Define task function mapping
|
||||
const TASK_FUNCTION_MAPPING = {
|
||||
|
|
Loading…
Reference in New Issue