Jadson commited on
Commit
f8c1138
·
verified ·
1 Parent(s): 1073a7b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +63 -46
index.html CHANGED
@@ -20,65 +20,82 @@
20
  </section>
21
 
22
  <script type="module">
23
- import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.10.1';
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>
 
20
  </section>
21
 
22
  <script type="module">
23
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.10.1';
24
+
 
 
 
 
25
  const textInput = document.getElementById('text-input');
26
  const analyzeTextButton = document.getElementById('analyze-text');
27
  const textOutput = document.getElementById('text-output');
28
+
29
+ // Verifique se os elementos existem
30
  if (!textInput || !analyzeTextButton || !textOutput) {
31
+ console.error('Erro: Elementos não encontrados no DOM.');
32
+ }
33
+
34
+ // Variável para armazenar o modelo
35
+ let nerModel;
36
+
37
+ // Carregar o modelo NER com quantização q4
38
+ async function loadModel() {
39
  try {
40
  textOutput.textContent = 'Carregando modelo de NER...';
41
+ nerModel = await pipeline('token-classification', 'Xenova/distilbert-base-multilingual-cased-ner-hrl', {
42
+ dtype: 'quantized'
43
  });
44
  textOutput.textContent = 'Modelo de NER pronto!';
45
  } catch (error) {
46
  console.error('Erro ao carregar o modelo:', error);
47
  textOutput.textContent = 'Erro ao carregar o modelo. Tente novamente mais tarde.';
 
48
  }
49
+ }
50
+
51
+ // Carregar o modelo ao iniciar
52
+ await loadModel();
53
+
54
+ // Evento de clique para análise
55
+ analyzeTextButton.addEventListener('click', async () => {
56
+ const inputText = textInput.value.trim();
57
+
58
+ if (!inputText) {
59
+ textOutput.textContent = 'Por favor, insira um texto para análise.';
60
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
+
63
+ textOutput.textContent = 'Analisando...';
64
+
65
+ try {
66
+ console.log("inputText",inputText)
67
+ const nerOutput = await nerModel(inputText,{
68
+ ignore_labels: [] // Return all labels
69
+ });
70
+ console.log(nerOutput)
71
+ renderEntities(nerOutput);
72
+ } catch (error) {
73
+ console.error('Erro durante a análise:', error);
74
+ textOutput.textContent = 'Erro durante a análise. Verifique o texto inserido.';
75
+ }
76
+ });
77
+
78
+ // Função para renderizar as entidades
79
+ function renderEntities(entities) {
80
+ textOutput.innerHTML = ''; // Limpar saída anterior
81
+
82
+ if (entities.length === 0) {
83
+ textOutput.textContent = 'Nenhuma entidade encontrada.';
84
+ return;
85
+ }
86
+
87
+ entities.forEach(entity => {
88
+ const { word, entity_group, score } = entity;
89
+
90
+ const entityElement = document.createElement('div');
91
+ entityElement.className = 'entity';
92
+ entityElement.innerHTML = `
93
+ <strong>Palavra:</strong> ${word} <br>
94
+ <strong>Entidade:</strong> ${entity_group} <br>
95
+ <strong>Confiança:</strong> ${(score * 100).toFixed(2)}%
96
+ `;
97
+ textOutput.appendChild(entityElement);
98
+ });
99
  }
100
  </script>
101
  </body>