<!-- templates/index.html --> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Clinical Text Predictor</title> | |
<style> | |
body { | |
font-family: 'Arial', sans-serif; | |
margin: 20px; | |
text-align: center; | |
} | |
h1 { | |
color: #333; | |
} | |
form { | |
margin-top: 20px; | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
} | |
label { | |
margin-bottom: 10px; | |
} | |
input { | |
padding: 8px; | |
margin-bottom: 10px; | |
width: 300px; | |
box-sizing: border-box; | |
} | |
button { | |
padding: 10px; | |
background-color: #4CAF50; | |
color: white; | |
border: none; | |
cursor: pointer; | |
font-size: 16px; | |
} | |
button:hover { | |
background-color: #45a049; | |
} | |
#predictionResult { | |
margin-top: 20px; | |
font-size: 18px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Clinical Text Predictor</h1> | |
<form id="predictionForm"> | |
<label for="inputText">Input Text:</label> | |
<input type="text" id="inputText" name="inputText" required> | |
<button type="button" onclick="predict()">Submit</button> | |
</form> | |
<p id="predictionResult"></p> | |
<script> | |
function predict() { | |
var inputText = document.getElementById('inputText').value; | |
// Make a POST request to the Flask API | |
fetch('/predict', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ | |
'input': inputText, | |
}), | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
document.getElementById('predictionResult').innerText = 'Prediction: ' + data.prediction; | |
}) | |
.catch(error => { | |
console.error('Error:', error); | |
document.getElementById('predictionResult').innerText = 'Error occurred. Please try again.'; | |
}); | |
} | |
</script> | |
</body> | |
</html> |