Spaces:
Running
Running
File size: 1,378 Bytes
6384276 ef9a278 6384276 ef9a278 6384276 ef9a278 6384276 ef9a278 6384276 ef9a278 6384276 725eacb 6384276 ef9a278 |
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 |
document.getElementById('textForm').addEventListener('submit', async function(event) {
event.preventDefault();
const inputText = document.getElementById('inputText').value;
const loader = document.getElementById('loader');
const successMessage = document.getElementById('successMessage');
const errorMessage = document.getElementById('errorMessage');
if (!inputText.trim()) {
alert("Please enter some text!");
return;
}
loader.style.display = "block";
successMessage.style.display = "none";
errorMessage.style.display = "none";
try {
const response = await fetch('/classify-text', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text: inputText }),
});
const data = await response.json();
loader.style.display = "none";
if (response.ok) {
successMessage.style.display = "block";
successMessage.textContent = data.formatted_message; // Display the formatted message with line breaks
} else {
throw new Error(data.detail || 'An error occurred');
}
} catch (error) {
loader.style.display = "none";
errorMessage.style.display = "block";
errorMessage.textContent = error.message;
}
}); |