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|
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Waste Classification AI</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles@3.3.0/tsparticles.bundle.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
body {
|
| 12 |
+
font-family: 'Inter', sans-serif;
|
| 13 |
+
background: linear-gradient(135deg, #f6f8fc 0%, #e9f0f7 100%);
|
| 14 |
+
}
|
| 15 |
+
.drop-zone {
|
| 16 |
+
border: 2px dashed #cbd5e0;
|
| 17 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 18 |
+
background: rgba(255, 255, 255, 0.8);
|
| 19 |
+
backdrop-filter: blur(8px);
|
| 20 |
+
}
|
| 21 |
+
.drop-zone:hover {
|
| 22 |
+
border-color: #4299e1;
|
| 23 |
+
background: rgba(255, 255, 255, 0.95);
|
| 24 |
+
transform: translateY(-2px);
|
| 25 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
| 26 |
+
}
|
| 27 |
+
.loading {
|
| 28 |
+
display: none;
|
| 29 |
+
}
|
| 30 |
+
.loading.active {
|
| 31 |
+
display: flex;
|
| 32 |
+
}
|
| 33 |
+
.result-card {
|
| 34 |
+
transition: all 0.3s ease;
|
| 35 |
+
transform: translateY(0);
|
| 36 |
+
}
|
| 37 |
+
.result-card.show {
|
| 38 |
+
transform: translateY(0);
|
| 39 |
+
opacity: 1;
|
| 40 |
+
}
|
| 41 |
+
.upload-icon {
|
| 42 |
+
transition: all 0.3s ease;
|
| 43 |
+
}
|
| 44 |
+
.drop-zone:hover .upload-icon {
|
| 45 |
+
transform: scale(1.1);
|
| 46 |
+
color: #4299e1;
|
| 47 |
+
}
|
| 48 |
+
.prediction-badge {
|
| 49 |
+
transition: all 0.3s ease;
|
| 50 |
+
}
|
| 51 |
+
.prediction-badge:hover {
|
| 52 |
+
transform: scale(1.05);
|
| 53 |
+
}
|
| 54 |
+
@keyframes float {
|
| 55 |
+
0% { transform: translateY(0px); }
|
| 56 |
+
50% { transform: translateY(-10px); }
|
| 57 |
+
100% { transform: translateY(0px); }
|
| 58 |
+
}
|
| 59 |
+
.floating {
|
| 60 |
+
animation: float 3s ease-in-out infinite;
|
| 61 |
+
}
|
| 62 |
+
.image-preview {
|
| 63 |
+
max-width: 100%;
|
| 64 |
+
max-height: 300px;
|
| 65 |
+
object-fit: contain;
|
| 66 |
+
border-radius: 0.5rem;
|
| 67 |
+
display: none;
|
| 68 |
+
}
|
| 69 |
+
.image-preview.show {
|
| 70 |
+
display: block;
|
| 71 |
+
}
|
| 72 |
+
.preview-container {
|
| 73 |
+
display: none;
|
| 74 |
+
margin-bottom: 1rem;
|
| 75 |
+
}
|
| 76 |
+
.preview-container.show {
|
| 77 |
+
display: block;
|
| 78 |
+
}
|
| 79 |
+
</style>
|
| 80 |
+
</head>
|
| 81 |
+
<body class="min-h-screen relative">
|
| 82 |
+
<!-- Particle Animation Background -->
|
| 83 |
+
<div id="tsparticles" style="position:fixed; inset:0; z-index:0;"></div>
|
| 84 |
+
|
| 85 |
+
<div class="container mx-auto px-4 py-12 2xl:max-w-screen-2xl">
|
| 86 |
+
<div class="mx-auto max-w-5xl">
|
| 87 |
+
<!-- Header Section -->
|
| 88 |
+
<div class="flex flex-col items-center justify-center mb-12 pt-8 pb-6">
|
| 89 |
+
<h1 class="text-5xl md:text-6xl font-extrabold tracking-tight text-gray-900 text-center leading-tight">
|
| 90 |
+
Waste Classification AI
|
| 91 |
+
</h1>
|
| 92 |
+
<div class="w-24 h-1 mt-4 mb-2 rounded-full bg-gradient-to-r from-blue-400 via-green-400 to-blue-400"></div>
|
| 93 |
+
<p class="text-xl text-gray-600 text-center mt-2">Upload an image to classify waste as dry or wet</p>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
+
<!-- Main Card -->
|
| 97 |
+
<div class="bg-white rounded-3xl shadow-2xl p-12 backdrop-blur-lg bg-opacity-90">
|
| 98 |
+
<!-- Image Preview -->
|
| 99 |
+
<div id="preview-container" class="preview-container">
|
| 100 |
+
<div class="relative">
|
| 101 |
+
<img id="image-preview" class="image-preview mx-auto" src="" alt="Preview">
|
| 102 |
+
<button id="remove-image" class="absolute top-2 right-2 bg-red-500 text-white rounded-full p-2 hover:bg-red-600 transition-colors">
|
| 103 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 104 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
| 105 |
+
</svg>
|
| 106 |
+
</button>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<!-- Upload Zone -->
|
| 111 |
+
<div id="drop-zone" class="drop-zone rounded-xl p-12 text-center cursor-pointer mb-8">
|
| 112 |
+
<div class="space-y-6">
|
| 113 |
+
<div class="upload-icon floating">
|
| 114 |
+
<svg class="mx-auto h-16 w-16 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48">
|
| 115 |
+
<path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
| 116 |
+
</svg>
|
| 117 |
+
</div>
|
| 118 |
+
<div class="text-gray-600">
|
| 119 |
+
<p class="text-xl font-medium mb-2">Drag and drop your image here</p>
|
| 120 |
+
<p class="text-sm text-gray-500 mb-4">or</p>
|
| 121 |
+
<button class="px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-all transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 mr-2" onclick="fileInput.click()">
|
| 122 |
+
Browse Files
|
| 123 |
+
</button>
|
| 124 |
+
<button id="camera-btn" class="px-6 py-3 bg-green-500 text-white rounded-lg hover:bg-green-600 transition-all transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50">
|
| 125 |
+
Use Camera
|
| 126 |
+
</button>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
<input type="file" id="file-input" class="hidden" accept="image/*">
|
| 130 |
+
</div>
|
| 131 |
+
|
| 132 |
+
<!-- Webcam Modal -->
|
| 133 |
+
<div id="camera-modal" class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-60 hidden">
|
| 134 |
+
<div class="bg-white rounded-2xl shadow-2xl p-8 flex flex-col items-center relative w-full max-w-md mx-auto">
|
| 135 |
+
<button id="close-camera" class="absolute top-4 right-4 text-gray-400 hover:text-red-500 text-2xl">×</button>
|
| 136 |
+
<video id="webcam" autoplay playsinline class="rounded-lg border border-gray-200 mb-4 w-full max-w-xs"></video>
|
| 137 |
+
<canvas id="webcam-canvas" class="hidden"></canvas>
|
| 138 |
+
<button id="capture-btn" class="px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-all mt-2">Capture</button>
|
| 139 |
+
</div>
|
| 140 |
+
</div>
|
| 141 |
+
|
| 142 |
+
<!-- Loading Animation -->
|
| 143 |
+
<div id="loading" class="loading items-center justify-center space-x-3 py-8">
|
| 144 |
+
<div class="w-4 h-4 bg-blue-500 rounded-full animate-bounce"></div>
|
| 145 |
+
<div class="w-4 h-4 bg-blue-500 rounded-full animate-bounce" style="animation-delay: 0.2s"></div>
|
| 146 |
+
<div class="w-4 h-4 bg-blue-500 rounded-full animate-bounce" style="animation-delay: 0.4s"></div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
<!-- Result Section -->
|
| 150 |
+
<div id="result" class="result-card opacity-0 transform translate-y-4 hidden">
|
| 151 |
+
<div class="p-6 rounded-xl bg-gradient-to-r from-blue-50 to-green-50">
|
| 152 |
+
<h2 class="text-2xl font-semibold mb-4 text-gray-800">Classification Result</h2>
|
| 153 |
+
<div class="prediction-badge inline-block px-6 py-3 rounded-full text-lg font-medium" id="prediction-text"></div>
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
|
| 157 |
+
<!-- Error Section -->
|
| 158 |
+
<div id="error" class="hidden">
|
| 159 |
+
<div class="p-6 rounded-xl bg-red-50 border border-red-100">
|
| 160 |
+
<div class="flex items-center">
|
| 161 |
+
<svg class="h-6 w-6 text-red-500 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 162 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
| 163 |
+
</svg>
|
| 164 |
+
<p id="error-text" class="text-red-700"></p>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
|
| 170 |
+
<!-- History Section -->
|
| 171 |
+
<div class="mt-16">
|
| 172 |
+
<div class="flex justify-between items-center mb-6">
|
| 173 |
+
<h2 class="text-2xl font-bold text-gray-800">Recent Predictions</h2>
|
| 174 |
+
<div class="flex gap-2">
|
| 175 |
+
<button class="filter-btn px-4 py-2 rounded-full text-sm font-medium bg-gray-100 text-gray-700 hover:bg-blue-100 hover:text-blue-700 transition-colors active flex items-center gap-2" data-filter="all">
|
| 176 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" stroke="currentColor"/><path d="M8 12h8" stroke="currentColor" stroke-linecap="round"/></svg>
|
| 177 |
+
All
|
| 178 |
+
</button>
|
| 179 |
+
<button class="filter-btn px-4 py-2 rounded-full text-sm font-medium bg-green-100 text-green-800 hover:bg-green-200 transition-colors flex items-center gap-2" data-filter="Dry Waste">
|
| 180 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><rect x="4" y="4" width="16" height="16" rx="4" stroke="#22c55e"/><path d="M8 12h8" stroke="#22c55e" stroke-linecap="round"/></svg>
|
| 181 |
+
Dry Waste
|
| 182 |
+
</button>
|
| 183 |
+
<button class="filter-btn px-4 py-2 rounded-full text-sm font-medium bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors flex items-center gap-2" data-filter="Wet Waste">
|
| 184 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><ellipse cx="12" cy="12" rx="8" ry="10" stroke="#2563eb"/><path d="M8 12h8" stroke="#2563eb" stroke-linecap="round"/></svg>
|
| 185 |
+
Wet Waste
|
| 186 |
+
</button>
|
| 187 |
+
</div>
|
| 188 |
+
<button id="clear-history" class="px-4 py-2 text-sm text-red-600 hover:text-red-700 transition-colors">
|
| 189 |
+
Clear History
|
| 190 |
+
</button>
|
| 191 |
+
</div>
|
| 192 |
+
<div id="history-container" class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-8">
|
| 193 |
+
{% for item in history %}
|
| 194 |
+
<div class="history-card bg-white border border-gray-100 rounded-2xl shadow-lg overflow-hidden transform transition-all duration-300 hover:scale-105 hover:shadow-2xl group opacity-100 scale-100" data-prediction="{{ item.prediction }}">
|
| 195 |
+
<div class="p-0 flex flex-col items-center">
|
| 196 |
+
<div class="w-full h-56 bg-gray-50 flex items-center justify-center overflow-hidden rounded-t-2xl relative">
|
| 197 |
+
<img src="data:image/jpeg;base64,{{ item.image }}"
|
| 198 |
+
alt="Prediction"
|
| 199 |
+
class="object-cover w-full h-full transition-transform duration-300 group-hover:scale-110"
|
| 200 |
+
onerror="this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgZmlsbD0iI2YzZjRmNiIvPjx0ZXh0IHg9IjUwJSIgeT0iNTAlIiBmb250LWZhbWlseT0iQXJpYWwiIGZvbnQtc2l6ZT0iMTYiIGZpbGw9IiM5Y2EzYWYiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGR5PSIuM2VtIj5JbWFnZSBsb2FkIGVycm9yPC90ZXh0Pjwvc3ZnPg=='">
|
| 201 |
+
</div>
|
| 202 |
+
<div class="flex flex-col items-center w-full p-4">
|
| 203 |
+
<span class="prediction-badge px-5 py-2 mb-2 rounded-full text-base font-semibold shadow-sm transition-all duration-300
|
| 204 |
+
{% if item.prediction == 'Dry Waste' %}
|
| 205 |
+
bg-green-100 text-green-800 border border-green-200
|
| 206 |
+
{% else %}
|
| 207 |
+
bg-blue-100 text-blue-800 border border-blue-200
|
| 208 |
+
{% endif %}">
|
| 209 |
+
{{ item.prediction }}
|
| 210 |
+
</span>
|
| 211 |
+
<span class="history-date block text-xs text-gray-400 mt-1" data-date="{{ item.timestamp }}">{{ item.timestamp }}</span>
|
| 212 |
+
</div>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
{% endfor %}
|
| 216 |
+
</div>
|
| 217 |
+
{% if not history %}
|
| 218 |
+
<div class="text-center py-8 text-gray-500">
|
| 219 |
+
<p>No predictions yet. Upload an image to get started!</p>
|
| 220 |
+
</div>
|
| 221 |
+
{% endif %}
|
| 222 |
+
<!-- Info Section: Now directly below history -->
|
| 223 |
+
<div class="mt-10 text-center text-gray-500">
|
| 224 |
+
<p class="text-sm">Supported formats: <span class="font-medium text-gray-700">PNG, JPG, JPEG</span></p>
|
| 225 |
+
<p class="text-sm mt-1">Maximum file size: <span class="font-medium text-gray-700">16MB</span></p>
|
| 226 |
+
</div>
|
| 227 |
+
</div>
|
| 228 |
+
</div>
|
| 229 |
+
</div>
|
| 230 |
+
|
| 231 |
+
<script>
|
| 232 |
+
const dropZone = document.getElementById('drop-zone');
|
| 233 |
+
const fileInput = document.getElementById('file-input');
|
| 234 |
+
const loading = document.getElementById('loading');
|
| 235 |
+
const result = document.getElementById('result');
|
| 236 |
+
const predictionText = document.getElementById('prediction-text');
|
| 237 |
+
const error = document.getElementById('error');
|
| 238 |
+
const errorText = document.getElementById('error-text');
|
| 239 |
+
const imagePreview = document.getElementById('image-preview');
|
| 240 |
+
const previewContainer = document.getElementById('preview-container');
|
| 241 |
+
const removeImage = document.getElementById('remove-image');
|
| 242 |
+
|
| 243 |
+
// Handle drag and drop
|
| 244 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
| 245 |
+
dropZone.addEventListener(eventName, preventDefaults, false);
|
| 246 |
+
});
|
| 247 |
+
|
| 248 |
+
function preventDefaults(e) {
|
| 249 |
+
e.preventDefault();
|
| 250 |
+
e.stopPropagation();
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
['dragenter', 'dragover'].forEach(eventName => {
|
| 254 |
+
dropZone.addEventListener(eventName, highlight, false);
|
| 255 |
+
});
|
| 256 |
+
|
| 257 |
+
['dragleave', 'drop'].forEach(eventName => {
|
| 258 |
+
dropZone.addEventListener(eventName, unhighlight, false);
|
| 259 |
+
});
|
| 260 |
+
|
| 261 |
+
function highlight(e) {
|
| 262 |
+
dropZone.classList.add('border-blue-500', 'bg-blue-50');
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
function unhighlight(e) {
|
| 266 |
+
dropZone.classList.remove('border-blue-500', 'bg-blue-50');
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
dropZone.addEventListener('drop', handleDrop, false);
|
| 270 |
+
dropZone.addEventListener('click', () => fileInput.click());
|
| 271 |
+
fileInput.addEventListener('change', handleFileSelect);
|
| 272 |
+
removeImage.addEventListener('click', resetUpload);
|
| 273 |
+
|
| 274 |
+
function handleDrop(e) {
|
| 275 |
+
const dt = e.dataTransfer;
|
| 276 |
+
const files = dt.files;
|
| 277 |
+
handleFiles(files);
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
function handleFileSelect(e) {
|
| 281 |
+
const files = e.target.files;
|
| 282 |
+
handleFiles(files);
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
function handleFiles(files) {
|
| 286 |
+
if (files.length > 0) {
|
| 287 |
+
const file = files[0];
|
| 288 |
+
if (file.type.startsWith('image/')) {
|
| 289 |
+
showImagePreview(file);
|
| 290 |
+
uploadFile(file);
|
| 291 |
+
} else {
|
| 292 |
+
showError('Please upload an image file (PNG, JPG, or JPEG)');
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
function showImagePreview(file) {
|
| 298 |
+
const reader = new FileReader();
|
| 299 |
+
reader.onload = function(e) {
|
| 300 |
+
imagePreview.src = e.target.result;
|
| 301 |
+
imagePreview.classList.add('show');
|
| 302 |
+
previewContainer.classList.add('show');
|
| 303 |
+
dropZone.style.display = 'none';
|
| 304 |
+
}
|
| 305 |
+
reader.readAsDataURL(file);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
function resetUpload() {
|
| 309 |
+
imagePreview.src = '';
|
| 310 |
+
imagePreview.classList.remove('show');
|
| 311 |
+
previewContainer.classList.remove('show');
|
| 312 |
+
dropZone.style.display = 'block';
|
| 313 |
+
result.classList.add('hidden');
|
| 314 |
+
error.classList.add('hidden');
|
| 315 |
+
fileInput.value = '';
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
function uploadFile(file) {
|
| 319 |
+
const formData = new FormData();
|
| 320 |
+
formData.append('file', file);
|
| 321 |
+
|
| 322 |
+
loading.classList.add('active');
|
| 323 |
+
result.classList.add('hidden');
|
| 324 |
+
error.classList.add('hidden');
|
| 325 |
+
|
| 326 |
+
fetch('/predict', {
|
| 327 |
+
method: 'POST',
|
| 328 |
+
body: formData
|
| 329 |
+
})
|
| 330 |
+
.then(response => response.json())
|
| 331 |
+
.then(data => {
|
| 332 |
+
loading.classList.remove('active');
|
| 333 |
+
if (data.error) {
|
| 334 |
+
showError(data.error);
|
| 335 |
+
} else {
|
| 336 |
+
showResult(data.prediction);
|
| 337 |
+
setTimeout(() => { window.location.reload(); }, 1000);
|
| 338 |
+
}
|
| 339 |
+
})
|
| 340 |
+
.catch(err => {
|
| 341 |
+
loading.classList.remove('active');
|
| 342 |
+
showError('An error occurred while processing your request');
|
| 343 |
+
});
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
function showResult(prediction) {
|
| 347 |
+
result.classList.remove('hidden');
|
| 348 |
+
predictionText.textContent = prediction;
|
| 349 |
+
|
| 350 |
+
// Add appropriate styling based on prediction
|
| 351 |
+
if (prediction === 'Dry Waste') {
|
| 352 |
+
predictionText.className = 'prediction-badge inline-block px-6 py-3 rounded-full text-lg font-medium bg-green-100 text-green-800';
|
| 353 |
+
} else {
|
| 354 |
+
predictionText.className = 'prediction-badge inline-block px-6 py-3 rounded-full text-lg font-medium bg-blue-100 text-blue-800';
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
// Trigger animation
|
| 358 |
+
setTimeout(() => {
|
| 359 |
+
result.classList.add('show');
|
| 360 |
+
}, 50);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function showError(message) {
|
| 364 |
+
error.classList.remove('hidden');
|
| 365 |
+
errorText.textContent = message;
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
// Format history dates for a modern look
|
| 369 |
+
[...document.querySelectorAll('.history-date')].forEach(function(el) {
|
| 370 |
+
const raw = el.getAttribute('data-date');
|
| 371 |
+
if (raw) {
|
| 372 |
+
const d = new Date(raw.replace(' ', 'T'));
|
| 373 |
+
if (!isNaN(d)) {
|
| 374 |
+
el.textContent = d.toLocaleString(undefined, {
|
| 375 |
+
year: 'numeric', month: 'short', day: 'numeric',
|
| 376 |
+
hour: '2-digit', minute: '2-digit'
|
| 377 |
+
});
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
});
|
| 381 |
+
|
| 382 |
+
// Clear History
|
| 383 |
+
document.getElementById('clear-history').addEventListener('click', function() {
|
| 384 |
+
if (confirm('Are you sure you want to clear the prediction history?')) {
|
| 385 |
+
fetch('/clear-history', {
|
| 386 |
+
method: 'POST'
|
| 387 |
+
})
|
| 388 |
+
.then(response => response.json())
|
| 389 |
+
.then(data => {
|
| 390 |
+
if (data.success) {
|
| 391 |
+
document.getElementById('history-container').innerHTML = `
|
| 392 |
+
<div class="text-center py-8 text-gray-500 col-span-full">
|
| 393 |
+
<p>No predictions yet. Upload an image to get started!</p>
|
| 394 |
+
</div>
|
| 395 |
+
`;
|
| 396 |
+
}
|
| 397 |
+
})
|
| 398 |
+
.catch(err => {
|
| 399 |
+
console.error('Error clearing history:', err);
|
| 400 |
+
});
|
| 401 |
+
}
|
| 402 |
+
});
|
| 403 |
+
|
| 404 |
+
tsParticles.load("tsparticles", {
|
| 405 |
+
fullScreen: { enable: false },
|
| 406 |
+
background: { color: "transparent" },
|
| 407 |
+
particles: {
|
| 408 |
+
number: { value: 60, density: { enable: true, value_area: 800 } },
|
| 409 |
+
color: { value: ["#4ade80", "#60a5fa", "#facc15"] },
|
| 410 |
+
shape: { type: "circle" },
|
| 411 |
+
opacity: { value: 0.25 },
|
| 412 |
+
size: { value: 4, random: { enable: true, minimumValue: 2 } },
|
| 413 |
+
move: { enable: true, speed: 1, direction: "none", outModes: "out" }
|
| 414 |
+
},
|
| 415 |
+
interactivity: {
|
| 416 |
+
events: { onHover: { enable: true, mode: "repulse" }, resize: true },
|
| 417 |
+
modes: { repulse: { distance: 80, duration: 0.4 } }
|
| 418 |
+
}
|
| 419 |
+
});
|
| 420 |
+
|
| 421 |
+
// Filter functionality for history cards (wrapped in DOMContentLoaded)
|
| 422 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 423 |
+
const filterBtns = document.querySelectorAll('.filter-btn');
|
| 424 |
+
const historyCards = document.querySelectorAll('.history-card');
|
| 425 |
+
filterBtns.forEach(btn => {
|
| 426 |
+
btn.addEventListener('click', function() {
|
| 427 |
+
filterBtns.forEach(b => b.classList.remove('active', 'bg-blue-100', 'text-blue-700'));
|
| 428 |
+
this.classList.add('active', 'bg-blue-100', 'text-blue-700');
|
| 429 |
+
const filter = this.getAttribute('data-filter');
|
| 430 |
+
historyCards.forEach(card => {
|
| 431 |
+
if (filter === 'all' || card.getAttribute('data-prediction') === filter) {
|
| 432 |
+
card.style.display = '';
|
| 433 |
+
card.classList.remove('opacity-0', 'scale-95');
|
| 434 |
+
card.classList.add('opacity-100', 'scale-100');
|
| 435 |
+
} else {
|
| 436 |
+
card.classList.add('opacity-0', 'scale-95');
|
| 437 |
+
setTimeout(() => { card.style.display = 'none'; }, 200);
|
| 438 |
+
}
|
| 439 |
+
});
|
| 440 |
+
});
|
| 441 |
+
});
|
| 442 |
+
});
|
| 443 |
+
|
| 444 |
+
// Webcam detection logic
|
| 445 |
+
const cameraBtn = document.getElementById('camera-btn');
|
| 446 |
+
const cameraModal = document.getElementById('camera-modal');
|
| 447 |
+
const closeCamera = document.getElementById('close-camera');
|
| 448 |
+
const webcam = document.getElementById('webcam');
|
| 449 |
+
const webcamCanvas = document.getElementById('webcam-canvas');
|
| 450 |
+
const captureBtn = document.getElementById('capture-btn');
|
| 451 |
+
|
| 452 |
+
let stream = null;
|
| 453 |
+
|
| 454 |
+
cameraBtn.addEventListener('click', async (event) => {
|
| 455 |
+
event.stopPropagation(); // Prevents drop zone click
|
| 456 |
+
cameraModal.classList.remove('hidden');
|
| 457 |
+
try {
|
| 458 |
+
stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 459 |
+
webcam.srcObject = stream;
|
| 460 |
+
} catch (err) {
|
| 461 |
+
alert('Could not access the camera.');
|
| 462 |
+
cameraModal.classList.add('hidden');
|
| 463 |
+
}
|
| 464 |
+
});
|
| 465 |
+
|
| 466 |
+
closeCamera.addEventListener('click', () => {
|
| 467 |
+
cameraModal.classList.add('hidden');
|
| 468 |
+
if (stream) {
|
| 469 |
+
stream.getTracks().forEach(track => track.stop());
|
| 470 |
+
}
|
| 471 |
+
});
|
| 472 |
+
|
| 473 |
+
captureBtn.addEventListener('click', () => {
|
| 474 |
+
const context = webcamCanvas.getContext('2d');
|
| 475 |
+
webcamCanvas.width = webcam.videoWidth;
|
| 476 |
+
webcamCanvas.height = webcam.videoHeight;
|
| 477 |
+
context.drawImage(webcam, 0, 0, webcam.videoWidth, webcam.videoHeight);
|
| 478 |
+
webcamCanvas.toBlob(blob => {
|
| 479 |
+
// Stop the camera
|
| 480 |
+
if (stream) {
|
| 481 |
+
stream.getTracks().forEach(track => track.stop());
|
| 482 |
+
}
|
| 483 |
+
cameraModal.classList.add('hidden');
|
| 484 |
+
// Send the captured image as a file to the backend
|
| 485 |
+
const file = new File([blob], 'webcam.jpg', { type: 'image/jpeg' });
|
| 486 |
+
uploadFile(file);
|
| 487 |
+
}, 'image/jpeg', 0.95);
|
| 488 |
+
});
|
| 489 |
+
</script>
|
| 490 |
+
</body>
|
| 491 |
+
</html>
|