EmoNet / script.js
Dreamy0's picture
Rename ui/script.js to script.js
4c4b119 verified
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';
}
}