import { pipeline } from "@huggingface/transformers"; function loadingBar(total: number, current: number, barLength = 20) { const filled = Math.round((current / total) * barLength); const empty = barLength - filled; const bar = `[${"#".repeat(filled)}${" ".repeat(empty)}] ${Math.round( (current / total) * 100 )}%`; process.stdout.write("\r" + bar); } process.stdout.write("\n"); // Move async function run() { // Load a pre-trained model and tokenizer const pipe = await pipeline( "text-generation", "HuggingFaceTB/SmolLM2-135M-Instruct", // "HuggingFaceTB/SmolLM2-360M-Instruct", // "HuggingFaceTB/SmolLM2-1.7B-Instruct", { cache_dir: "./cache", progress_callback: (progress: any) => { loadingBar(progress.total, progress.loaded); }, } ); // Perform sentiment analysis const result = await pipe( [ { role: "user", content: `Recomend a song for me based on these songs: 'Dheere Dheere Aap Mere', 'Zara Zara - Deep House Mix', 'Hey Minnale (From "Amaran") (Tamil)', 'Apna Bana Le (From "Bhediya")`, }, ], { max_new_tokens: 100, } ); console.log(result); } run().catch(console.error);