Spaces:
Sleeping
Sleeping
File size: 13,537 Bytes
2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 86e6366 1c6d657 86e6366 cb18342 1c6d657 2340261 86e6366 2340261 1c6d657 86e6366 1c6d657 2340261 1c6d657 cb18342 86e6366 1c6d657 86e6366 1c6d657 86e6366 1c6d657 2340261 1c6d657 2340261 cb18342 2340261 1c6d657 2340261 86e6366 1c6d657 2340261 1c6d657 86e6366 2340261 86e6366 1c6d657 86e6366 cb18342 86e6366 1c6d657 86e6366 2340261 1c6d657 2340261 1c6d657 86e6366 1c6d657 86e6366 2340261 86e6366 2340261 86e6366 2340261 86e6366 1c6d657 86e6366 1c6d657 2340261 1c6d657 86e6366 1c6d657 2340261 1c6d657 2340261 86e6366 cb18342 86e6366 1c6d657 2340261 1c6d657 cb18342 2340261 86e6366 1c6d657 2340261 86e6366 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 86e6366 2340261 1c6d657 86e6366 cb18342 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 86e6366 2340261 86e6366 2340261 86e6366 2340261 1c6d657 2340261 86e6366 2340261 1c6d657 2340261 1c6d657 86e6366 1c6d657 2340261 86e6366 1c6d657 2340261 86e6366 1c6d657 2340261 86e6366 1c6d657 2340261 1c6d657 86e6366 00f0a41 2340261 1c6d657 2340261 1c6d657 86e6366 00f0a41 2340261 86e6366 2340261 1c6d657 86e6366 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 86e6366 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 1c6d657 2340261 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Threat Detection Comparison</title>
<style>
:root {
--primary: #E73562;
--secondary: #EA782D;
--rf-accent: #E73562;
--yolo-accent: #33ff99;
--dark-bg: #121212;
--surface-bg: #1E1E2E;
--text-primary: #E0E0E0;
--text-secondary: #BDB2C6;
--border-color: rgba(255, 255, 255, 0.06);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: var(--dark-bg);
color: var(--text-primary);
padding: 20px;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.container {
width: 100%;
max-width: 1600px;
margin: 0 auto;
background: var(--surface-bg);
border-radius: 14px;
box-shadow: 0 10px 30px rgba(0,0,0,0.35);
border: 1px solid var(--border-color);
overflow: hidden;
display: flex;
flex-direction: column;
flex: 1;
}
header {
text-align: center;
padding: 15px;
background: rgba(0,0,0,0.18);
border-bottom: 1px solid var(--border-color);
}
h1 {
/* FIX: Removed background-clip text which was causing the solid orange bar */
color: var(--primary);
text-shadow: 0 2px 10px rgba(231, 53, 98, 0.2);
font-size: 1.8em;
font-weight: 700;
margin-bottom: 4px;
}
.header-note {
font-size: 0.85rem;
color: var(--text-secondary);
}
.main-content {
display: flex;
flex-direction: column;
flex: 1;
padding: 20px;
gap: 20px;
}
/* Top Controls Bar */
.controls-top {
display: flex;
gap: 20px;
background: rgba(0,0,0,0.15);
border-radius: 12px;
padding: 20px;
border: 1px solid var(--border-color);
align-items: center;
flex-wrap: wrap;
}
.upload-group {
flex: 1;
min-width: 300px;
}
.preview-group {
width: 150px;
height: 100px;
background: #000;
border: 1px solid var(--border-color);
border-radius: 8px;
display: none;
overflow: hidden;
position: relative;
}
.preview-group img {
width: 100%;
height: 100%;
object-fit: cover;
}
.actions-group {
display: flex;
flex-direction: column;
gap: 10px;
min-width: 250px;
}
.upload-area {
border: 2px dashed var(--primary);
border-radius: 8px;
padding: 25px;
text-align: center;
transition: all 0.2s ease;
cursor: pointer;
background: rgba(255,255,255,0.02);
height: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.upload-area:hover, .upload-area.dragover {
background: rgba(231, 53, 98, 0.08);
border-color: var(--secondary);
}
.upload-area p { color: var(--text-secondary); font-size: 0.95em; margin: 0; }
label { color: var(--text-secondary); font-size: 0.85em; display: flex; justify-content: space-between; margin-bottom: 4px; }
.slider-val { color: var(--primary); font-weight: bold; }
input[type="range"] {
width: 100%; height: 6px; border-radius: 4px;
background: rgba(255,255,255,0.1); outline: none; -webkit-appearance: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
background: var(--primary); cursor: pointer;
}
.action-btn {
background: linear-gradient(135deg, var(--primary), var(--secondary));
color: white; border: none; padding: 12px 24px;
border-radius: 8px; font-weight: 600;
cursor: pointer; width: 100%;
transition: transform 0.2s;
}
.action-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 4px 15px rgba(231, 53, 98, 0.4); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; background: #444; }
/* Results Area */
.results-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
flex: 1;
min-height: 0;
}
.result-card {
background: rgba(0,0,0,0.2);
border-radius: 12px;
border: 1px solid var(--border-color);
display: flex;
flex-direction: column;
overflow: hidden;
height: 100%;
}
.card-header {
padding: 12px 15px;
border-bottom: 1px solid var(--border-color);
font-weight: 600;
letter-spacing: 0.5px;
display: flex;
align-items: center;
gap: 8px;
background: rgba(0,0,0,0.1);
}
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.rf { background: var(--rf-accent); box-shadow: 0 0 8px var(--rf-accent); }
.dot.yolo { background: var(--yolo-accent); box-shadow: 0 0 8px var(--yolo-accent); }
.image-box {
flex: 1;
background: #000;
position: relative;
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
height: 100%;
min-height: 500px;
width: 100%;
}
.image-box img {
width: 100%;
height: 100%;
object-fit: contain;
display: block;
}
.loader {
position: absolute;
inset: 0;
background: rgba(0,0,0,0.7);
display: none;
justify-content: center;
align-items: center;
flex-direction: column;
color: var(--text-secondary);
font-size: 1.1em;
z-index: 10;
}
.spinner {
width: 40px; height: 40px;
border: 4px solid rgba(255,255,255,0.1);
border-radius: 50%;
margin-bottom: 15px;
animation: spin 1s linear infinite;
}
.rf .spinner { border-top-color: var(--rf-accent); }
.yolo .spinner { border-top-color: var(--yolo-accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) {
.controls-top { flex-direction: column; align-items: stretch; }
.preview-group { width: 100%; height: 150px; }
.results-grid { grid-template-columns: 1fr; }
.image-box { min-height: 400px; }
}
.visually-hidden { position:absolute; left:-9999px; }
</style>
</head>
<body>
<div class="container">
<header>
<h1>Comparison: RF-DETR vs YOLOv8</h1>
<p class="header-note">Threat Detection on CPU • Upload an image to compare model performance</p>
</header>
<div class="main-content">
<!-- Top Controls (Full Width) -->
<div class="controls-top">
<!-- 1. Upload -->
<div class="upload-group">
<div id="upload-area" class="upload-area">
<p style="font-size: 1.1em; font-weight: 500; color: var(--text-primary);">Click or Drop Image Here</p>
<p style="font-size: 0.8em; margin-top: 5px;">JPG, PNG supported</p>
</div>
<input id="file-input" class="visually-hidden" type="file" accept="image/*" />
</div>
<!-- 2. Preview (Appears after upload) -->
<div id="preview-container" class="preview-group">
<img id="preview-img" src="" alt="Input">
</div>
<!-- 3. Actions -->
<div class="actions-group">
<div>
<label>Confidence Threshold <span id="conf-val" class="slider-val">0.25</span></label>
<input id="conf-slider" type="range" min="0.05" max="0.95" step="0.05" value="0.25">
</div>
<button id="predict-btn" class="action-btn" disabled>RUN COMPARISON</button>
</div>
</div>
<!-- Bottom Results (Grid) -->
<div class="results-grid">
<!-- RF-DETR -->
<div class="result-card rf">
<div class="card-header">
<span class="dot rf"></span> RF-DETR Nano
</div>
<div class="image-box">
<div class="loader" id="loader-rf"><div class="spinner"></div>Inference Running...</div>
<img id="res-rf">
</div>
</div>
<!-- YOLOv8 -->
<div class="result-card yolo">
<div class="card-header">
<span class="dot yolo"></span> YOLOv8 Nano
</div>
<div class="image-box">
<div class="loader" id="loader-yolo"><div class="spinner"></div>Inference Running...</div>
<img id="res-yolo">
</div>
</div>
</div>
</div>
</div>
<script>
const fileInput = document.getElementById('file-input');
const uploadArea = document.getElementById('upload-area');
const previewContainer = document.getElementById('preview-container');
const previewImg = document.getElementById('preview-img');
const predictBtn = document.getElementById('predict-btn');
const confSlider = document.getElementById('conf-slider');
const confVal = document.getElementById('conf-val');
const resRf = document.getElementById('res-rf');
const resYolo = document.getElementById('res-yolo');
const loadRf = document.getElementById('loader-rf');
const loadYolo = document.getElementById('loader-yolo');
let currentDataUrl = null;
// --- Event Listeners ---
confSlider.addEventListener('input', (e) => confVal.textContent = e.target.value);
uploadArea.addEventListener('click', () => fileInput.click());
uploadArea.addEventListener('dragover', (e) => { e.preventDefault(); uploadArea.classList.add('dragover'); });
uploadArea.addEventListener('dragleave', () => uploadArea.classList.remove('dragover'));
uploadArea.addEventListener('drop', (e) => {
e.preventDefault();
uploadArea.classList.remove('dragover');
if(e.dataTransfer.files[0]) handleFile(e.dataTransfer.files[0]);
});
fileInput.addEventListener('change', (e) => {
if(e.target.files[0]) handleFile(e.target.files[0]);
});
function handleFile(file) {
const reader = new FileReader();
reader.onload = (e) => {
currentDataUrl = e.target.result;
previewImg.src = currentDataUrl;
previewContainer.style.display = 'block'; // Show preview
predictBtn.disabled = false;
// Clear previous results
resRf.src = "";
resYolo.src = "";
};
reader.readAsDataURL(file);
}
predictBtn.addEventListener('click', async () => {
if(!currentDataUrl) return;
// UI State: Running
predictBtn.disabled = true;
loadRf.style.display = 'flex';
loadYolo.style.display = 'flex';
try {
const response = await fetch('/predict', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
image: currentDataUrl,
conf: parseFloat(confSlider.value)
})
});
const data = await response.json();
if(data.error) throw new Error(data.error);
// Set Results
resRf.src = data.rfdetr.image;
resYolo.src = data.yolov8.image;
} catch (err) {
console.error(err);
alert("Prediction Error: " + err.message);
} finally {
predictBtn.disabled = false;
loadRf.style.display = 'none';
loadYolo.style.display = 'none';
}
});
</script>
</body>
</html> |