devluke's picture
Upload index.html
c6f3046 verified
Raw History Blame
43.8 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Undertone Classification Dashboard</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet"> <style> :root { --primary: #1d4ed8; --primary-light: #3b82f6; --primary-pale: #eff6ff; --dark-text: #0f172a; --muted-text: #64748b; --border: rgba(29, 78, 216, 0.15); --card-bg: #ffffff; --cool-color: #818cf8; --neutral-color: #fb923c; --warm-color: #f59e0b; } body { background: linear-gradient(160deg, #eff6ff 0%, #f8fafc 60%, #e0f2fe 100%); color: var(--dark-text); font-family: 'Inter', sans-serif; min-height: 100vh; } /* ── Cards ── */ .glass-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 4px 24px rgba(29, 78, 216, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04); } /* ── Buttons ── */ .btn-gradient-primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff; border: none; border-radius: 12px; transition: .25s; } .btn-gradient-success { background: linear-gradient(135deg, #0ea5e9, #0284c7); color: #fff; border: none; border-radius: 12px; transition: .25s; } .btn-gradient-primary:hover, .btn-gradient-success:hover { transform: translateY(-2px); color: #fff; box-shadow: 0 8px 24px rgba(29, 78, 216, .3); } /* ── Video ── */ #video { border-radius: 14px; width: 100%; background: #000; border: 2px solid var(--border); } /* ── Nav tabs (pill style) ── */ .nav-tabs { border-bottom: none; background: #f1f5f9; border-radius: 12px; padding: 4px; gap: 4px; display: flex; } .nav-tabs .nav-link { color: var(--muted-text); border: none; font-weight: 600; padding: 9px 18px; border-radius: 9px; flex: 1; text-align: center; transition: .2s; } .nav-tabs .nav-link.active { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(29, 78, 216, .12); } .nav-tabs .nav-link:not(.active):hover { color: var(--primary); background: rgba(255, 255, 255, .5); } /* ── Drag-drop zone ── */ .drop-zone { border: 2px dashed #cbd5e1; border-radius: 16px; padding: 28px 16px; text-align: center; cursor: pointer; transition: .2s; background: #f8fafc; position: relative; } .drop-zone:hover, .drop-zone.drag-over { border-color: var(--primary-light); background: var(--primary-pale); } .drop-zone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; } .drop-zone-icon { font-size: 2rem; color: #93c5fd; margin-bottom: 8px; } .drop-zone-text { font-size: .82rem; font-weight: 600; color: var(--muted-text); } .drop-zone-sub { font-size: .72rem; color: #94a3b8; } /* ── File preview ── */ #filePreviewWrap { display: none; margin-top: 12px; position: relative; border-radius: 12px; overflow: hidden; } #filePreview { width: 100%; max-height: 180px; object-fit: cover; border-radius: 12px; display: block; } .preview-remove { position: absolute; top: 8px; right: 8px; background: rgba(0, 0, 0, .55); color: #fff; border: none; border-radius: 50%; width: 28px; height: 28px; font-size: .75rem; cursor: pointer; display: flex; align-items: center; justify-content: center; } .preview-name { font-size: .72rem; color: var(--muted-text); margin-top: 6px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* ── Form control ── */ .form-control { background: #f8fafc; border: 1px solid #cbd5e1; color: var(--dark-text); } .form-control:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(59, 130, 246, .15); } /* ── Section headings ── */ h1, h5 { color: var(--dark-text); } .text-primary { color: var(--primary) !important; } .text-secondary { color: var(--muted-text) !important; } .text-muted { color: #94a3b8 !important; } /* ── Spinner ── */ .loading-overlay { display: flex; flex-direction: column; align-items: center; justify-content: center; } .spinner-border { width: 3rem; height: 3rem; color: var(--primary); } /* ── Undertone badge ── */ .undertone-badge { display: inline-flex; align-items: center; gap: 10px; padding: 10px 22px; border-radius: 50px; font-size: 1.4rem; font-weight: 800; letter-spacing: .03em; animation: fadeUp .5s ease both; } .badge-cool { background: linear-gradient(135deg, #312e81, #4338ca); color: #c7d2fe; box-shadow: 0 0 28px rgba(99, 102, 241, .3); } .badge-neutral { background: linear-gradient(135deg, #7c2d12, #c2410c); color: #fed7aa; box-shadow: 0 0 28px rgba(251, 146, 60, .3); } .badge-warm { background: linear-gradient(135deg, #78350f, #d97706); color: #fef3c7; box-shadow: 0 0 28px rgba(245, 158, 11, .3); } .swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .4); } /* ── Image comparison panel ── */ .img-pair { display: flex; gap: 16px; align-items: flex-start; } .img-slot { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; } .img-slot-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-text); } .img-thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 14px; border: 3px solid #fff; box-shadow: 0 0 0 3px var(--ring-color, #3b82f6), 0 4px 16px rgba(59, 130, 246, .2); transition: box-shadow .4s; } .crop-preview { width: 110px; height: 110px; border-radius: 50%; object-fit: cover; border: 4px solid #fff; box-shadow: 0 0 0 4px var(--ring-color, #3b82f6), 0 4px 20px rgba(59, 130, 246, .25); transition: box-shadow .4s; } /* ── Agreement pill ── */ .agree-pill { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 700; padding: 4px 14px; border-radius: 50px; text-transform: uppercase; letter-spacing: .05em; } .agree-yes { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; } .agree-no { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; } /* ── Radial ring ── */ .ring-wrap { position: relative; width: 80px; height: 80px; flex-shrink: 0; } .ring-wrap svg { transform: rotate(-90deg); } .ring-bg { fill: none; stroke: #e2e8f0; stroke-width: 7; } .ring-fill { fill: none; stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset 1s ease; } .ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; font-size: .85rem; color: var(--dark-text); } .ring-sub { font-size: .6rem; font-weight: 500; color: var(--muted-text); margin-top: 1px; } /* ── Model score blocks ── */ .model-block { border-radius: 16px; padding: 16px 18px; background: #f8fafc; border: 1px solid #e2e8f0; } .model-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--primary); margin-bottom: 12px; } .bar-track { height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin-top: 5px; } .bar-fill { height: 100%; border-radius: 4px; transition: width 1s ease; } .bar-cool { background: linear-gradient(90deg, #4f46e5, #818cf8); } .bar-neutral { background: linear-gradient(90deg, #c2410c, #fb923c); } .bar-warm { background: linear-gradient(90deg, #b45309, #f59e0b); } /* ── Score label text ── */ .score-row span:first-child { color: var(--dark-text); } .score-row span:last-child { color: var(--primary); } /* ── Palette ── */ .palette-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--primary); margin-bottom: 10px; } .palette-chip { width: 36px; height: 36px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .1); cursor: default; transition: transform .2s; position: relative; } .palette-chip:hover { transform: scale(1.2); z-index: 2; } .palette-chip[title]:hover::after { content: attr(title); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--dark-text); color: #fff; font-size: .65rem; white-space: nowrap; padding: 3px 8px; border-radius: 6px; pointer-events: none; } /* ── Placeholder steps ── */ .step-list { list-style: none; padding: 0; margin: 0; text-align: left; } .step-list li { display: flex; align-items: center; gap: 10px; font-size: .8rem; color: var(--muted-text); padding: 6px 0; } .step-num { width: 22px; height: 22px; border-radius: 50%; background: var(--primary-pale); color: var(--primary); font-size: .7rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; } /* ── Divider label ── */ .section-divider { display: flex; align-items: center; gap: 10px; margin: 12px 0; } .section-divider span { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-text); white-space: nowrap; } .section-divider::before, .section-divider::after { content: ''; flex: 1; height: 1px; background: #e2e8f0; } /* ── Score grid ── */ .scores-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } /* ── Lang toggle ── */ .lang-toggle { display: inline-flex; border: 2px solid var(--border); border-radius: 50px; overflow: hidden; gap: 0; } .lang-btn { background: none; border: none; padding: 5px 14px; font-size: .72rem; font-weight: 700; color: var(--muted-text); cursor: pointer; transition: .18s; letter-spacing: .04em; } .lang-btn.active { background: var(--primary); color: #fff; } .lang-btn:not(.active):hover { background: var(--primary-pale); color: var(--primary); } /* ── Animations ── */ @keyframes fadeUp { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: none } } .result-anim { animation: fadeUp .45s ease both; } .result-anim:nth-child(2) { animation-delay: .08s } .result-anim:nth-child(3) { animation-delay: .16s } .result-anim:nth-child(4) { animation-delay: .24s } </style> </head> <body> <div class="container py-5"> <header class="text-center mb-5" style="position:relative"> <div style="position:absolute;right:0;top:0;"> <div class="lang-toggle"> <button class="lang-btn" id="btnEN" onclick="setLang('en')">EN</button> <button class="lang-btn active" id="btnID" onclick="setLang('id')">ID</button> </div> </div> <h1 class="fw-bold mb-2"><i class="fas fa-microchip me-2 text-primary"></i><span data-i18n="title">Undertone Classification Dashboard</span></h1> <p class="text-secondary" data-i18n="subtitle">Artificial Intelligence System Powered by ResNet50 &amp; MobileNetV2</p> </header> <div class="row g-4"> <div class="col-lg-6"> <div class="glass-card p-4 h-100"> <h5 class="mb-1 fw-bold"><i class="fas fa-camera-retro me-2 text-primary"></i><span data-i18n="inputTitle">Data Input Source</span></h5> <p class="text-muted mb-3" style="font-size:.78rem" data-i18n="inputSubtitle">Upload a portrait or use your live camera</p> <ul class="nav nav-tabs mb-4" id="inputTab" role="tablist"> <li class="nav-item" role="presentation"> <button class="nav-link active" id="gallery-tab" data-bs-toggle="tab" data-bs-target="#galleryTab" type="button" role="tab"> <i class="fas fa-image me-2"></i><span data-i18n="tabUpload">Upload Image</span> </button> </li> <li class="nav-item" role="presentation"> <button class="nav-link" id="camera-tab" data-bs-toggle="tab" data-bs-target="#cameraTab" type="button" role="tab"> <i class="fas fa-video me-2"></i><span data-i18n="tabCamera">Live Camera</span> </button> </li> </ul> <div class="tab-content" id="inputTabContent"> <div class="tab-pane fade show active" id="galleryTab" role="tabpanel"> <div class="drop-zone mb-1" id="dropZone"> <input type="file" id="fileInput" accept="image/*" onchange="onFileChange(event)"> <div class="drop-zone-icon"><i class="fas fa-cloud-upload-alt"></i></div> <div class="drop-zone-text" data-i18n="dropText">Drag &amp; drop or click to browse </div> <div class="drop-zone-sub mt-1" data-i18n="dropSub">JPG, PNG, WEBP &bull; Portrait recommended</div> </div> <div id="filePreviewWrap"> <img id="filePreview" src="" alt="Preview"> <button class="preview-remove" onclick="clearFile()" title="Remove"><i class="fas fa-times"></i></button> <div id="previewName" class="preview-name"></div> </div> <button id="btnGallery" onclick="uploadFile()" class="btn btn-gradient-primary w-100 py-3 fw-bold mt-3"> <i class="fas fa-search me-2"></i><span data-i18n="btnAnalyze">Analyze Image</span> </button> </div> <div class="tab-pane fade" id="cameraTab" role="tabpanel"> <div class="ratio ratio-4x3 mb-3 overflow-hidden rounded"> <video id="video" autoplay playsinline></video> </div> <button id="btnCamera" onclick="captureCamera()" class="btn btn-gradient-success w-100 py-3 fw-bold"> <i class="fas fa-bolt me-2"></i><span data-i18n="btnCapture">CAPTURE &amp; PROCESS</span> </button> <canvas id="canvas" style="display:none;"></canvas> </div> </div> </div> </div> <div class="col-lg-6" id="output-wrapper"> <div id="loadingSpinner" class="glass-card p-5 h-100 d-none loading-overlay"> <div class="spinner-border mb-3" role="status"> <span class="visually-hidden">Loading...</span> </div> <h5 class="text-primary" data-i18n="loadingTitle">Processing Image...</h5> <p class="text-muted small" data-i18n="loadingSub">Running Deep Learning Inference</p> </div> <div class="glass-card p-4 d-none" id="resultPanel"> <!-- β‘  Hero: image comparison + badge --> <div class="mb-4 result-anim"> <!-- Image pair --> <div class="img-pair mb-3"> <div class="img-slot"> <span class="img-slot-label"><i class="fas fa-image me-1"></i>Original</span> <img id="originalImg" class="img-thumb" src="" alt="Original image"> </div> <div class="img-slot"> <span class="img-slot-label"><i class="fas fa-crop-alt me-1"></i>ROI Crop</span> <img id="cropImg" class="img-thumb" src="" alt="Face ROI crop"> </div> </div> <!-- Badge row --> <div class="d-flex flex-column align-items-start gap-2"> <p class="text-secondary small mb-0" style="font-size:.72rem;letter-spacing:.08em;text-transform:uppercase" data-i18n="undertoneLabel">Undertone Detected</p> <div id="resBadge" class="undertone-badge mb-1">β€”</div> <div id="agreepill" class="agree-pill agree-yes"> <i class="fas fa-check-circle"></i> <span id="agreeText">Models agree</span> </div> </div> </div> <!-- β‘‘ Model scores side by side --> <div class="section-divider result-anim"><span><i class="fas fa-chart-bar me-1"></i><span data-i18n="modelConfidence">Model Confidence</span></span></div> <div class="scores-grid mb-3 result-anim"> <div class="model-block"> <div class="model-title"><i class="fas fa-brain me-1"></i>ResNet50</div> <div id="resnetScores"></div> </div> <div class="model-block"> <div class="model-title"><i class="fas fa-microchip me-1"></i>MobileNetV2</div> <div id="mobilenetScores"></div> </div> </div> <!-- β‘’ Palette recommendation --> <div class="section-divider result-anim"><span><i class="fas fa-palette me-1"></i><span data-i18n="colourPalette">Colour Palette</span></span></div> <div class="model-block result-anim" id="paletteBlock"> <div id="paletteChips" class="d-flex flex-wrap gap-2"></div> <p id="paletteDesc" class="text-secondary mt-2 mb-0" style="font-size:.78rem"></p> </div> </div> <div id="placeholder" class="glass-card p-4 h-100 d-flex align-items-center justify-content-center"> <div style="max-width:280px;text-align:center"> <div style="width:64px;height:64px;border-radius:50%;background:var(--primary-pale);display:flex;align-items:center;justify-content:center;margin:0 auto 16px;"> <i class="fas fa-face-smile fa-xl text-primary"></i> </div> <h5 class="fw-bold mb-1" style="font-size:1rem" data-i18n="phTitle">Ready for Analysis</h5> <p class="text-muted mb-4" style="font-size:.78rem" data-i18n="phDesc">Upload a clear portrait photo or use your camera to detect your skin undertone.</p> <ul class="step-list"> <li><span class="step-num">1</span><span data-i18n="step1">Choose Upload Image or Live Camera tab</span></li> <li><span class="step-num">2</span><span data-i18n="step2">Select or capture a front-facing portrait</span></li> <li><span class="step-num">3</span><span data-i18n="step3">Click Analyze β€” AI detects your undertone</span></li> </ul> </div> </div> </div> </div> </div> <footer class="text-center py-4 mt-4 text-muted" style="font-size: 0.85rem;"> &copy; 2026 Afina Putri Dzulqiyana &amp; Dr. Herlawati, S.Si., M.M., M.Kom. All rights reserved. </footer> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> const video = document.getElementById('video'); const canvas = document.getElementById('canvas'); // ── i18n ───────────────────────────────────────────────────────────── const TRANSLATIONS = { en: { title: 'Undertone Classification Dashboard', subtitle: 'Artificial Intelligence System Powered by ResNet50 & MobileNetV2', inputTitle: 'Data Input Source', inputSubtitle: 'Upload a portrait or use your live camera', tabUpload: 'Upload Image', tabCamera: 'Live Camera', dropText: 'Drag & drop or click to browse', dropSub: 'JPG, PNG, WEBP β€’ Portrait recommended', btnAnalyze: 'Analyze Image', btnCapture: 'Capture & Analyze', loadingTitle: 'Processing Image...', loadingSub: 'Running Deep Learning Inference', undertoneLabel: 'Undertone Detected', modelConfidence: 'Model Confidence', colourPalette: 'Colour Palette', phTitle: 'Ready for Analysis', phDesc: 'Upload a clear portrait photo or use your camera to detect your skin undertone.', step1: 'Choose Upload Image or Live Camera tab', step2: 'Select or capture a front-facing portrait', step3: 'Click Analyze β€” AI detects your undertone', agreeYes: 'Both models agree', agreeNo: (r, m) => `ResNet: ${r} Β· MobileNet: ${m}`, alertNoFile: 'Select an image first', alertServer: 'Server error', }, id: { title: 'Dashboard Klasifikasi Undertone', subtitle: 'Sistem Kecerdasan Buatan Berbasis ResNet50 & MobileNetV2', inputTitle: 'Sumber Data Input', inputSubtitle: 'Unggah foto wajah atau gunakan kamera langsung', tabUpload: 'Unggah Gambar', tabCamera: 'Kamera Langsung', dropText: 'Seret & lepas atau klik untuk memilih', dropSub: 'JPG, PNG, WEBP β€’ Disarankan foto wajah', btnAnalyze: 'Analisis Gambar', btnCapture: 'Tangkap & Analisis', loadingTitle: 'Memproses Gambar...', loadingSub: 'Menjalankan Inferensi Deep Learning', undertoneLabel: 'Undertone Terdeteksi', modelConfidence: 'Kepercayaan Model', colourPalette: 'Palet Warna', phTitle: 'Siap untuk Analisis', phDesc: 'Unggah foto wajah yang jelas atau gunakan kamera untuk mendeteksi undertone kulit Anda.', step1: 'Pilih tab Unggah Gambar atau Kamera Langsung', step2: 'Pilih atau ambil foto wajah menghadap ke depan', step3: 'Klik Analisis β€” AI mendeteksi undertone Anda', agreeYes: 'Kedua model setuju', agreeNo: (r, m) => `ResNet: ${r} Β· MobileNet: ${m}`, alertNoFile: 'Pilih gambar terlebih dahulu', alertServer: 'Kesalahan server', } }; let currentLang = 'id'; function setLang(lang) { currentLang = lang; const t = TRANSLATIONS[lang]; document.querySelectorAll('[data-i18n]').forEach(el => { const key = el.getAttribute('data-i18n'); if (t[key] && typeof t[key] === 'string') el.textContent = t[key]; }); document.getElementById('btnEN').classList.toggle('active', lang === 'en'); document.getElementById('btnID').classList.toggle('active', lang === 'id'); document.documentElement.lang = lang === 'id' ? 'id' : 'en'; const pDesc = document.getElementById('paletteDesc'); if (pDesc && pDesc.dataset.palette) { pDesc.textContent = PALETTES[pDesc.dataset.palette].desc[lang]; } } // ── Palette data per undertone ────────────────────────────────────── const PALETTES = { cool: { swatch: '#818cf8', ringColor: '#6366f1', label: 'Cool', colors: [ { hex: '#7c3aed', name: 'Violet' }, { hex: '#2563eb', name: 'Royal Blue' }, { hex: '#0e7490', name: 'Teal' }, { hex: '#be185d', name: 'Fuchsia' }, { hex: '#374151', name: 'Charcoal' }, { hex: '#e0e7ff', name: 'Lavender' }, { hex: '#f0fdf4', name: 'Mint White' }, { hex: '#c7d2fe', name: 'Periwinkle' }, ], desc: { en: 'Cool undertones suit jewel tones, icy blues, purples & true whites. Avoid yellow-based oranges.', id: 'Undertone cool (dingin) cocok dengan warna permata, biru es, ungu & putih bersih. Hindari warna oranye berbasis kuning.' } }, neutral: { swatch: '#fb923c', ringColor: '#f97316', label: 'Neutral', colors: [ { hex: '#92400e', name: 'Caramel' }, { hex: '#b45309', name: 'Amber' }, { hex: '#4f46e5', name: 'Indigo' }, { hex: '#065f46', name: 'Forest Green' }, { hex: '#be123c', name: 'Rose Red' }, { hex: '#d4a27f', name: 'Nude Beige' }, { hex: '#6b7280', name: 'Cool Grey' }, { hex: '#fef3c7', name: 'Cream' }, ], desc: { en: 'Neutral undertones are the most versatile β€” warm & cool tones both work. Earthy nudes and balanced jewels shine.', id: 'Undertone netral adalah yang paling serbaguna β€” warna hangat & dingin sama-sama cocok. Warna nude bumi dan permata seimbang terlihat bersinar.' } }, warm: { swatch: '#f59e0b', ringColor: '#d97706', label: 'Warm', colors: [ { hex: '#b45309', name: 'Golden Brown' }, { hex: '#c2410c', name: 'Burnt Orange' }, { hex: '#a16207', name: 'Mustard' }, { hex: '#166534', name: 'Olive Green' }, { hex: '#7c2d12', name: 'Terracotta' }, { hex: '#fde68a', name: 'Warm Yellow' }, { hex: '#fca5a5', name: 'Peach' }, { hex: '#f9a8d4', name: 'Coral Pink' }, ], desc: { en: 'Warm undertones glow in earthy oranges, golds, browns & warm greens. Avoid icy or ashy tones.', id: 'Undertone warm (hangat) bercahaya dalam warna oranye bumi, emas, cokelat & hijau hangat. Hindari warna es atau keabuan.' } } }; // ── Drag-drop ──────────────────────────────────────────────────────── const dropZone = document.getElementById('dropZone'); dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('drag-over'); }); dropZone.addEventListener('dragleave', () => dropZone.classList.remove('drag-over')); dropZone.addEventListener('drop', e => { e.preventDefault(); dropZone.classList.remove('drag-over'); if (e.dataTransfer.files[0]) { document.getElementById('fileInput').files = e.dataTransfer.files; onFileChange({ target: { files: e.dataTransfer.files } }); } }); function onFileChange(e) { const file = e.target.files[0]; if (!file) return; const wrap = document.getElementById('filePreviewWrap'); document.getElementById('filePreview').src = URL.createObjectURL(file); document.getElementById('previewName').textContent = file.name; wrap.style.display = 'block'; } function clearFile() { document.getElementById('fileInput').value = ''; document.getElementById('filePreviewWrap').style.display = 'none'; document.getElementById('filePreview').src = ''; } // ── Camera Init ───────────────────────────────────────────────────── document.getElementById('camera-tab').addEventListener('shown.bs.tab', () => { if (!video.srcObject) navigator.mediaDevices.getUserMedia({ video: true }).then(s => { video.srcObject = s; document.getElementById('camBadge').classList.remove('d-none'); }); }); document.getElementById('gallery-tab').addEventListener('shown.bs.tab', () => { if (video.srcObject) { video.srcObject.getTracks().forEach(t => t.stop()); video.srcObject = null; document.getElementById('camBadge').classList.add('d-none'); } }); // ── Loading toggle ────────────────────────────────────────────────── function toggleLoading(show) { const spinner = document.getElementById('loadingSpinner'); const placeholder = document.getElementById('placeholder'); const resultPanel = document.getElementById('resultPanel'); const btnGallery = document.getElementById('btnGallery'); const btnCamera = document.getElementById('btnCamera'); if (show) { spinner.classList.remove('d-none'); placeholder.classList.add('d-none'); resultPanel.classList.add('d-none'); btnGallery.disabled = btnCamera.disabled = true; } else { spinner.classList.add('d-none'); btnGallery.disabled = btnCamera.disabled = false; } } // ── Score bars ────────────────────────────────────────────────────── function createScoreUI(scores, containerId) { const container = document.getElementById(containerId); container.innerHTML = ''; Object.entries(scores).forEach(([label, score]) => { const pct = (score * 100).toFixed(1); const barClass = `bar-${label.toLowerCase()}`; container.innerHTML += ` <div class="mb-2"> <div class="d-flex justify-content-between align-items-center mb-1"> <span style="font-size:.8rem;font-weight:600;color:#334155">${label}</span> <span style="font-size:.78rem;font-weight:700;color:#1d4ed8">${pct}%</span> </div> <div class="bar-track"> <div class="bar-fill ${barClass}" style="width:0%" data-target="${pct}%"></div> </div> </div>`; }); // Animate bars after paint requestAnimationFrame(() => requestAnimationFrame(() => { container.querySelectorAll('.bar-fill').forEach(el => { el.style.width = el.dataset.target; }); })); } // ── Main result render ────────────────────────────────────────────── function handleResponse(data) { toggleLoading(false); const resLabel = data.results.resnet.label; // e.g. 'cool' const mobLabel = data.results.mobilenet.label; // e.g. 'warm' const agree = resLabel === mobLabel; const palette = PALETTES[resLabel] || PALETTES['neutral']; const displayLabel = palette.label; // Title-case: 'Cool' // Original image const originalImg = document.getElementById('originalImg'); originalImg.src = data.original_b64; originalImg.style.boxShadow = `0 0 0 3px ${palette.ringColor}55, 0 4px 16px rgba(0,0,0,.12)`; // Crop image + ring glow colour const cropImg = document.getElementById('cropImg'); cropImg.src = data.crop_b64; cropImg.style.setProperty('--ring-color', palette.ringColor); cropImg.style.boxShadow = `0 0 0 3px ${palette.ringColor}, 0 0 24px ${palette.ringColor}55`; // Badge const badge = document.getElementById('resBadge'); badge.className = `undertone-badge badge-${resLabel}`; badge.innerHTML = `<span class="swatch" style="background:${palette.swatch}"></span>${displayLabel}`; // Agreement pill const pill = document.getElementById('agreepill'); const agreeText = document.getElementById('agreeText'); if (agree) { pill.className = 'agree-pill agree-yes'; pill.querySelector('i').className = 'fas fa-check-circle'; agreeText.textContent = TRANSLATIONS[currentLang].agreeYes; } else { pill.className = 'agree-pill agree-no'; pill.querySelector('i').className = 'fas fa-exclamation-circle'; const mobDisplay = (PALETTES[mobLabel] || PALETTES['neutral']).label; agreeText.textContent = TRANSLATIONS[currentLang].agreeNo(displayLabel, mobDisplay); } // Score bars createScoreUI(data.results.resnet.scores, 'resnetScores'); createScoreUI(data.results.mobilenet.scores, 'mobilenetScores'); // Palette chips const chips = document.getElementById('paletteChips'); chips.innerHTML = palette.colors.map(c => `<div class="palette-chip" style="background:${c.hex}" title="${c.name}"></div>` ).join(''); const pDesc = document.getElementById('paletteDesc'); const paletteKey = PALETTES[resLabel] ? resLabel : 'neutral'; pDesc.dataset.palette = paletteKey; pDesc.textContent = palette.desc[currentLang]; document.getElementById('resultPanel').classList.remove('d-none'); } // ── Upload ────────────────────────────────────────────────────────── async function uploadFile() { const file = document.getElementById('fileInput').files[0]; if (!file) return alert(TRANSLATIONS[currentLang].alertNoFile); toggleLoading(true); const fd = new FormData(); fd.append('file', file); try { const res = await fetch('/predict', { method: 'POST', body: fd }); const data = await res.json(); if (res.ok) handleResponse(data); else { alert(data.error); toggleLoading(false); document.getElementById('placeholder').classList.remove('d-none'); } } catch { alert(TRANSLATIONS[currentLang].alertServer); toggleLoading(false); } } // ── Camera capture ────────────────────────────────────────────────── async function captureCamera() { canvas.width = video.videoWidth; canvas.height = video.videoHeight; canvas.getContext('2d').drawImage(video, 0, 0); toggleLoading(true); try { const res = await fetch('/predict', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ image: canvas.toDataURL('image/jpeg') }) }); const data = await res.json(); if (res.ok) handleResponse(data); else { alert(data.error); toggleLoading(false); document.getElementById('placeholder').classList.remove('d-none'); } } catch { alert(TRANSLATIONS[currentLang].alertServer); toggleLoading(false); } } // Set default language on load document.addEventListener('DOMContentLoaded', () => setLang('id')); </script> </body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Undertone Classification Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root {
--primary: #1d4ed8;
--primary-light: #3b82f6;
--primary-pale: #eff6ff;
--dark-text: #0f172a;
--muted-text: #64748b;
--border: rgba(29, 78, 216, 0.15);
--card-bg: #ffffff;
--cool-color: #818cf8;
--neutral-color: #fb923c;
--warm-color: #f59e0b;
}
body {
background: linear-gradient(160deg, #eff6ff 0%, #f8fafc 60%, #e0f2fe 100%);
color: var(--dark-text);
font-family: 'Inter', sans-serif;
min-height: 100vh;
}
/* ── Cards ── */
.glass-card {
background: var(--card-bg);
border: 1px solid var(--border);
border-radius: 24px;
box-shadow: 0 4px 24px rgba(29, 78, 216, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
}
/* ── Buttons ── */
.btn-gradient-primary {
background: linear-gradient(135deg, #2563eb, #1d4ed8);
color: #fff;
border: none;
border-radius: 12px;
transition: .25s;
}
.btn-gradient-success {
background: linear-gradient(135deg, #0ea5e9, #0284c7);
color: #fff;
border: none;
border-radius: 12px;
transition: .25s;
}
.btn-gradient-primary:hover,
.btn-gradient-success:hover {
transform: translateY(-2px);
color: #fff;
box-shadow: 0 8px 24px rgba(29, 78, 216, .3);
}
/* ── Video ── */
#video {
border-radius: 14px;
width: 100%;
background: #000;
border: 2px solid var(--border);
}
/* ── Nav tabs (pill style) ── */
.nav-tabs {
border-bottom: none;
background: #f1f5f9;
border-radius: 12px;
padding: 4px;
gap: 4px;
display: flex;
}
.nav-tabs .nav-link {
color: var(--muted-text);
border: none;
font-weight: 600;
padding: 9px 18px;
border-radius: 9px;
flex: 1;
text-align: center;
transition: .2s;
}
.nav-tabs .nav-link.active {
background: #fff;
color: var(--primary);
box-shadow: 0 2px 8px rgba(29, 78, 216, .12);
}
.nav-tabs .nav-link:not(.active):hover {