Delete static/script.js
Browse files- static/script.js +0 -87
static/script.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
| 1 |
-
document.addEventListener('DOMContentLoaded', function() {
|
| 2 |
-
const imageUpload = document.getElementById('image-upload');
|
| 3 |
-
const previewContainer = document.getElementById('preview-container');
|
| 4 |
-
const imagePreview = document.getElementById('image-preview');
|
| 5 |
-
const uploadPlaceholder = document.getElementById('upload-placeholder');
|
| 6 |
-
const submitButton = document.getElementById('submit-button');
|
| 7 |
-
const uploadForm = document.getElementById('upload-form');
|
| 8 |
-
const errorMessage = document.getElementById('error-message');
|
| 9 |
-
const resultContainer = document.getElementById('result-container');
|
| 10 |
-
const resultMessage = document.getElementById('result-message');
|
| 11 |
-
const membershipStatus = document.getElementById('membership-status');
|
| 12 |
-
const probabilityFill = document.getElementById('probability-fill');
|
| 13 |
-
const probabilityText = document.getElementById('probability-text');
|
| 14 |
-
const loading = document.getElementById('loading');
|
| 15 |
-
|
| 16 |
-
let selectedFile = null;
|
| 17 |
-
|
| 18 |
-
// Handle image selection
|
| 19 |
-
imageUpload.addEventListener('change', function(e) {
|
| 20 |
-
selectedFile = e.target.files[0];
|
| 21 |
-
|
| 22 |
-
if (selectedFile) {
|
| 23 |
-
const reader = new FileReader();
|
| 24 |
-
|
| 25 |
-
reader.onload = function(e) {
|
| 26 |
-
imagePreview.src = e.target.result;
|
| 27 |
-
previewContainer.classList.remove('hidden');
|
| 28 |
-
uploadPlaceholder.classList.add('hidden');
|
| 29 |
-
submitButton.disabled = false;
|
| 30 |
-
errorMessage.classList.add('hidden');
|
| 31 |
-
resultContainer.classList.add('hidden');
|
| 32 |
-
};
|
| 33 |
-
|
| 34 |
-
reader.readAsDataURL(selectedFile);
|
| 35 |
-
}
|
| 36 |
-
});
|
| 37 |
-
|
| 38 |
-
// Handle form submission
|
| 39 |
-
uploadForm.addEventListener('submit', function(e) {
|
| 40 |
-
e.preventDefault();
|
| 41 |
-
|
| 42 |
-
if (!selectedFile) {
|
| 43 |
-
errorMessage.textContent = 'Please select an image first';
|
| 44 |
-
errorMessage.classList.remove('hidden');
|
| 45 |
-
return;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
// Show loading indicator
|
| 49 |
-
loading.classList.remove('hidden');
|
| 50 |
-
submitButton.disabled = true;
|
| 51 |
-
errorMessage.classList.add('hidden');
|
| 52 |
-
resultContainer.classList.add('hidden');
|
| 53 |
-
|
| 54 |
-
const formData = new FormData();
|
| 55 |
-
formData.append('image', selectedFile);
|
| 56 |
-
|
| 57 |
-
fetch('/api/check-membership', {
|
| 58 |
-
method: 'POST',
|
| 59 |
-
body: formData
|
| 60 |
-
})
|
| 61 |
-
.then(response => {
|
| 62 |
-
if (!response.ok) {
|
| 63 |
-
throw new Error(`Server responded with ${response.status}`);
|
| 64 |
-
}
|
| 65 |
-
return response.json();
|
| 66 |
-
})
|
| 67 |
-
.then(data => {
|
| 68 |
-
// Display results
|
| 69 |
-
resultMessage.textContent = data.message;
|
| 70 |
-
membershipStatus.innerHTML = `This image is <strong>${data.is_in_training_data}</strong> in the model's training data.`;
|
| 71 |
-
|
| 72 |
-
const probability = data.probability * 100;
|
| 73 |
-
probabilityFill.style.width = `${probability}%`;
|
| 74 |
-
probabilityText.textContent = `${probability.toFixed(2)}%`;
|
| 75 |
-
|
| 76 |
-
resultContainer.classList.remove('hidden');
|
| 77 |
-
})
|
| 78 |
-
.catch(error => {
|
| 79 |
-
errorMessage.textContent = `Error: ${error.message}`;
|
| 80 |
-
errorMessage.classList.remove('hidden');
|
| 81 |
-
})
|
| 82 |
-
.finally(() => {
|
| 83 |
-
loading.classList.add('hidden');
|
| 84 |
-
submitButton.disabled = false;
|
| 85 |
-
});
|
| 86 |
-
});
|
| 87 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|