CoolFace
Apppublic

willingram/experiments

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
index.js38 linesDownload Raw Back to root
1import { pipeline, env } from "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.10.1";2 3// Since we will download the model from the Hugging Face Hub, we can skip the local model check4env.allowLocalModels = false;5 6const myStatusButton = document.getElementById("myBtn");7async function identifyIdentityField(columnNames) {8  const classifier = await pipeline("text-classification", "Xenova/distilbert-base-uncased-finetuned-sst-2-english");9 10  const identityCandidates = ["id", "identifier", "identity", "customer_id", "user_id"];11 12  let identityField = null;13  let highestScore = 0;14  for (const column of columnNames) {15    const result = await classifier(column);16    console.log(`${column}: ${result[0].score}`)17 18    if (identityCandidates.some((candidate) => column.toLowerCase().includes(candidate))) {19      if (result[0].score > highestScore) {20        highestScore = result[0].score;21        identityField = column;22      }23    }24  }25 26  return [identityField,highestScor];27}28 29const columnNames = ["customer_name", "customers_id", "date_of_birth", "email"];30 31myStatusButton.addEventListener("click", (e) => {32  e.preventDefault();33  // console.log(JSON.parse(myTextInput.value));34  identifyIdentityField(JSON.parse(myTextInput.value)).then(([identityField,highestScore]) => {35    myOutput.innerText = `The most likely identity field is: ${identityField}, with score ${highestScore}.`;36  });37});38