Spaces:
Running
Running
File size: 27,298 Bytes
1e958b1 |
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 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Upscaler Pro</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.dropzone {
border: 2px dashed #9CA3AF;
transition: all 0.3s ease;
}
.dropzone.active {
border-color: #3B82F6;
background-color: rgba(59, 130, 246, 0.05);
}
.image-card {
transition: all 0.3s ease;
}
.image-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.progress-bar {
transition: width 0.5s ease;
}
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
.animate-pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<header class="mb-10 text-center">
<h1 class="text-4xl font-bold text-gray-800 mb-2">Image Upscaler Pro</h1>
<p class="text-gray-600 max-w-2xl mx-auto">Enhance your images with our advanced upscaling technology. Upload multiple images, process them, and download the results.</p>
</header>
<!-- Main Content -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Upload Section -->
<div class="lg:col-span-1 bg-white rounded-xl shadow-md p-6 h-fit sticky top-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Upload Images</h2>
<!-- Dropzone -->
<div id="dropzone" class="dropzone rounded-lg p-8 text-center cursor-pointer mb-4">
<div class="flex flex-col items-center justify-center space-y-2">
<i class="fas fa-cloud-upload-alt text-4xl text-blue-500"></i>
<p class="text-gray-600">Drag & drop images here or click to browse</p>
<p class="text-sm text-gray-400">Supports JPG, PNG, WEBP (Max 10MB each)</p>
</div>
<input type="file" id="fileInput" class="hidden" accept="image/*" multiple>
</div>
<button id="uploadBtn" class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg flex items-center justify-center space-x-2">
<i class="fas fa-upload"></i>
<span>Select Files</span>
</button>
<div class="mt-6">
<h3 class="font-medium text-gray-700 mb-2">Upscale Options</h3>
<div class="space-y-3">
<div class="flex items-center">
<input type="radio" id="scale2x" name="scale" value="2" class="h-4 w-4 text-blue-600" checked>
<label for="scale2x" class="ml-2 text-gray-700">2x Upscale</label>
</div>
<div class="flex items-center">
<input type="radio" id="scale4x" name="scale" value="4" class="h-4 w-4 text-blue-600">
<label for="scale4x" class="ml-2 text-gray-700">4x Upscale</label>
</div>
<div class="flex items-center">
<input type="radio" id="scale8x" name="scale" value="8" class="h-4 w-4 text-blue-600">
<label for="scale8x" class="ml-2 text-gray-700">8x Upscale (Slow)</label>
</div>
</div>
</div>
<div class="mt-6">
<h3 class="font-medium text-gray-700 mb-2">Processing Options</h3>
<div class="space-y-3">
<div class="flex items-center">
<input type="checkbox" id="enhanceDetails" class="h-4 w-4 text-blue-600 rounded" checked>
<label for="enhanceDetails" class="ml-2 text-gray-700">Enhance Details</label>
</div>
<div class="flex items-center">
<input type="checkbox" id="reduceNoise" class="h-4 w-4 text-blue-600 rounded" checked>
<label for="reduceNoise" class="ml-2 text-gray-700">Reduce Noise</label>
</div>
</div>
</div>
<button id="processBtn" class="w-full mt-6 bg-green-600 hover:bg-green-700 text-white py-3 px-4 rounded-lg font-medium flex items-center justify-center space-x-2 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
<i class="fas fa-magic"></i>
<span>Process Images</span>
</button>
<button id="downloadBtn" class="w-full mt-4 bg-purple-600 hover:bg-purple-700 text-white py-2 px-4 rounded-lg flex items-center justify-center space-x-2 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
<i class="fas fa-file-export"></i>
<span>Export Results</span>
</button>
</div>
<!-- Image Gallery -->
<div class="lg:col-span-2">
<div class="bg-white rounded-xl shadow-md p-6">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-semibold text-gray-800">Image Gallery</h2>
<div class="text-sm text-gray-500">
<span id="imageCount">0</span> images selected
</div>
</div>
<!-- Status Messages -->
<div id="statusMessage" class="hidden mb-6 p-4 rounded-lg"></div>
<!-- Processing Progress -->
<div id="progressContainer" class="hidden mb-6">
<div class="flex justify-between text-sm text-gray-600 mb-1">
<span>Processing images</span>
<span id="progressText">0%</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div id="progressBar" class="progress-bar bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
</div>
</div>
<!-- Empty State -->
<div id="emptyState" class="text-center py-12">
<i class="fas fa-images text-4xl text-gray-300 mb-4"></i>
<h3 class="text-lg font-medium text-gray-500">No images uploaded yet</h3>
<p class="text-gray-400 mt-1">Upload some images to get started</p>
</div>
<!-- Image Grid -->
<div id="imageGrid" class="grid grid-cols-1 sm:grid-cols-2 gap-4 hidden">
<!-- Images will be added here dynamically -->
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// DOM Elements
const dropzone = document.getElementById('dropzone');
const fileInput = document.getElementById('fileInput');
const uploadBtn = document.getElementById('uploadBtn');
const processBtn = document.getElementById('processBtn');
const downloadBtn = document.getElementById('downloadBtn');
const imageGrid = document.getElementById('imageGrid');
const emptyState = document.getElementById('emptyState');
const imageCount = document.getElementById('imageCount');
const progressContainer = document.getElementById('progressContainer');
const progressBar = document.getElementById('progressBar');
const progressText = document.getElementById('progressText');
const statusMessage = document.getElementById('statusMessage');
// State
let images = [];
let processedImages = [];
// Event Listeners
uploadBtn.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', handleFileSelect);
dropzone.addEventListener('dragover', (e) => {
e.preventDefault();
dropzone.classList.add('active');
});
dropzone.addEventListener('dragleave', () => {
dropzone.classList.remove('active');
});
dropzone.addEventListener('drop', (e) => {
e.preventDefault();
dropzone.classList.remove('active');
fileInput.files = e.dataTransfer.files;
handleFileSelect({ target: fileInput });
});
dropzone.addEventListener('click', () => fileInput.click());
processBtn.addEventListener('click', processImages);
downloadBtn.addEventListener('click', exportResults);
// Functions
function handleFileSelect(event) {
const files = event.target.files;
if (!files.length) return;
images = [];
processedImages = [];
imageGrid.innerHTML = '';
let validFiles = 0;
for (let i = 0; i < files.length; i++) {
const file = files[i];
// Check file type
if (!file.type.match('image.*')) {
showStatus(`Skipped ${file.name}: Not an image file`, 'warning');
continue;
}
// Check file size (10MB max)
if (file.size > 10 * 1024 * 1024) {
showStatus(`Skipped ${file.name}: File too large (max 10MB)`, 'warning');
continue;
}
validFiles++;
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.onload = function() {
images.push({
id: Date.now() + i,
name: file.name,
original: e.target.result,
processed: null,
width: img.width,
height: img.height,
status: 'pending'
});
updateUI();
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
if (validFiles > 0) {
showStatus(`Successfully added ${validFiles} image(s)`, 'success');
processBtn.disabled = false;
}
}
function updateUI() {
if (images.length === 0) {
emptyState.classList.remove('hidden');
imageGrid.classList.add('hidden');
imageCount.textContent = '0';
processBtn.disabled = true;
downloadBtn.disabled = true;
return;
}
emptyState.classList.add('hidden');
imageGrid.classList.remove('hidden');
imageCount.textContent = images.length;
imageGrid.innerHTML = '';
images.forEach((img, index) => {
const card = document.createElement('div');
card.className = 'image-card bg-gray-50 rounded-lg overflow-hidden border border-gray-200';
card.innerHTML = `
<div class="relative">
<img src="${img.original}" alt="${img.name}" class="w-full h-40 object-contain bg-gray-100">
<div class="absolute top-2 right-2 bg-white rounded-full p-1 shadow">
${img.status === 'processed' ?
'<i class="fas fa-check-circle text-green-500"></i>' :
img.status === 'processing' ?
'<i class="fas fa-spinner fa-spin text-blue-500"></i>' :
'<i class="fas fa-clock text-gray-400"></i>'}
</div>
</div>
<div class="p-3">
<div class="flex justify-between items-start">
<div class="truncate">
<h3 class="text-sm font-medium text-gray-800 truncate">${img.name}</h3>
<p class="text-xs text-gray-500">${img.width} × ${img.height}</p>
</div>
${img.processed ?
`<span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full">${Math.round((img.processed.size / img.original.length) * 100)}% larger</span>` :
''}
</div>
${img.status === 'processed' ? `
<div class="mt-2 flex space-x-2">
<button class="view-result-btn flex-1 bg-blue-50 hover:bg-blue-100 text-blue-600 text-xs py-1 px-2 rounded flex items-center justify-center space-x-1" data-id="${img.id}">
<i class="fas fa-eye text-xs"></i>
<span>View</span>
</button>
</div>` : ''}
</div>
`;
imageGrid.appendChild(card);
});
// Add event listeners to view buttons
document.querySelectorAll('.view-result-btn').forEach(btn => {
btn.addEventListener('click', function() {
const id = parseInt(this.getAttribute('data-id'));
viewResult(id);
});
});
}
function processImages() {
if (images.length === 0) return;
processBtn.disabled = true;
downloadBtn.disabled = true;
progressContainer.classList.remove('hidden');
// Simulate processing with progress updates
let processed = 0;
const total = images.length;
// Update all images to processing status
images.forEach(img => {
img.status = 'processing';
});
updateUI();
// Process each image (simulated)
const processInterval = setInterval(() => {
if (processed >= total) {
clearInterval(processInterval);
processingComplete();
return;
}
const currentImage = images[processed];
// Simulate processing time (1-3 seconds per image)
setTimeout(() => {
// This is where you would normally call your actual upscaling API
// For demo purposes, we're just creating a slightly larger version
const scaleFactor = parseInt(document.querySelector('input[name="scale"]:checked').value);
const enhanceDetails = document.getElementById('enhanceDetails').checked;
const reduceNoise = document.getElementById('reduceNoise').checked;
// Create a canvas to "process" the image
const canvas = document.createElement('canvas');
const img = new Image();
img.onload = function() {
canvas.width = img.width * scaleFactor;
canvas.height = img.height * scaleFactor;
const ctx = canvas.getContext('2d');
ctx.imageSmoothingEnabled = true;
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
// Apply some "enhancements" (simulated)
if (enhanceDetails || reduceNoise) {
// In a real app, you would apply actual image processing here
// For demo, we'll just add a slight overlay
ctx.globalCompositeOperation = 'overlay';
ctx.fillStyle = enhanceDetails ? 'rgba(255, 255, 255, 0.05)' : 'rgba(0, 0, 0, 0.02)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.globalCompositeOperation = 'source-over';
}
const processedDataUrl = canvas.toDataURL('image/jpeg', 0.9);
currentImage.processed = {
data: processedDataUrl,
size: processedDataUrl.length,
width: canvas.width,
height: canvas.height,
scale: scaleFactor,
options: {
enhanceDetails,
reduceNoise
}
};
currentImage.status = 'processed';
processed++;
const progress = Math.round((processed / total) * 100);
progressBar.style.width = `${progress}%`;
progressText.textContent = `${progress}%`;
updateUI();
if (processed === total) {
processingComplete();
}
};
img.src = currentImage.original;
}, Math.random() * 2000 + 1000);
}, 100);
}
function processingComplete() {
showStatus('All images processed successfully!', 'success');
processBtn.disabled = true;
downloadBtn.disabled = false;
processedImages = [...images];
// Hide progress bar after a delay
setTimeout(() => {
progressContainer.classList.add('hidden');
progressBar.style.width = '0%';
progressText.textContent = '0%';
}, 2000);
}
function viewResult(id) {
const image = images.find(img => img.id === id);
if (!image || !image.processed) return;
// Create modal
const modal = document.createElement('div');
modal.className = 'fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50 p-4';
modal.innerHTML = `
<div class="bg-white rounded-xl max-w-4xl w-full max-h-[90vh] overflow-hidden flex flex-col">
<div class="flex justify-between items-center border-b p-4">
<h3 class="text-lg font-semibold">${image.name}</h3>
<button class="close-modal text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="flex-1 overflow-auto p-4">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<h4 class="text-sm font-medium text-gray-500 mb-2">Original (${image.width} × ${image.height})</h4>
<img src="${image.original}" class="w-full h-auto max-h-[60vh] object-contain bg-gray-100 rounded">
</div>
<div>
<h4 class="text-sm font-medium text-gray-500 mb-2">Upscaled ${image.processed.scale}x (${image.processed.width} × ${image.processed.height})</h4>
<img src="${image.processed.data}" class="w-full h-auto max-h-[60vh] object-contain bg-gray-100 rounded">
</div>
</div>
</div>
<div class="border-t p-4 flex justify-end space-x-3">
<button class="download-single-btn bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg flex items-center space-x-2" data-id="${image.id}">
<i class="fas fa-download"></i>
<span>Download</span>
</button>
</div>
</div>
`;
document.body.appendChild(modal);
// Add event listeners
modal.querySelector('.close-modal').addEventListener('click', () => {
document.body.removeChild(modal);
});
modal.querySelector('.download-single-btn').addEventListener('click', () => {
downloadSingleImage(image);
document.body.removeChild(modal);
});
}
function downloadSingleImage(image) {
if (!image.processed) return;
const a = document.createElement('a');
a.href = image.processed.data;
a.download = `upscaled_${image.name.split('.')[0]}.jpg`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
showStatus(`Downloaded upscaled version of ${image.name}`, 'success');
}
function exportResults() {
if (processedImages.length === 0) return;
// Prepare data for export
const exportData = processedImages.map(img => ({
id: img.id,
name: img.name,
originalWidth: img.width,
originalHeight: img.height,
originalBase64: img.original,
processedWidth: img.processed.width,
processedHeight: img.processed.height,
processedBase64: img.processed.data,
scaleFactor: img.processed.scale,
processingOptions: img.processed.options,
timestamp: new Date().toISOString()
}));
// Create JSON file
const json = JSON.stringify(exportData, null, 2);
const blob = new Blob([json], { type: 'application/json' });
const url = URL.createObjectURL(blob);
// Create download link
const a = document.createElement('a');
a.href = url;
a.download = `image_upscale_results_${new Date().toISOString().slice(0, 10)}.json`;
document.body.appendChild(a);
a.click();
// Clean up
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 100);
showStatus(`Exported ${processedImages.length} image results`, 'success');
}
function showStatus(message, type) {
statusMessage.classList.remove('hidden');
statusMessage.textContent = message;
// Set color based on type
const colors = {
success: 'bg-green-100 text-green-800',
warning: 'bg-yellow-100 text-yellow-800',
error: 'bg-red-100 text-red-800',
info: 'bg-blue-100 text-blue-800'
};
// Reset classes
statusMessage.className = 'mb-6 p-4 rounded-lg';
statusMessage.classList.add(colors[type] || colors.info);
// Auto-hide after 5 seconds
setTimeout(() => {
statusMessage.classList.add('hidden');
}, 5000);
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Svngoku/image-upscaler-ui" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |