Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"webpack": "^5.79.0"
},
"dependencies": {
"@xenova/transformers": "^2.0.0"
"@huggingface/transformers": "^3.4.0"
}
}
14 changes: 2 additions & 12 deletions examples/extension/src/background.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
// background.js - Handles requests from the UI, runs the model, then sends back a response

import { pipeline, env } from '@xenova/transformers';

// Skip initial check for local models, since we are not loading any local models.
env.allowLocalModels = false;

// Due to a bug in onnxruntime-web, we must disable multithreading for now.
// See https://github.com/microsoft/onnxruntime/issues/14445 for more information.
env.backends.onnx.wasm.numThreads = 1;

import { pipeline } from '@huggingface/transformers';

class PipelineSingleton {
static task = 'text-classification';
static model = 'Xenova/distilbert-base-uncased-finetuned-sst-2-english';
static instance = null;

static async getInstance(progress_callback = null) {
if (this.instance === null) {
this.instance = pipeline(this.task, this.model, { progress_callback });
}
this.instance ??= pipeline(this.task, this.model, { progress_callback });

return this.instance;
}
Expand Down
5 changes: 4 additions & 1 deletion examples/extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const config = {
mode: 'development',
devtool: 'inline-source-map',
entry: {
background: './src/background.js',
background: {
import: './src/background.js',
chunkLoading: `import-scripts`,
},
popup: './src/popup.js',
content: './src/content.js',
},
Expand Down