File size: 13,394 Bytes
b0bcfd5 | 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 | {% extends "base.html" %}
{% block title %}Upload Scan β ICH Screening{% endblock %}
{% block content %}
<section class="breadcrumb">
<a href="{{ url_for('home') }}">Home</a>
<span class="sep">/</span>
<span>Upload Scans</span>
</section>
<section class="upload-hero">
<h1>Upload DICOM Scans</h1>
<p>
Upload one or many CT brain scans for AI-powered hemorrhage screening.
A single exam may contain hundreds of slices β all modes below handle
that seamlessly.
</p>
</section>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="flash-messages">
{% for category, message in messages %}
<div class="flash flash-{{ category }}">{{ message }}</div>
{% endfor %}
</div>
{% endif %}
{% endwith %}
<!-- ββ Tab navigation ββββββββββββββββββββββββββββββββββββββββββββββββ -->
<div class="upload-tabs" role="tablist">
<button class="upload-tab active" data-tab="single" role="tab">Single File</button>
<button class="upload-tab" data-tab="multi" role="tab">Multi-File / ZIP</button>
{% if local_mode %}
<button class="upload-tab" data-tab="dirscan" role="tab">Scan Directory</button>
{% endif %}
</div>
<!-- ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
<!-- TAB 1 β Single .dcm file -->
<!-- ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
<section class="panel upload-panel tab-panel active" id="tab-single">
<form method="post" action="{{ url_for('analyze') }}"
enctype="multipart/form-data" id="singleForm">
<div class="dropzone" id="dropzoneSingle">
<svg width="56" height="56" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="1.5"
stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
<polyline points="17 8 12 3 7 8" />
<line x1="12" y1="3" x2="12" y2="15" />
</svg>
<p class="dropzone-text">Drag & drop a .dcm file here</p>
<p class="muted small">or click to browse</p>
<input type="file" name="file" id="singleInput" accept=".dcm" hidden />
</div>
<div class="file-info" id="singleInfo" style="display: none">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
<polyline points="14 2 14 8 20 8" />
</svg>
<span id="singleFileName"></span>
<button type="button" class="btn btn-sm btn-ghost js-clear-single">Remove</button>
</div>
<button type="submit" class="btn btn-primary" id="singleSubmit" disabled>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2">
<path d="M22 12h-4l-3 9L9 3l-3 9H2" />
</svg>
Analyze Scan
</button>
</form>
<div class="loading-overlay" id="singleOverlay" style="display: none">
<div class="spinner"></div>
<p>Running AI analysis…</p>
<p class="muted small">This may take a moment on first run while the model loads.</p>
</div>
</section>
<!-- ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
<!-- TAB 2 β Multi-file / ZIP upload -->
<!-- ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
<section class="panel upload-panel tab-panel" id="tab-multi">
<form method="post" action="{{ url_for('analyze') }}"
enctype="multipart/form-data" id="multiForm">
<div class="dropzone" id="dropzoneMulti">
<svg width="56" height="56" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="1.5"
stroke-linecap="round" stroke-linejoin="round">
<rect x="2" y="7" width="20" height="14" rx="2" />
<path d="M16 7V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2" />
</svg>
<p class="dropzone-text">Drag & drop .dcm files or a .zip archive</p>
<p class="muted small">Select multiple files, or a single .zip containing DICOM slices</p>
<input type="file" name="file" id="multiInput"
accept=".dcm,.zip" multiple hidden />
</div>
<div class="file-info" id="multiInfo" style="display: none">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2">
<rect x="2" y="7" width="20" height="14" rx="2" />
<path d="M16 7V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2" />
</svg>
<span id="multiFileName"></span>
<button type="button" class="btn btn-sm btn-ghost js-clear-multi">Remove all</button>
</div>
<button type="submit" class="btn btn-primary" id="multiSubmit" disabled>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2">
<path d="M22 12h-4l-3 9L9 3l-3 9H2" />
</svg>
Analyze Batch
</button>
</form>
<div class="loading-overlay" id="multiOverlay" style="display: none">
<div class="spinner"></div>
<p>Uploading files…</p>
<p class="muted small">Large batches may take a moment to upload.</p>
</div>
</section>
<!-- ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
<!-- TAB 3 β Directory scan (local mode only) -->
<!-- ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ -->
{% if local_mode %}
<section class="panel upload-panel tab-panel" id="tab-dirscan">
<form method="post" action="{{ url_for('analyze_directory') }}" id="dirForm">
<label class="dir-label" for="dirPath">
Server-side directory containing .dcm files
</label>
<div class="dir-input-row">
<input type="text" name="dir_path" id="dirPath" class="input"
placeholder="D:\scans\patient_001"
spellcheck="false" autocomplete="off" />
<button type="submit" class="btn btn-primary" id="dirSubmit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8" />
<line x1="21" y1="21" x2="16.65" y2="16.65" />
</svg>
Scan & Analyze
</button>
</div>
<p class="muted small" style="margin-top: 8px">
The server will recursively find all <code>.dcm</code> files in this
directory and its sub-folders, then run inference on each.
This option is only available when running locally.
</p>
</form>
</section>
{% endif %}
<!-- ββ How it works ββββββββββββββββββββββββββββββββββββββββββββββββββ -->
<section class="panel" style="margin-top: 16px">
<h3>How It Works</h3>
<div class="steps-grid">
<div class="step">
<div class="step-num">1</div>
<div class="step-text">
<strong>Upload</strong>
<p class="muted small">Select DICOM files, a ZIP, or enter a directory path</p>
</div>
</div>
<div class="step">
<div class="step-num">2</div>
<div class="step-text">
<strong>Process</strong>
<p class="muted small">CT windowing & preprocessing on each slice</p>
</div>
</div>
<div class="step">
<div class="step-num">3</div>
<div class="step-text">
<strong>Analyze</strong>
<p class="muted small">EfficientNet-B0 model with calibrated scoring</p>
</div>
</div>
<div class="step">
<div class="step-num">4</div>
<div class="step-text">
<strong>Report</strong>
<p class="muted small">Grad-CAM visualization & clinical report per slice</p>
</div>
</div>
</div>
</section>
{% endblock %}
{% block scripts %}
<script>
(function () {
/* ββ Tab switching ββββββββββββββββββββββββββββββββββββββββββββββββββ */
var tabs = document.querySelectorAll(".upload-tab");
var panels = document.querySelectorAll(".tab-panel");
tabs.forEach(function (tab) {
tab.addEventListener("click", function () {
tabs.forEach(function (t) { t.classList.remove("active"); });
panels.forEach(function (p) { p.classList.remove("active"); });
tab.classList.add("active");
var target = document.getElementById("tab-" + tab.dataset.tab);
if (target) target.classList.add("active");
});
});
/* ββ Helper: generic dropzone wiring βββββββββββββββββββββββββββββββ */
function wireDropzone(opts) {
var zone = document.getElementById(opts.zoneId);
var input = document.getElementById(opts.inputId);
var info = document.getElementById(opts.infoId);
var label = document.getElementById(opts.labelId);
var clear = document.querySelector(opts.clearSel);
var submit = document.getElementById(opts.submitId);
var form = document.getElementById(opts.formId);
var overlay = document.getElementById(opts.overlayId);
if (!zone || !input) return;
function showFiles(files) {
var validFiles = [];
for (var i = 0; i < files.length; i++) {
var name = files[i].name.toLowerCase();
if (name.endsWith(".dcm") || name.endsWith(".zip")) {
validFiles.push(files[i]);
}
}
if (!validFiles.length) return;
if (opts.multi) {
var totalSizeMB = 0;
for (var j = 0; j < validFiles.length; j++) {
totalSizeMB += validFiles[j].size / (1024 * 1024);
}
label.textContent = validFiles.length + " file" +
(validFiles.length > 1 ? "s" : "") +
" (" + totalSizeMB.toFixed(1) + " MB)";
} else {
label.textContent = validFiles[0].name;
}
info.style.display = "flex";
zone.style.display = "none";
submit.disabled = false;
}
function reset() {
input.value = "";
info.style.display = "none";
zone.style.display = "flex";
submit.disabled = true;
}
zone.addEventListener("click", function () { input.click(); });
zone.addEventListener("dragover", function (e) {
e.preventDefault();
zone.classList.add("dragover");
});
zone.addEventListener("dragleave", function () {
zone.classList.remove("dragover");
});
zone.addEventListener("drop", function (e) {
e.preventDefault();
zone.classList.remove("dragover");
if (e.dataTransfer.files.length) {
input.files = e.dataTransfer.files;
showFiles(e.dataTransfer.files);
}
});
input.addEventListener("change", function () {
if (input.files.length) showFiles(input.files);
});
if (clear) clear.addEventListener("click", reset);
if (form && overlay) {
form.addEventListener("submit", function () {
overlay.style.display = "flex";
submit.disabled = true;
});
}
}
/* ββ Wire single-file dropzone βββββββββββββββββββββββββββββββββββββ */
wireDropzone({
zoneId: "dropzoneSingle",
inputId: "singleInput",
infoId: "singleInfo",
labelId: "singleFileName",
clearSel: ".js-clear-single",
submitId: "singleSubmit",
formId: "singleForm",
overlayId: "singleOverlay",
multi: false,
});
/* ββ Wire multi-file dropzone ββββββββββββββββββββββββββββββββββββββ */
wireDropzone({
zoneId: "dropzoneMulti",
inputId: "multiInput",
infoId: "multiInfo",
labelId: "multiFileName",
clearSel: ".js-clear-multi",
submitId: "multiSubmit",
formId: "multiForm",
overlayId: "multiOverlay",
multi: true,
});
/* ββ Directory scan: disable submit when input is empty ββββββββββββ */
var dirInput = document.getElementById("dirPath");
var dirSubmit = document.getElementById("dirSubmit");
if (dirInput && dirSubmit) {
function checkDir() { dirSubmit.disabled = !dirInput.value.trim(); }
dirInput.addEventListener("input", checkDir);
checkDir();
}
})();
</script>
{% endblock %}
|