Check_2 / templates /index.html
sid22669's picture
Add application file
912ab32
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Classification</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 50px;
}
.container {
max-width: 500px;
margin: 0 auto;
text-align: center;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
font-size: 16px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.result {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>Text Classification</h1>
<input type="text" id="textInput" placeholder="Enter your text here">
<button onclick="classifyText()">Classify</button>
<div id="result" class="result"></div>
</div>
<script>
async function classifyText() {
const text = document.getElementById('textInput').value;
if (!text.trim()) {
document.getElementById('result').textContent = "Please enter some text!";
return;
}
try {
const response = await fetch("/predict", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ text: text })
});
if (response.ok) {
const data = await response.json();
document.getElementById('result').textContent = `Prediction: ${data.prediction}`;
} else {
document.getElementById('result').textContent = "Error: Unable to fetch prediction.";
}
} catch (error) {
console.error("Error:", error);
document.getElementById('result').textContent = "Error: Unable to fetch prediction.";
}
}
</script>
</body>
</html>