Spaces:
Running
Running
File size: 1,217 Bytes
722315c 768494f 722315c 768494f 5737b10 722315c 768494f 722315c 768494f 722315c 768494f 722315c |
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 |
async function analyze() {
const text = document.getElementById('textInput').value;
const output = document.getElementById('output');
const label = document.getElementById('label');
const confidence = document.getElementById('confidence');
const roast = document.getElementById('roast');
// Reset UI state
output.style.display = 'none';
label.textContent = '';
confidence.textContent = '';
roast.textContent = '';
// ✅ Replace with your real ngrok URL (HTTPS)
const API_URL = "https://cf6827739654.ngrok-free.app";
try {
const response = await fetch(`${API_URL}/predict`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ text })
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
const data = await response.json();
label.textContent = data.label;
confidence.textContent = (data.confidence * 100).toFixed(2);
roast.textContent = data.roast;
output.style.display = 'block';
} catch (err) {
console.error("Frontend error:", err);
roast.textContent = "Something went wrong talking to the server.";
output.style.display = 'block';
}
}
|