Spaces:
Running
Running
File size: 10,460 Bytes
c001f24 | 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 | {% extends "base.html" %}
{% block title %}Upload Images{% endblock %}
{% block head %}
<!-- Mobile viewport optimization -->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1, viewport-fit=cover">
<style>
:root {
--app-bg: #181a1c;
--card-bg: #212529;
--border-color: #495057;
--primary-color: #0d6efd;
--primary-bg-subtle: rgba(13, 110, 253, 0.1);
}
body {
background-color: var(--app-bg);
color: #e9ecef;
}
/* Layout wrapper */
.upload-wrapper {
min-height: calc(100vh - 56px);
min-height: calc(100dvh - 56px);
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
padding-bottom: env(safe-area-inset-bottom);
}
.main-card {
background-color: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 16px;
box-shadow: 0 4px 24px rgba(0,0,0,0.4);
width: 100%;
max-width: 600px;
overflow: hidden;
}
/* Touch-friendly Drop Zone */
.file-drop-area {
position: relative;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 100%;
min-height: 200px; /* Large target area */
padding: 30px;
border: 2px dashed var(--border-color);
border-radius: 12px;
transition: all 0.2s ease;
background: rgba(255,255,255,0.02);
cursor: pointer;
}
.file-drop-area:active, .file-drop-area.drag-over {
border-color: var(--primary-color);
background: var(--primary-bg-subtle);
transform: scale(0.99);
}
.file-drop-area.has-files {
border-color: #198754;
border-style: solid;
background: rgba(25, 135, 84, 0.1);
}
/* The invisible input covers the whole area */
.file-input {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
opacity: 0;
cursor: pointer;
z-index: 10;
}
/* Icon styling */
.upload-icon {
font-size: 3rem;
color: #adb5bd;
margin-bottom: 1rem;
transition: color 0.2s;
}
.file-drop-area.has-files .upload-icon {
color: #198754;
}
.file-msg {
font-size: 1.1rem;
font-weight: 500;
color: #dee2e6;
text-align: center;
margin-bottom: 0.5rem;
}
.file-hint {
font-size: 0.85rem;
color: #adb5bd;
}
/* Buttons */
.btn-action {
min-height: 54px;
font-size: 1.1rem;
font-weight: 600;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
transition: transform 0.1s;
}
.btn-action:active {
transform: scale(0.98);
}
/* Animations */
.fade-in-up { animation: fadeInUp 0.4s ease-out forwards; }
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
{% endblock %}
{% block content %}
<div class="upload-wrapper">
<div class="main-card fade-in-up">
<!-- Header -->
<div class="p-4 border-bottom border-secondary" style="border-color: #495057 !important;">
<div class="text-center">
<h1 class="h4 mb-1">Upload Images</h1>
<p class="text-secondary small mb-0">Select pages or screenshots to analyze</p>
</div>
</div>
<div class="card-body p-4">
<!-- Remote Camera Component -->
{% include 'camera_receiver_component.html' %}
<form id="upload-form">
<!-- Large Drop Zone -->
<div class="mb-4">
<div class="d-flex justify-content-between align-items-center mb-2">
<label class="form-label mb-0">Files</label>
<button type="button" class="btn btn-sm btn-outline-info" onclick="toggleCameraReceiver()">
<i class="bi bi-camera-video me-1"></i> Use Remote Camera
</button>
</div>
<div class="file-drop-area" id="drop-zone">
<i class="bi bi-images upload-icon" id="drop-icon"></i>
<span class="file-msg" id="file-label-main">Tap to select images</span>
<span class="file-hint" id="file-label-sub">Support for PNG, JPG, JPEG</span>
<!-- Invisible Input -->
<input type="file" class="file-input" id="images-upload" name="images" accept="image/*" multiple required>
</div>
</div>
<!-- Action Button -->
<button type="submit" class="btn btn-primary w-100 btn-action shadow" id="submitBtn">
<span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
<span class="btn-text">Start Processing</span>
<i class="bi bi-arrow-right-circle btn-icon"></i>
</button>
</form>
<div id="status" class="mt-3"></div>
<!-- Back Link -->
<div class="mt-4 text-center">
<a href="/" class="text-decoration-none text-secondary d-inline-flex align-items-center py-2 px-3">
<i class="bi bi-arrow-left me-2"></i> Back to PDF Upload
</a>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
// UX Elements
const dropZone = document.getElementById('drop-zone');
const fileInput = document.getElementById('images-upload');
const mainLabel = document.getElementById('file-label-main');
const subLabel = document.getElementById('file-label-sub');
const icon = document.getElementById('drop-icon');
const statusDiv = document.getElementById('status');
// Handle File Selection (Visual Feedback)
fileInput.addEventListener('change', function() {
const count = this.files ? this.files.length : 0;
if (count > 0) {
dropZone.classList.add('has-files');
icon.className = 'bi bi-check-circle-fill upload-icon';
if (count === 1) {
mainLabel.textContent = this.files[0].name;
subLabel.textContent = "1 image selected";
} else {
mainLabel.textContent = `${count} Images Selected`;
subLabel.textContent = "Ready to upload";
}
} else {
resetUI();
}
});
function resetUI() {
dropZone.classList.remove('has-files');
icon.className = 'bi bi-images upload-icon';
mainLabel.textContent = "Tap to select images";
subLabel.textContent = "Support for PNG, JPG, JPEG";
fileInput.value = ''; // Clear value
}
// Drag & Drop Visuals
['dragenter', 'dragover'].forEach(eventName => {
dropZone.addEventListener(eventName, (e) => {
e.preventDefault(); e.stopPropagation();
dropZone.classList.add('drag-over');
}, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropZone.addEventListener(eventName, (e) => {
e.preventDefault(); e.stopPropagation();
dropZone.classList.remove('drag-over');
}, false);
});
function toggleCameraReceiver() {
const component = document.getElementById('camera-receiver-component');
if (component.style.display === 'none') {
component.style.display = 'block';
if (typeof initCameraReceiver === 'function') {
initCameraReceiver();
}
} else {
component.style.display = 'none';
}
}
// Form Submission
document.getElementById('upload-form').addEventListener('submit', async function(e) {
e.preventDefault();
const btn = document.getElementById('submitBtn');
const spinner = btn.querySelector('.spinner-border');
const btnText = btn.querySelector('.btn-text');
const btnIcon = btn.querySelector('.btn-icon');
// Check if files selected
if (!fileInput.files || fileInput.files.length === 0) {
statusDiv.innerHTML = `<div class="alert alert-warning d-flex align-items-center"><i class="bi bi-exclamation-triangle me-2"></i> Please select at least one image.</div>`;
return;
}
// Loading State
btn.disabled = true;
spinner.classList.remove('d-none');
btnIcon.classList.add('d-none');
btnText.textContent = "Uploading...";
statusDiv.innerHTML = '';
const formData = new FormData(e.target);
try {
const response = await fetch('/upload_images', {
method: 'POST',
body: formData
});
const result = await response.json();
if (response.ok) {
// Success State
btn.className = "btn btn-success w-100 btn-action shadow";
btnText.textContent = "Success!";
statusDiv.innerHTML = `<div class="alert alert-success border-0 bg-success bg-opacity-10 text-success"><i class="bi bi-check-lg me-2"></i> Uploaded ${result.files.length} images. Redirecting...</div>`;
// Redirect
setTimeout(() => {
window.location.href = `/cropv2/${result.session_id}/0`;
}, 800);
} else {
throw new Error(result.error || 'Upload failed');
}
} catch (error) {
// Error State
statusDiv.innerHTML = `<div class="alert alert-danger border-0 bg-danger bg-opacity-10 text-danger"><i class="bi bi-x-circle me-2"></i> Error: ${error.message}</div>`;
btn.disabled = false;
spinner.classList.add('d-none');
btnIcon.classList.remove('d-none');
btnText.textContent = "Try Again";
}
});
</script>
{% endblock %}
|