File size: 992 Bytes
2f35054 e7ba29d 2f35054 e7ba29d 2f35054 e7ba29d 2f35054 22f8eb7 e7ba29d 2f35054 e7ba29d 2f35054 e7ba29d 2f35054 e7ba29d 2f35054 e7ba29d 2f35054 e7ba29d 2f35054 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
const workers: Record<string, Worker | null> = {}
export const getWorker = (pipeline: string) => {
if (!workers[pipeline]) {
let workerUrl: string
switch (pipeline) {
case 'text-classification':
workerUrl = `${process.env.PUBLIC_URL}/workers/text-classification.js`
break
case 'zero-shot-classification':
workerUrl = `${process.env.PUBLIC_URL}/workers/zero-shot-classification.js`
break
case 'text-generation':
workerUrl = `${process.env.PUBLIC_URL}/workers/text-generation.js`
break
case 'feature-extraction':
workerUrl = `${process.env.PUBLIC_URL}/workers/feature-extraction.js`
break
default:
return null
}
workers[pipeline] = new Worker(workerUrl, { type: 'module' })
}
return workers[pipeline]
}
export const terminateWorker = (pipeline: string) => {
const worker = workers[pipeline]
if (worker) {
worker.terminate()
delete workers[pipeline]
}
}
|