Mnddoke / static /index1.html
Ashrafb's picture
Rename static/index.html to static/index1.html
25577e8 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Captioning</title>
</head>
<body>
<h1>Image Captioning</h1>
<form id="uploadForm" action="/predict/" method="post" enctype="multipart/form-data">
<label for="image">Upload Image:</label><br>
<input type="file" id="image" name="image" accept="image/*"><br>
<label for="context">Question:</label><br>
<input type="text" id="context" name="context"><br>
<button type="submit" id="submitBtn">Submit</button>
</form>
<div id="result" style="display: none;">
<h2>Result:</h2>
<p id="caption"></p>
</div>
<div id="loading" style="display: none;">
<p>Loading...</p>
</div>
<script>
document.getElementById('uploadForm').addEventListener('submit', async function(event) {
event.preventDefault();
showLoadingIndicator();
let formData = new FormData(this);
try {
let response = await fetch('/get_caption', {
method: 'POST',
body: formData
});
if (response.ok) {
let result = await response.json();
document.getElementById('caption').innerText = result.caption;
document.getElementById('result').style.display = 'block';
hideLoadingIndicator();
} else {
alert('An error occurred while processing the request.');
hideLoadingIndicator();
}
} catch (error) {
console.error('An error occurred:', error);
alert('An error occurred while processing the request.');
hideLoadingIndicator();
}
});
function showLoadingIndicator() {
document.getElementById('loading').style.display = 'block';
document.getElementById('submitBtn').disabled = true;
}
function hideLoadingIndicator() {
document.getElementById('loading').style.display = 'none';
document.getElementById('submitBtn').disabled = false;
}
</script>
</body>
</html>