Rehyor commited on
Commit
360c4aa
·
verified ·
1 Parent(s): dcab08d

Initialize the AI Model:

Browse files

Inside your new <script type="module"> tag, right at the top, import the pipeline function and set up a class to manage the AI model. This ensures the model is loaded only once.

import { pipeline, cos_sim } from '[https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.1](https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.1)';

// Singleton class to manage the AI pipeline
class FeatureExtractionPipeline {
static task = 'feature-extraction';
static model = 'Xenova/all-MiniLM-L6-v2';
static instance = null;

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

Create the AI Analysis Function:

Create a new async function runAiAnalysis(jobDescription, cvContent) that uses the model.

This function will get the AI pipeline, use it to convert both texts into numerical embeddings, and then use cos_sim to calculate their similarity.

async function runAiAnalysis(jobDescription, cvContent) {
const extractor = await FeatureExtractionPipeline.getInstance();
const output = await extractor([jobDescription, cvContent], { pooling: 'mean', normalize: true });
const similarity = cos_sim(output[0].data, output[1].data);
// Convert similarity (0-1) to a percentage score (60-99) for better display
return Math.max(60, Math.min(99, Math.round(similarity * 40 + 60)));
}

Files changed (0) hide show