Spaces:
Running
Running
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; | |
} | |
}); |