Spaces:
Running
Running
Update ui/script.js
Browse files- ui/script.js +11 -4
ui/script.js
CHANGED
|
@@ -5,21 +5,28 @@ async function analyze() {
|
|
| 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 |
const API_URL = "https://cf6827739654.ngrok-free.app";
|
| 15 |
|
| 16 |
try {
|
| 17 |
const response = await fetch(`${API_URL}/predict`, {
|
| 18 |
method: 'POST',
|
| 19 |
-
headers: {
|
|
|
|
|
|
|
| 20 |
body: JSON.stringify({ text })
|
| 21 |
});
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
const data = await response.json();
|
| 24 |
|
| 25 |
label.textContent = data.label;
|
|
@@ -29,8 +36,8 @@ async function analyze() {
|
|
| 29 |
output.style.display = 'block';
|
| 30 |
|
| 31 |
} catch (err) {
|
| 32 |
-
console.error(err);
|
| 33 |
-
roast.textContent = "Something went wrong
|
| 34 |
output.style.display = 'block';
|
| 35 |
}
|
| 36 |
}
|
|
|
|
| 5 |
const confidence = document.getElementById('confidence');
|
| 6 |
const roast = document.getElementById('roast');
|
| 7 |
|
| 8 |
+
// Reset UI state
|
| 9 |
output.style.display = 'none';
|
| 10 |
label.textContent = '';
|
| 11 |
confidence.textContent = '';
|
| 12 |
roast.textContent = '';
|
| 13 |
|
| 14 |
+
// ✅ Replace with your real ngrok URL (HTTPS)
|
| 15 |
const API_URL = "https://cf6827739654.ngrok-free.app";
|
| 16 |
|
| 17 |
try {
|
| 18 |
const response = await fetch(`${API_URL}/predict`, {
|
| 19 |
method: 'POST',
|
| 20 |
+
headers: {
|
| 21 |
+
'Content-Type': 'application/json'
|
| 22 |
+
},
|
| 23 |
body: JSON.stringify({ text })
|
| 24 |
});
|
| 25 |
|
| 26 |
+
if (!response.ok) {
|
| 27 |
+
throw new Error(`HTTP ${response.status}`);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
const data = await response.json();
|
| 31 |
|
| 32 |
label.textContent = data.label;
|
|
|
|
| 36 |
output.style.display = 'block';
|
| 37 |
|
| 38 |
} catch (err) {
|
| 39 |
+
console.error("Frontend error:", err);
|
| 40 |
+
roast.textContent = "Something went wrong talking to the server.";
|
| 41 |
output.style.display = 'block';
|
| 42 |
}
|
| 43 |
}
|