import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.10.1'; // Since we will download the model from the Hugging Face Hub, we can skip the local model check env.allowLocalModels = false; // Configuração do modelo de NER const nerStatus = document.getElementById('status'); const textInput = document.getElementById('text-input'); const analyzeTextButton = document.getElementById('analyze-text'); const textOutput = document.getElementById('text-output'); nerStatus.textContent = 'Carregando modelo de NER...'; const nerModel = await pipeline('ner', 'Xenova/distilbert-base-multilingual-cased-ner-hrl'); nerStatus.textContent = 'Modelo de NER pronto!'; // Função para análise de texto analyzeTextButton.addEventListener('click', async () => { const inputText = textInput.value.trim(); if (!inputText) { textOutput.textContent = 'Por favor, insira um texto para análise.'; return; } textOutput.textContent = 'Analisando...'; const nerOutput = await nerModel(inputText); // Renderizando as entidades detectadas renderEntities(nerOutput); }); // Função para exibir os resultados das entidades detectadas function renderEntities(entities) { textOutput.innerHTML = ''; entities.forEach(entity => { const { word, entity_group, score } = entity; const entityElement = document.createElement('div'); entityElement.className = 'entity'; entityElement.innerHTML = ` Palavra: ${word}
Entidade: ${entity_group}
Confiança: ${(score * 100).toFixed(2)}% `; textOutput.appendChild(entityElement); }); }