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

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- // Carregar modelo NER com quantização q4
34
- let nerModel;
35
- try {
36
- textOutput.textContent = 'Carregando modelo de NER...';
37
- nerModel = await pipeline('ner', 'Xenova/distilbert-base-multilingual-cased-ner-hrl', {
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
- const nerOutput = await nerModel(inputText);
56
- renderEntities(nerOutput);
 
 
 
57
  } catch (error) {
58
- console.error('Erro durante a análise:', error);
59
- textOutput.textContent = 'Erro durante a análise. Verifique o texto inserido.';
 
60
  }
61
- });
62
-
63
- function renderEntities(entities) {
64
- textOutput.innerHTML = '';
65
- entities.forEach(entity => {
66
- const { word, entity_group, score } = entity;
67
-
68
- const entityElement = document.createElement('div');
69
- entityElement.className = 'entity';
70
- entityElement.innerHTML = `
71
- <strong>Palavra:</strong> ${word} <br>
72
- <strong>Entidade:</strong> ${entity_group} <br>
73
- <strong>Confiança:</strong> ${(score * 100).toFixed(2)}%
74
- `;
75
- textOutput.appendChild(entityElement);
 
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>