Update index.html
Browse files- index.html +48 -43
index.html
CHANGED
|
@@ -21,59 +21,64 @@
|
|
| 21 |
|
| 22 |
<script type="module">
|
| 23 |
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
| 24 |
-
|
| 25 |
// Configuração para desativar modelos locais
|
| 26 |
env.allowLocalModels = false;
|
| 27 |
-
|
| 28 |
// Reconhecimento de Entidades Nomeadas (NER)
|
| 29 |
const textInput = document.getElementById('text-input');
|
| 30 |
const analyzeTextButton = document.getElementById('analyze-text');
|
| 31 |
const textOutput = document.getElementById('text-output');
|
| 32 |
-
|
| 33 |
-
//
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
nerModel
|
| 38 |
-
dtype: 'q4'
|
| 39 |
-
});
|
| 40 |
-
textOutput.textContent = 'Modelo de NER pronto!';
|
| 41 |
-
} catch (error) {
|
| 42 |
-
console.error('Erro ao carregar o modelo:', error);
|
| 43 |
-
textOutput.textContent = 'Erro ao carregar o modelo. Tente novamente mais tarde.';
|
| 44 |
-
}
|
| 45 |
-
|
| 46 |
-
analyzeTextButton.addEventListener('click', async () => {
|
| 47 |
-
const inputText = textInput.value.trim();
|
| 48 |
-
if (!inputText) {
|
| 49 |
-
textOutput.textContent = 'Por favor, insira um texto para análise.';
|
| 50 |
-
return;
|
| 51 |
-
}
|
| 52 |
-
|
| 53 |
-
textOutput.textContent = 'Analisando...';
|
| 54 |
try {
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
| 57 |
} catch (error) {
|
| 58 |
-
console.error('Erro
|
| 59 |
-
textOutput.textContent = 'Erro
|
|
|
|
| 60 |
}
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
</script>
|
| 79 |
</body>
|
|
|
|
| 21 |
|
| 22 |
<script type="module">
|
| 23 |
import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
|
| 24 |
+
|
| 25 |
// Configuração para desativar modelos locais
|
| 26 |
env.allowLocalModels = false;
|
| 27 |
+
|
| 28 |
// Reconhecimento de Entidades Nomeadas (NER)
|
| 29 |
const textInput = document.getElementById('text-input');
|
| 30 |
const analyzeTextButton = document.getElementById('analyze-text');
|
| 31 |
const textOutput = document.getElementById('text-output');
|
| 32 |
+
|
| 33 |
+
// Verifique se os elementos HTML foram encontrados
|
| 34 |
+
if (!textInput || !analyzeTextButton || !textOutput) {
|
| 35 |
+
console.error('Elementos HTML necessários não foram encontrados.');
|
| 36 |
+
} else {
|
| 37 |
+
let nerModel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
try {
|
| 39 |
+
textOutput.textContent = 'Carregando modelo de NER...';
|
| 40 |
+
nerModel = await pipeline('ner', 'Xenova/distilbert-base-multilingual-cased-ner-hrl', {
|
| 41 |
+
dtype: 'q4',
|
| 42 |
+
});
|
| 43 |
+
textOutput.textContent = 'Modelo de NER pronto!';
|
| 44 |
} catch (error) {
|
| 45 |
+
console.error('Erro ao carregar o modelo:', error);
|
| 46 |
+
textOutput.textContent = 'Erro ao carregar o modelo. Tente novamente mais tarde.';
|
| 47 |
+
return; // Saia se o modelo não puder ser carregado
|
| 48 |
}
|
| 49 |
+
|
| 50 |
+
analyzeTextButton.addEventListener('click', async () => {
|
| 51 |
+
const inputText = textInput.value.trim();
|
| 52 |
+
if (!inputText) {
|
| 53 |
+
textOutput.textContent = 'Por favor, insira um texto para análise.';
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
textOutput.textContent = 'Analisando...';
|
| 58 |
+
try {
|
| 59 |
+
const nerOutput = await nerModel(inputText);
|
| 60 |
+
renderEntities(nerOutput);
|
| 61 |
+
} catch (error) {
|
| 62 |
+
console.error('Erro durante a análise:', error);
|
| 63 |
+
textOutput.textContent = 'Erro durante a análise. Verifique o texto inserido.';
|
| 64 |
+
}
|
| 65 |
});
|
| 66 |
+
|
| 67 |
+
function renderEntities(entities) {
|
| 68 |
+
textOutput.innerHTML = '';
|
| 69 |
+
entities.forEach(entity => {
|
| 70 |
+
const { word, entity_group, score } = entity;
|
| 71 |
+
|
| 72 |
+
const entityElement = document.createElement('div');
|
| 73 |
+
entityElement.className = 'entity';
|
| 74 |
+
entityElement.innerHTML = `
|
| 75 |
+
<strong>Palavra:</strong> ${word} <br>
|
| 76 |
+
<strong>Entidade:</strong> ${entity_group} <br>
|
| 77 |
+
<strong>Confiança:</strong> ${(score * 100).toFixed(2)}%
|
| 78 |
+
`;
|
| 79 |
+
textOutput.appendChild(entityElement);
|
| 80 |
+
});
|
| 81 |
+
}
|
| 82 |
}
|
| 83 |
</script>
|
| 84 |
</body>
|