-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (51 loc) · 1.69 KB
/
script.js
File metadata and controls
63 lines (51 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// JavaScript code
//script.js
async function query(data) {
const response = await fetch(
'https://api-inference.huggingface.co/models/d4data/biomedical-ner-all',
{
headers: {
Authorization: 'Bearer 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',
},
method: 'POST',
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
}
const textInput = document.getElementById('textInput');
const fetchButton = document.getElementById('fetchButton');
const output = document.getElementById('output');
fetchButton.addEventListener('click', async () => {
const inputText = textInput.value;
if (inputText.trim() === '') {
alert('Please enter some text.');
} else {
const response = await query({ inputs: inputText });
displayEntitiesInTables(response);
}
});
function displayEntitiesInTables(entities) {
const entityGroups = {};
for (const entity of entities) {
const entityGroup = entity.entity_group;
if (!entityGroups[entityGroup]) {
entityGroups[entityGroup] = [];
}
entityGroups[entityGroup].push(entity);
}
let tableHTML = '';
for (const group in entityGroups) {
if (entityGroups.hasOwnProperty(group)) {
tableHTML += `<h2>${group}</h2><table>`;
tableHTML += '<tr><th>Word</th><th>Score</th></tr>';
for (const entity of entityGroups[group]) {
tableHTML += `<tr><td>${entity.word}</td><td>${entity.score}</td></tr>`;
}
tableHTML += '</table>';
}
}
output.innerHTML = tableHTML;
output.classList.remove('hidden');
}