Spaces:
Running
Running
Update ui/script.js
Browse files- ui/script.js +36 -30
ui/script.js
CHANGED
|
@@ -1,30 +1,36 @@
|
|
| 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 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
roast.textContent =
|
| 28 |
-
|
| 29 |
-
|
| 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 |
+
// 👇 YOUR NGROK URL GOES HERE
|
| 14 |
+
const API_URL = "https://c179cffb5e08.ngrok-free.app";
|
| 15 |
+
|
| 16 |
+
try {
|
| 17 |
+
const response = await fetch(`${API_URL}/predict`, {
|
| 18 |
+
method: 'POST',
|
| 19 |
+
headers: { 'Content-Type': 'application/json' },
|
| 20 |
+
body: JSON.stringify({ text })
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
const data = await response.json();
|
| 24 |
+
|
| 25 |
+
label.textContent = data.label;
|
| 26 |
+
confidence.textContent = (data.confidence * 100).toFixed(2);
|
| 27 |
+
roast.textContent = data.roast;
|
| 28 |
+
|
| 29 |
+
output.style.display = 'block';
|
| 30 |
+
|
| 31 |
+
} catch (err) {
|
| 32 |
+
console.error(err);
|
| 33 |
+
roast.textContent = "Something went wrong. EmoNet had a breakdown.";
|
| 34 |
+
output.style.display = 'block';
|
| 35 |
+
}
|
| 36 |
+
}
|