Spaces:
Running
Running
Upload script.js
Browse files- ui/script.js +30 -0
ui/script.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
async function analyze() {
|
| 2 |
+
const text = document.getElementById('textInput').value;
|
| 3 |
+
const output = document.getElementById('output');
|
| 4 |
+
const label = document.getElementById('label');
|
| 5 |
+
const confidence = document.getElementById('confidence');
|
| 6 |
+
const roast = document.getElementById('roast');
|
| 7 |
+
|
| 8 |
+
output.style.display = 'none';
|
| 9 |
+
label.textContent = '';
|
| 10 |
+
confidence.textContent = '';
|
| 11 |
+
roast.textContent = '';
|
| 12 |
+
|
| 13 |
+
try {
|
| 14 |
+
const response = await fetch(window.location.origin + `/predict`, {
|
| 15 |
+
method: 'POST',
|
| 16 |
+
headers: { 'Content-Type': 'application/json' },
|
| 17 |
+
body: JSON.stringify({ text })
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
const data = await response.json();
|
| 21 |
+
label.textContent = data.label;
|
| 22 |
+
confidence.textContent = (data.confidence * 100).toFixed(2);
|
| 23 |
+
roast.textContent = data.roast;
|
| 24 |
+
output.style.display = 'block';
|
| 25 |
+
} catch (err) {
|
| 26 |
+
console.error(err);
|
| 27 |
+
roast.textContent = "Something went wrong. EmoNet had a breakdown.";
|
| 28 |
+
output.style.display = 'block';
|
| 29 |
+
}
|
| 30 |
+
}
|