Esteves Enzo
add NSFW filter
8b95140
raw
history blame
756 Bytes
import { pipeline, env } from "@xenova/transformers";
// Use the Singleton pattern to enable lazy construction of the pipeline.
// NOTE: We wrap the class in a function to prevent code duplication (see below).
process.env.HF_ACCESS_TOKEN = process.env.NEXT_PUBLIC_APP_HF_TOKEN
const P = () => class PipelineSingleton {
static task = 'image-classification';
static model = 'enzostvs/nsfw-detector-transformersjs';
static instance = null;
static async getInstance(progress_callback: any = null) {
if (this.instance === null) {
this.instance = pipeline(this.task, this.model, { progress_callback }) as any;
}
return this.instance;
}
}
const PipelineSingleton = P();
export default PipelineSingleton;