|
import { AllTasks, pipeline, PipelineType } from "@huggingface/transformers"; |
|
|
|
|
|
|
|
class PipelineSingletonClass { |
|
static task = 'text-classification'; |
|
static model = 'SamLowe/roberta-base-go_emotions-onnx'; |
|
static instance: Promise<AllTasks[PipelineType]> | null = null; |
|
|
|
static async getInstance(progress_callback = undefined) { |
|
if (this.instance === null) { |
|
this.instance = pipeline(this.task as PipelineType, this.model, { progress_callback }); |
|
} |
|
return this.instance; |
|
} |
|
} |
|
const P = () => PipelineSingletonClass |
|
|
|
let PipelineSingleton: typeof PipelineSingletonClass; |
|
if (process.env.NODE_ENV !== 'production') { |
|
|
|
|
|
|
|
|
|
if (!global.PipelineSingleton) { |
|
|
|
global.PipelineSingleton = P(); |
|
} |
|
|
|
PipelineSingleton = global.PipelineSingleton; |
|
} else { |
|
PipelineSingleton = P(); |
|
} |
|
export default PipelineSingleton; |
|
|