Spaces:
Sleeping
Sleeping
File size: 17,129 Bytes
80c4760 ac8c4df 80c4760 ac8c4df 80c4760 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 75d2ec6 80c4760 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 75d2ec6 80c4760 75d2ec6 80c4760 75d2ec6 80c4760 75d2ec6 80c4760 75d2ec6 80c4760 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 75d2ec6 80c4760 75d2ec6 ac8c4df 80c4760 75d2ec6 ac8c4df 80c4760 ac8c4df 75d2ec6 ac8c4df 75d2ec6 ac8c4df 75d2ec6 ac8c4df 75d2ec6 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 75d2ec6 ac8c4df 75d2ec6 ac8c4df 80c4760 ac8c4df 80c4760 75d2ec6 ac8c4df 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 75d2ec6 ac8c4df 75d2ec6 80c4760 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 75d2ec6 ac8c4df 80c4760 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 75d2ec6 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 80c4760 ac8c4df 75d2ec6 ac8c4df 75d2ec6 ac8c4df 80c4760 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YOLO Vision AI - Multi-Image Analysis</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%);
min-height: 100vh;
overflow-x: hidden;
position: relative;
color: #e0e0e0;
}
.particles {
position: absolute; width: 100%; height: 100%; overflow: hidden; z-index: 0;
}
.particle {
position: absolute; width: 2px; height: 2px; background: #00d4ff; border-radius: 50%; animation: float 6s ease-in-out infinite; opacity: 0.6;
}
@keyframes float {
0%, 100% { transform: translateY(0px) rotate(0deg); }
50% { transform: translateY(-20px) rotate(180deg); }
}
.container {
position: relative; z-index: 1; max-width: 800px; margin: 0 auto; padding: 2rem; min-height: 100vh; display: flex; flex-direction: column; justify-content: flex-start; align-items: center;
}
.header {
text-align: center; margin-bottom: 2rem; animation: slideDown 1s ease-out; width: 100%;
}
.title {
font-size: 3.5rem; font-weight: 700; background: linear-gradient(45deg, #00d4ff, #ff00ff, #00ff88); background-size: 200% 200%; -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; animation: gradientShift 3s ease-in-out infinite; margin-bottom: 1rem; text-shadow: 0 0 30px rgba(0, 212, 255, 0.5);
}
.subtitle {
font-size: 1.2rem; color: #a0a0a0; font-weight: 300;
}
.upload-area {
width: 100%; max-width: 550px; min-height: 300px; border: 2px dashed #00d4ff; border-radius: 20px; background: rgba(0, 212, 255, 0.05); backdrop-filter: blur(10px); display: flex; flex-direction: column; justify-content: center; align-items: center; cursor: pointer; transition: all 0.3s ease; position: relative; overflow: hidden; animation: slideUp 1s ease-out 0.3s both;
}
.upload-area:hover {
border-color: #ff00ff; background: rgba(255, 0, 255, 0.05); transform: translateY(-5px); box-shadow: 0 20px 40px rgba(0, 212, 255, 0.2);
}
.upload-area.dragover {
border-color: #00ff88; background: rgba(0, 255, 136, 0.1); transform: scale(1.02);
}
.upload-icon {
font-size: 4rem; color: #00d4ff; margin-bottom: 1rem; transition: all 0.3s ease;
}
.upload-area:hover .upload-icon {
color: #ff00ff; transform: scale(1.1);
}
.upload-text {
color: #ffffff; font-size: 1.1rem; margin-bottom: 0.5rem; font-weight: 500;
}
.upload-subtext {
color: #a0a0a0; font-size: 0.9rem;
}
.file-input {
display: none;
}
.file-list-container {
display: none;
width: 100%;
max-width: 550px;
margin-top: 2rem;
animation: fadeIn 0.5s ease;
}
#fileList {
list-style: none;
background: rgba(0, 212, 255, 0.05);
border-radius: 10px;
padding: 1rem;
max-height: 200px;
overflow-y: auto;
border: 1px solid rgba(0, 212, 255, 0.2);
}
#fileList li {
padding: 0.5rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
color: #c0c0c0;
}
#fileList li:last-child {
border-bottom: none;
}
.analyze-button {
display: block;
width: 100%;
background: linear-gradient(45deg, #00d4ff, #0099cc); border: none; color: white; padding: 15px 40px; font-size: 1.1rem; font-weight: 600; border-radius: 50px; cursor: pointer; margin-top: 1.5rem; transition: all 0.3s ease; text-transform: uppercase; letter-spacing: 1px;
}
.analyze-button:hover {
transform: translateY(-2px); box-shadow: 0 10px 25px rgba(0, 212, 255, 0.4); background: linear-gradient(45deg, #ff00ff, #cc0099);
}
.analyze-button:disabled {
opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; background: #555;
}
.loading {
display: none; margin-top: 2rem; text-align: center;
}
.spinner {
width: 40px; height: 40px; border: 4px solid rgba(0, 212, 255, 0.3); border-top: 4px solid #00d4ff; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto;
}
#results-container {
margin-top: 2rem;
width: 100%;
max-width: 550px; /* Adjusted max-width */
}
.result-card {
padding: 1.5rem;
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(15px);
border: 1px solid rgba(0, 212, 255, 0.3);
animation: slideUp 0.5s ease-out;
margin-bottom: 2rem;
border-radius: 15px; /* Unified border radius */
}
/* --- NEW: Image style within the card --- */
.result-image {
width: 100%;
height: auto;
max-height: 400px;
object-fit: contain;
border-radius: 10px;
margin-bottom: 1.5rem;
background-color: rgba(0,0,0,0.2);
}
.result-card h3 {
font-size: 1.2rem;
color: #00d4ff;
margin-bottom: 1.5rem;
padding-bottom: 1rem;
border-bottom: 1px solid rgba(0, 212, 255, 0.2);
font-weight: 600;
word-wrap: break-word;
}
.prediction-block {
margin-bottom: 1.5rem;
}
.prediction-block:last-child {
margin-bottom: 0;
}
.prediction-title {
font-size: 0.9rem;
color: #a0a0a0;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 0.5rem;
}
.prediction-class {
font-size: 1.8rem; /* Made class name larger */
font-weight: 700;
color: #00ff88;
text-transform: capitalize;
line-height: 1.2;
}
.prediction-confidence {
font-size: 1rem; /* Slightly larger confidence text */
color: #e0e0e0;
}
.damage-note {
font-size: 0.8rem;
color: #aaa;
font-style: italic;
margin-top: 4px;
}
.error {
color: #ff4444; background: rgba(255, 68, 68, 0.1); padding: 1rem; border-radius: 10px; border: 1px solid #ff4444; margin-top: 2rem; width: 100%; max-width: 550px;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-50px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(50px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes gradientShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@media (max-width: 768px) {
.title { font-size: 2.5rem; } .container { padding: 1rem; } .upload-area { min-height: 250px; }
}
</style>
</head>
<body>
<div class="particles" id="particles"></div>
<div class="container">
<div class="header">
<h1 class="title">YOLO Vision AI</h1>
<p class="subtitle">Multi-Image Vehicle Part & Damage Analysis</p>
</div>
<div class="upload-area" id="uploadArea">
<div class="upload-icon">🔮</div>
<div class="upload-text">Drop your images here or click to upload</div>
<div class="upload-subtext">Supports PNG, JPG, JPEG formats</div>
<input type="file" id="fileInput" class="file-input" accept=".png,.jpg,.jpeg" multiple>
</div>
<div class="file-list-container" id="fileListContainer">
<ul id="fileList"></ul>
<button class="analyze-button" id="analyzeButton">🚀 Analyze Images</button>
</div>
<div class="loading" id="loading">
<div class="spinner"></div>
<p style="color: #00d4ff; margin-top: 1rem;">Processing your images...</p>
</div>
<div id="results-container"></div>
<div class="error" id="errorContainer" style="display: none;"></div>
</div>
<script>
// Create animated particles
function createParticles() {
const container = document.getElementById('particles');
if (container.children.length > 0) return;
for (let i = 0; i < 50; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
particle.style.animationDelay = Math.random() * 6 + 's';
particle.style.animationDuration = (3 + Math.random() * 3) + 's';
container.appendChild(particle);
}
}
createParticles();
// DOM elements
const uploadArea = document.getElementById('uploadArea');
const fileInput = document.getElementById('fileInput');
const fileListContainer = document.getElementById('fileListContainer');
const fileList = document.getElementById('fileList');
const analyzeButton = document.getElementById('analyzeButton');
const loading = document.getElementById('loading');
const errorContainer = document.getElementById('errorContainer');
const resultsContainer = document.getElementById('results-container');
// --- NEW: Store for file objects and their data URLs for preview ---
let fileDataStore = [];
// Event Listeners
uploadArea.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', handleFileSelect);
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
uploadArea.addEventListener(eventName, preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
uploadArea.addEventListener(eventName, () => uploadArea.classList.add('dragover'), false);
});
['dragleave', 'drop'].forEach(eventName => {
uploadArea.addEventListener(eventName, () => uploadArea.classList.remove('dragover'), false);
});
uploadArea.addEventListener('drop', handleDrop, false);
analyzeButton.addEventListener('click', analyzeImages);
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
function handleDrop(e) {
handleFiles(e.dataTransfer.files);
}
function handleFileSelect(e) {
handleFiles(e.target.files);
}
// --- UPDATED: Reads files and generates data URLs for previews ---
async function handleFiles(files) {
if (files.length === 0) return;
// Clear previous selections and results
resetUI();
fileDataStore = [];
const filePromises = Array.from(files).map(file => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
fileDataStore.push({ file: file, dataURL: e.target.result });
resolve();
};
reader.onerror = reject;
reader.readAsDataURL(file);
});
});
await Promise.all(filePromises);
// Update the UI list
fileDataStore.forEach(item => {
const listItem = document.createElement('li');
listItem.textContent = `${item.file.name} (${(item.file.size / 1024).toFixed(1)} KB)`;
fileList.appendChild(listItem);
});
fileListContainer.style.display = 'block';
uploadArea.style.display = 'none'; // Hide upload area after selection
}
async function analyzeImages() {
if (fileDataStore.length === 0) {
showError('Please select one or more images first');
return;
}
loading.style.display = 'block';
analyzeButton.disabled = true;
hideError();
resultsContainer.innerHTML = '';
try {
const formData = new FormData();
fileDataStore.forEach(item => {
formData.append('file', item.file);
});
const response = await fetch('/predict', { method: 'POST', body: formData });
const data = await response.json();
if (response.ok) {
displayResults(data);
} else {
showError(data.error || 'An unknown error occurred during prediction');
}
} catch (error) {
showError('Failed to connect to the server. Please check your connection and try again.');
console.error('Error:', error);
} finally {
loading.style.display = 'none';
analyzeButton.disabled = false;
fileInput.value = '';
}
}
// --- UPDATED: Displays results with image previews ---
function displayResults(results) {
if (!Array.isArray(results) || results.length === 0) {
resultsContainer.innerHTML = '<p>No results were returned from the server.</p>';
return;
}
results.forEach(result => {
// Find the corresponding image data URL from our store
const fileData = fileDataStore.find(item => item.file.name === result.filename);
if (!fileData) return; // Skip if no matching image found
const card = document.createElement('div');
card.className = 'result-card';
const partPred = result.part_prediction;
const damagePred = result.damage_prediction;
const damageNote = damagePred.note ? `<div class="damage-note">${damagePred.note}</div>` : '';
card.innerHTML = `
<img src="${fileData.dataURL}" alt="${result.filename}" class="result-image">
<h3>${result.filename}</h3>
<div class="prediction-block">
<div class="prediction-title">Part Detected</div>
<div class="prediction-class">${partPred.class.replace(/_/g, ' ')}</div>
<div class="prediction-confidence">Confidence: ${(partPred.confidence * 100).toFixed(2)}%</div>
</div>
<div class="prediction-block">
<div class="prediction-title">Damage Status</div>
<div class="prediction-class" style="color: ${damagePred.class === 'correct' ? '#00ff88' : '#ff4444'};">${damagePred.class}</div>
<div class="prediction-confidence">Confidence: ${(damagePred.confidence * 100).toFixed(2)}%</div>
${damageNote}
</div>
`;
resultsContainer.appendChild(card);
});
}
function resetUI() {
fileList.innerHTML = '';
resultsContainer.innerHTML = '';
fileListContainer.style.display = 'none';
uploadArea.style.display = 'flex';
hideError();
}
function showError(message) {
errorContainer.textContent = message;
errorContainer.style.display = 'block';
}
function hideError() {
errorContainer.style.display = 'none';
}
</script>
</body>
</html> |