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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="ko" class="dark">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>SPAO AI λ£©λΆ μμ±κΈ°</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script>
|
| 9 |
+
tailwind.config = { darkMode: 'class', theme: { extend: { colors: { brand: { blue: '#3B82F6', hover: '#2563EB' } } } } }
|
| 10 |
+
</script>
|
| 11 |
+
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin />
|
| 12 |
+
<link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" />
|
| 13 |
+
<style>
|
| 14 |
+
* { font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
|
| 15 |
+
body { -webkit-font-smoothing: antialiased; background: #1a1a1a; color: #f9fafb; margin: 0; overflow: hidden; }
|
| 16 |
+
::-webkit-scrollbar { width: 6px; height: 6px; }
|
| 17 |
+
::-webkit-scrollbar-track { background: #1a1a1a; }
|
| 18 |
+
::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
|
| 19 |
+
::-webkit-scrollbar-thumb:hover { background: #4b5563; }
|
| 20 |
+
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
| 21 |
+
@keyframes shimmer { 0% { background-position: -600px 0; } 100% { background-position: 600px 0; } }
|
| 22 |
+
@keyframes pulseRing { 0% { transform: scale(0.85); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }
|
| 23 |
+
.animate-fadeIn { animation: fadeIn .25s ease-out; }
|
| 24 |
+
.shimmer { background: linear-gradient(90deg, #232323 0%, #2c2c2c 40%, #232323 80%); background-size: 600px 100%; animation: shimmer 1.6s linear infinite; }
|
| 25 |
+
.pulse-ring::before { content: ''; position: absolute; inset: -6px; border-radius: 9999px; border: 2px solid #3B82F6; animation: pulseRing 1.4s ease-out infinite; }
|
| 26 |
+
.ai-label-overlay { position: absolute; top: 12pt; right: 12pt; font-weight: 300; font-size: 10pt; color: #3c3c3c; pointer-events: none; z-index: 2; letter-spacing: -0.02em; }
|
| 27 |
+
.drop-active { border-color: #3B82F6 !important; background: rgba(59,130,246,.08) !important; }
|
| 28 |
+
textarea { resize: vertical; }
|
| 29 |
+
</style>
|
| 30 |
+
<script type="importmap">
|
| 31 |
+
{ "imports": {
|
| 32 |
+
"react": "https://esm.sh/react@19.1.0",
|
| 33 |
+
"react/": "https://esm.sh/react@19.1.0/",
|
| 34 |
+
"react-dom/": "https://esm.sh/react-dom@19.1.0/",
|
| 35 |
+
"lucide-react": "https://esm.sh/lucide-react@0.462.0?external=react"
|
| 36 |
+
} }
|
| 37 |
+
</script>
|
| 38 |
+
</head>
|
| 39 |
+
<body>
|
| 40 |
+
<div id="root"></div>
|
| 41 |
+
<script type="module">
|
| 42 |
+
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
| 43 |
+
import ReactDOM from 'react-dom/client';
|
| 44 |
+
import { Download, X, Upload, Sparkles, RefreshCw, AlertTriangle, Clock, Check, ImagePlus, User, Maximize2 } from 'lucide-react';
|
| 45 |
+
|
| 46 |
+
const h = React.createElement;
|
| 47 |
+
|
| 48 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 49 |
+
// Constants β μν¬νλ‘μ°(SPAO.json) CustomCombo μ΅μ
κ³Ό 1:1
|
| 50 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 51 |
+
const SHOT_OPTIONS = ['μ μ μ»·', 'μλ°μ μ»·', 'νλ°μ μ»·', 'λ νΌλ°μ€ ꡬλ κ·Έλλ‘'];
|
| 52 |
+
const ANGLE_OPTIONS = ['μ λ©΄', 'λ°μΈ‘λ©΄', 'μΈ‘λ©΄', 'λ‘μ°μ΅κΈ', 'νμ΄μ΅κΈ', 'νλ©΄'];
|
| 53 |
+
const GAZE_OPTIONS = ['μΉ΄λ©λΌ μμ', 'μμ°μ€λ¬μ΄ μμ '];
|
| 54 |
+
const AGE_OPTIONS = ['μ±μΈ', 'ν€μ¦'];
|
| 55 |
+
const DETAIL_GROUPS = [
|
| 56 |
+
{ key: 'outer', label: 'μμ°ν°', length: 'outer_length', fit: 'outer_fit' },
|
| 57 |
+
{ key: 'top', label: 'μμ', length: 'top_length', fit: 'top_fit' },
|
| 58 |
+
{ key: 'bottom', label: 'νμ', length: 'bottom_length', fit: 'bottom_fit' },
|
| 59 |
+
];
|
| 60 |
+
const DETAIL_OPTIONS = {
|
| 61 |
+
outer_length: { label: 'μμ°ν° κΈΈμ΄', options: ['ν리', '골λ°', 'νλ²
μ§'], def: '골λ°' },
|
| 62 |
+
outer_fit: { label: 'μμ°ν° ν', options: ['μ¬λ¦Ό', 'νμ€', 'μ€λ²'], def: 'νμ€' },
|
| 63 |
+
top_length: { label: 'μμ κΈΈμ΄', options: ['ν리', '골λ°', 'νλ²
μ§'], def: '골λ°' },
|
| 64 |
+
top_fit: { label: 'μμ ν', options: ['μ¬λ¦Ό', 'νμ€', 'μ€λ²'], def: 'μ€λ²' },
|
| 65 |
+
bottom_length: { label: 'νμ κΈΈμ΄', options: ['νλ²
μ§', '무λ¦', 'μ’
μ리', 'λ°λͺ©', 'μ λ°'], def: 'μ λ°' },
|
| 66 |
+
bottom_fit: { label: 'νμ ν', options: ['μ¬λ¦Ό', 'νμ€', 'μ€λ²'], def: 'μ€λ²' },
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
const ADULT_FACE_PRESETS = [
|
| 70 |
+
{ id: 'preset_9', label: 'μ¬μ', url: '/face_preset_9.png' },
|
| 71 |
+
{ id: 'preset_15', label: 'λ¨μ', url: '/face_preset_15.png' },
|
| 72 |
+
];
|
| 73 |
+
const KIDS_FACE_PRESETS = [
|
| 74 |
+
{ id: 'preset_kids_1', label: 'ν€μ¦ A', url: '/face_preset_kids_1.png' },
|
| 75 |
+
{ id: 'preset_kids_2', label: 'ν€μ¦ B', url: '/face_preset_kids_2.png' },
|
| 76 |
+
{ id: 'preset_kids_3', label: 'ν€μ¦ C', url: '/face_preset_kids_3.png' },
|
| 77 |
+
{ id: 'preset_kids_7', label: 'ν€μ¦ G', url: '/face_preset_kids_7.png' },
|
| 78 |
+
{ id: 'preset_kids_4', label: 'ν€μ¦ D', url: '/face_preset_kids_4.png' },
|
| 79 |
+
{ id: 'preset_kids_5', label: 'ν€μ¦ E', url: '/face_preset_kids_5.png' },
|
| 80 |
+
{ id: 'preset_kids_6', label: 'ν€μ¦ F', url: '/face_preset_kids_6.png' },
|
| 81 |
+
];
|
| 82 |
+
|
| 83 |
+
const IMAGE_SLOTS = [
|
| 84 |
+
{ key: 'outer', label: 'μμ°ν°', required: false },
|
| 85 |
+
{ key: 'top', label: 'μμ', required: false },
|
| 86 |
+
{ key: 'bottom', label: 'νμ', required: false, hint: 'μνΌμ€λ μ¬κΈ°' },
|
| 87 |
+
{ key: 'shoes', label: 'μ λ°', required: false },
|
| 88 |
+
{ key: 'inner', label: 'μ΄λμ¨μ΄', required: false },
|
| 89 |
+
{ key: 'belt', label: '벨νΈ', required: false },
|
| 90 |
+
{ key: 'background', label: 'λ°°κ²½', required: false, hint: 'λΉμ°λ©΄ κΈ°λ³Έ μ€νλμ€' },
|
| 91 |
+
{ key: 'pose', label: 'λ νΌλ°μ€ ν¬μ¦', required: false, hint: "'λ νΌλ°μ€ ꡬλ κ·Έλλ‘' μ ν μ νμ" },
|
| 92 |
+
];
|
| 93 |
+
|
| 94 |
+
// AI νκΈ° β μ μ₯ μ μΊλ²μ€μ μ½μ
(κΈ°μ‘΄ μ±κ³Ό λμΌ κ·κ²©)
|
| 95 |
+
const AI_LABEL_TEXT = 'AI μμ± μ΄λ―Έμ§';
|
| 96 |
+
const AI_LABEL_FONT_PT = 28;
|
| 97 |
+
const AI_LABEL_MARGIN_PT = 12 * (28 / 10);
|
| 98 |
+
|
| 99 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 100 |
+
// Helpers
|
| 101 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 102 |
+
const fileToDataUrl = (file, maxSide = 1536) => new Promise((resolve, reject) => {
|
| 103 |
+
const reader = new FileReader();
|
| 104 |
+
reader.onerror = reject;
|
| 105 |
+
reader.onload = () => {
|
| 106 |
+
const img = new Image();
|
| 107 |
+
img.onerror = reject;
|
| 108 |
+
img.onload = () => {
|
| 109 |
+
const scale = Math.min(1, maxSide / Math.max(img.width, img.height));
|
| 110 |
+
const w = Math.round(img.width * scale), hgt = Math.round(img.height * scale);
|
| 111 |
+
const canvas = document.createElement('canvas');
|
| 112 |
+
canvas.width = w; canvas.height = hgt;
|
| 113 |
+
const ctx = canvas.getContext('2d');
|
| 114 |
+
const keepPng = /png|webp/i.test(file.type);
|
| 115 |
+
if (!keepPng) { ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, w, hgt); }
|
| 116 |
+
ctx.drawImage(img, 0, 0, w, hgt);
|
| 117 |
+
resolve(keepPng ? canvas.toDataURL('image/png') : canvas.toDataURL('image/jpeg', 0.92));
|
| 118 |
+
};
|
| 119 |
+
img.src = reader.result;
|
| 120 |
+
};
|
| 121 |
+
reader.readAsDataURL(file);
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
const drawAiDisclosureOnCanvas = (ctx, width, height) => {
|
| 125 |
+
ctx.save();
|
| 126 |
+
ctx.textAlign = 'right'; ctx.textBaseline = 'top'; ctx.fillStyle = '#3c3c3c';
|
| 127 |
+
ctx.font = `300 ${AI_LABEL_FONT_PT}pt 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif`;
|
| 128 |
+
const ptToPx = 96 / 72;
|
| 129 |
+
const m = Math.max(AI_LABEL_MARGIN_PT * ptToPx, Math.min(width, height) * 0.028, 18);
|
| 130 |
+
ctx.fillText(AI_LABEL_TEXT, width - m, m);
|
| 131 |
+
ctx.restore();
|
| 132 |
+
};
|
| 133 |
+
|
| 134 |
+
async function downloadWithLabel(imageUrl, filename, withLabel = true) {
|
| 135 |
+
const img = new Image();
|
| 136 |
+
await new Promise((res, rej) => { img.onload = res; img.onerror = rej; img.src = imageUrl; });
|
| 137 |
+
const canvas = document.createElement('canvas');
|
| 138 |
+
canvas.width = img.naturalWidth; canvas.height = img.naturalHeight;
|
| 139 |
+
const ctx = canvas.getContext('2d');
|
| 140 |
+
ctx.drawImage(img, 0, 0);
|
| 141 |
+
if (withLabel) drawAiDisclosureOnCanvas(ctx, canvas.width, canvas.height);
|
| 142 |
+
const a = document.createElement('a');
|
| 143 |
+
a.href = canvas.toDataURL('image/png'); a.download = filename; a.click();
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
| 147 |
+
|
| 148 |
+
// λΉλ‘κ·ΈμΈ μ¬μ©μλ μμ
μ λ€μ λΆλ¬μ¬ μ μλλ‘ λΈλΌμ°μ λ³ IDλ₯Ό λ³΄κ΄ (λ‘κ·ΈμΈ μμ μλ²κ° κ³μ λͺ
μΌλ‘ λ¬Άμ)
|
| 149 |
+
const CLIENT_ID = (() => {
|
| 150 |
+
try {
|
| 151 |
+
let id = localStorage.getItem('spao_client_id');
|
| 152 |
+
if (!id) { id = crypto.randomUUID(); localStorage.setItem('spao_client_id', id); }
|
| 153 |
+
return id;
|
| 154 |
+
} catch { return 'c-' + Math.random().toString(36).slice(2); }
|
| 155 |
+
})();
|
| 156 |
+
const apiHeaders = (json = false) => ({ 'X-Client-Id': CLIENT_ID, ...(json ? { 'Content-Type': 'application/json' } : {}) });
|
| 157 |
+
|
| 158 |
+
// μ μΆ β jobId β ν΄λ§. κΈ΄ HTTP μ°κ²°μ μ‘κ³ μμ§ μμΌλ―λ‘ Space νλ‘μ νμμμκ³Ό 무κ΄.
|
| 159 |
+
async function submitToComfy(payload) {
|
| 160 |
+
const res = await fetch('/api/comfy/generate', { method: 'POST', headers: apiHeaders(true), body: JSON.stringify(payload) });
|
| 161 |
+
if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.detail || `HTTP ${res.status}`); }
|
| 162 |
+
return (await res.json()).jobId;
|
| 163 |
+
}
|
| 164 |
+
async function pollComfyJob(jobId, onProgress) {
|
| 165 |
+
let misses = 0;
|
| 166 |
+
while (true) {
|
| 167 |
+
await sleep(3000);
|
| 168 |
+
let r;
|
| 169 |
+
try { r = await fetch(`/api/comfy/jobs/${jobId}`, { headers: apiHeaders() }); } catch { if (++misses > 10) throw new Error('μλ² μλ΅μ΄ μμ΅λλ€.'); continue; }
|
| 170 |
+
if (r.status === 404) throw new Error('μμ
μ 보λ₯Ό μμ΄λ²λ Έμ΅λλ€ (μλ² μ¬μμ). λ€μ μλν΄μ£ΌμΈμ.');
|
| 171 |
+
if (!r.ok) { if (++misses > 10) throw new Error(`HTTP ${r.status}`); continue; }
|
| 172 |
+
misses = 0;
|
| 173 |
+
const j = await r.json();
|
| 174 |
+
onProgress?.(j);
|
| 175 |
+
if (j.status === 'done') return j;
|
| 176 |
+
if (j.status === 'error') throw new Error(j.error || 'μμ± μ€ν¨');
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
const fmtSec = (s) => { s = Math.round(s || 0); return s >= 60 ? `${Math.floor(s / 60)}λΆ ${s % 60}μ΄` : `${s}μ΄`; };
|
| 181 |
+
|
| 182 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 183 |
+
// UI atoms
|
| 184 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 185 |
+
const SectionTitle = ({ children, right }) => h('div', { className: 'flex items-center justify-between mb-2.5' },
|
| 186 |
+
h('h3', { className: 'text-[13px] font-semibold text-gray-200 tracking-tight' }, children), right || null);
|
| 187 |
+
|
| 188 |
+
const Segmented = ({ options, value, onChange, cols }) => h('div', {
|
| 189 |
+
className: `grid gap-1.5`, style: { gridTemplateColumns: `repeat(${cols || options.length}, minmax(0, 1fr))` } },
|
| 190 |
+
options.map(o => h('button', {
|
| 191 |
+
key: o, type: 'button', onClick: () => onChange(o),
|
| 192 |
+
className: `px-2 py-2 rounded-lg text-[12.5px] font-medium border transition-colors ${value === o
|
| 193 |
+
? 'bg-brand-blue border-brand-blue text-white'
|
| 194 |
+
: 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}`
|
| 195 |
+
}, o)));
|
| 196 |
+
|
| 197 |
+
const UploadTile = ({ slot, value, onChange, disabled }) => {
|
| 198 |
+
const inputRef = useRef(null);
|
| 199 |
+
const [drag, setDrag] = useState(false);
|
| 200 |
+
const handleFiles = async (files) => {
|
| 201 |
+
const f = files?.[0]; if (!f || !f.type.startsWith('image/')) return;
|
| 202 |
+
onChange(await fileToDataUrl(f), f.name);
|
| 203 |
+
};
|
| 204 |
+
return h('div', {
|
| 205 |
+
className: `relative rounded-xl border overflow-hidden group ${drag ? 'drop-active' : ''} ${value ? 'border-[#3a3a3a]' : 'border-dashed border-[#3a3a3a] bg-[#212121] hover:border-[#4b5563]'}`,
|
| 206 |
+
style: { aspectRatio: '3 / 4' },
|
| 207 |
+
onDragOver: e => { e.preventDefault(); setDrag(true); }, onDragLeave: () => setDrag(false),
|
| 208 |
+
onDrop: e => { e.preventDefault(); setDrag(false); if (!disabled) handleFiles(e.dataTransfer.files); },
|
| 209 |
+
onClick: () => !disabled && !value && inputRef.current?.click(),
|
| 210 |
+
},
|
| 211 |
+
h('input', { ref: inputRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: e => { handleFiles(e.target.files); e.target.value = ''; } }),
|
| 212 |
+
value
|
| 213 |
+
? h(React.Fragment, null,
|
| 214 |
+
h('img', { src: value, className: 'w-full h-full object-cover bg-white', alt: slot.label }),
|
| 215 |
+
!disabled && h('button', { type: 'button', onClick: e => { e.stopPropagation(); onChange(null, null); },
|
| 216 |
+
className: 'absolute top-1.5 right-1.5 w-6 h-6 rounded-full bg-black/70 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity' }, h(X, { size: 13 })),
|
| 217 |
+
h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-gradient-to-t from-black/70 to-transparent text-[11px] text-white' }, slot.label))
|
| 218 |
+
: h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-1 text-gray-500 cursor-pointer' },
|
| 219 |
+
h(ImagePlus, { size: 18 }),
|
| 220 |
+
h('span', { className: 'text-[11.5px] text-gray-300' }, slot.label, slot.required && h('span', { className: 'text-brand-blue ml-0.5' }, '*')),
|
| 221 |
+
slot.hint && h('span', { className: 'text-[10px] text-gray-500 px-2 text-center leading-tight' }, slot.hint))
|
| 222 |
+
);
|
| 223 |
+
};
|
| 224 |
+
|
| 225 |
+
const FaceTile = ({ preset, selected, onClick }) => h('button', {
|
| 226 |
+
type: 'button', onClick, title: preset.label,
|
| 227 |
+
className: `relative rounded-xl overflow-hidden border-2 transition-colors ${selected ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}`,
|
| 228 |
+
style: { aspectRatio: '1 / 1' } },
|
| 229 |
+
h('img', { src: preset.url, className: 'w-full h-full object-cover', alt: preset.label }),
|
| 230 |
+
selected && h('div', { className: 'absolute top-1 right-1 w-5 h-5 rounded-full bg-brand-blue flex items-center justify-center' }, h(Check, { size: 12, className: 'text-white' })),
|
| 231 |
+
h('div', { className: 'absolute bottom-0 inset-x-0 px-1.5 py-0.5 bg-black/60 text-[10.5px] text-white text-center' }, preset.label));
|
| 232 |
+
|
| 233 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 234 |
+
// App
|
| 235 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 236 |
+
function App() {
|
| 237 |
+
const [user, setUser] = useState({ username: 'anonymous', is_logged_in: false, oauth_enabled: false });
|
| 238 |
+
const [health, setHealth] = useState(null);
|
| 239 |
+
|
| 240 |
+
const [age, setAge] = useState('μ±μΈ');
|
| 241 |
+
const [facePreset, setFacePreset] = useState('preset_9');
|
| 242 |
+
const [faceUpload, setFaceUpload] = useState(null);
|
| 243 |
+
const [shot, setShot] = useState('μ μ μ»·');
|
| 244 |
+
const [angle, setAngle] = useState('λ°μΈ‘λ©΄');
|
| 245 |
+
const [gaze, setGaze] = useState('μμ°μ€λ¬μ΄ μμ ');
|
| 246 |
+
const [prompt, setPrompt] = useState('');
|
| 247 |
+
const [details, setDetails] = useState(Object.fromEntries(Object.entries(DETAIL_OPTIONS).map(([k, v]) => [k, v.def])));
|
| 248 |
+
const [detailTab, setDetailTab] = useState('top');
|
| 249 |
+
const [images, setImages] = useState({});
|
| 250 |
+
const [imageNames, setImageNames] = useState({}); // μ¬λ‘―λ³ μλ³Έ νμΌλͺ
(Dataset λ‘κ·ΈΒ·μ€νμΌμ½λ μ§κ³μ©)
|
| 251 |
+
const [faceUploadName, setFaceUploadName] = useState(null);
|
| 252 |
+
|
| 253 |
+
const [jobs, setJobs] = useState([]); // μ§ν μ€/μ€ν¨ μμ
[{id, jobId, meta, stageLabel, startedAt, error}]
|
| 254 |
+
const [tick, setTick] = useState(0); // κ²½κ³Όμκ° νμμ© 1μ΄ νμ΄λ¨Έ
|
| 255 |
+
const [results, setResults] = useState([]); // [{id, imageUrl, meta, elapsedSec}]
|
| 256 |
+
const [current, setCurrent] = useState(null);
|
| 257 |
+
const [error, setError] = useState(null);
|
| 258 |
+
const [aiLabel, setAiLabel] = useState(true);
|
| 259 |
+
const [lightbox, setLightbox] = useState(false); // κ²°κ³Ό μ΄λ―Έμ§ νλ 보기
|
| 260 |
+
useEffect(() => {
|
| 261 |
+
if (!lightbox) return;
|
| 262 |
+
const onKey = (e) => { if (e.key === 'Escape') setLightbox(false); };
|
| 263 |
+
window.addEventListener('keydown', onKey);
|
| 264 |
+
return () => window.removeEventListener('keydown', onKey);
|
| 265 |
+
}, [lightbox]);
|
| 266 |
+
const faceFileRef = useRef(null);
|
| 267 |
+
|
| 268 |
+
useEffect(() => {
|
| 269 |
+
fetch('/api/whoami').then(r => r.ok ? r.json() : null).then(d => d && setUser(d)).catch(() => {});
|
| 270 |
+
fetch('/api/comfy/health').then(r => r.ok ? r.json() : { ok: false, error: 'λΈλ¦¬μ§ λΌμ°νΈκ° μμ΅λλ€' }).then(setHealth).catch(() => setHealth({ ok: false, error: 'μν νμΈ μ€ν¨' }));
|
| 271 |
+
}, []);
|
| 272 |
+
|
| 273 |
+
const activeJobs = jobs.filter(j => !j.error);
|
| 274 |
+
useEffect(() => {
|
| 275 |
+
if (activeJobs.length === 0) return;
|
| 276 |
+
const id = setInterval(() => setTick(t => t + 1), 1000);
|
| 277 |
+
return () => clearInterval(id);
|
| 278 |
+
}, [activeJobs.length]);
|
| 279 |
+
|
| 280 |
+
useEffect(() => { // μ°λ Ή λ°κΎΈλ©΄ ν΄λΉ κ·Έλ£Ή 첫 ν리μ
μΌλ‘
|
| 281 |
+
const list = age === 'ν€μ¦' ? KIDS_FACE_PRESETS : ADULT_FACE_PRESETS;
|
| 282 |
+
if (!faceUpload && !list.some(p => p.id === facePreset)) setFacePreset(list[0].id);
|
| 283 |
+
}, [age]);
|
| 284 |
+
|
| 285 |
+
const presets = age === 'ν€μ¦' ? KIDS_FACE_PRESETS : ADULT_FACE_PRESETS;
|
| 286 |
+
const setImg = (key, v, name) => { setImages(prev => ({ ...prev, [key]: v })); setImageNames(prev => ({ ...prev, [key]: v ? (name || null) : null })); };
|
| 287 |
+
|
| 288 |
+
const missing = [];
|
| 289 |
+
if (!images.outer && !images.top && !images.bottom) missing.push('μμ 1κ° μ΄μ (μμ°ν°Β·μμΒ·νμ)');
|
| 290 |
+
if (shot === 'λ νΌλ°μ€ ꡬλ κ·Έλλ‘' && !images.pose) missing.push('λ νΌλ°μ€ ν¬μ¦');
|
| 291 |
+
const canGenerate = missing.length === 0 && (faceUpload || facePreset) && health?.ok;
|
| 292 |
+
|
| 293 |
+
const handleGenerate = async () => {
|
| 294 |
+
if (user.oauth_enabled && !user.is_logged_in) { alert("λ‘κ·ΈμΈμ΄ νμν©λλ€. μ°μΈ‘ μλ¨μ 'Hugging Faceλ‘ λ‘κ·ΈμΈ' λ²νΌμ λλ¬μ£ΌμΈμ."); return; }
|
| 295 |
+
if (!canGenerate) return;
|
| 296 |
+
setError(null);
|
| 297 |
+
const id = Date.now().toString(36) + Math.random().toString(36).slice(2, 5);
|
| 298 |
+
const meta = { shot, angle, gaze, age, prompt, face: faceUpload ? 'μ
λ‘λ' : (presets.find(p => p.id === facePreset)?.label || facePreset) };
|
| 299 |
+
const payload = { face: faceUpload || facePreset, faceFilename: faceUpload ? faceUploadName : null, images, imageFilenames: imageNames,
|
| 300 |
+
options: { shot, angle, gaze, age, ...details }, prompt, meta };
|
| 301 |
+
setJobs(prev => [...prev, { id, meta, stageLabel: 'μμ² μ μ‘ μ€', startedAt: Date.now() }]);
|
| 302 |
+
const patch = (p) => setJobs(prev => prev.map(j => j.id === id ? { ...j, ...p } : j));
|
| 303 |
+
let jobId;
|
| 304 |
+
try {
|
| 305 |
+
jobId = await submitToComfy(payload);
|
| 306 |
+
} catch (e) {
|
| 307 |
+
patch({ error: e.message }); return;
|
| 308 |
+
}
|
| 309 |
+
patch({ jobId, stageLabel: 'λκΈ° μ€' });
|
| 310 |
+
await trackJob(id, jobId, meta, patch);
|
| 311 |
+
};
|
| 312 |
+
|
| 313 |
+
// μλ² μμ
μ μλ£κΉμ§ λ°λΌκ°λ©° κ²°κ³Ό/μλ¬λ₯Ό λ°μ (μ μμ²κ³Ό μλ‘κ³ μΉ¨ 볡ꡬ λ λ€ μ¬μ©)
|
| 314 |
+
const trackJob = async (id, jobId, meta, patch) => {
|
| 315 |
+
try {
|
| 316 |
+
const j = await pollComfyJob(jobId, (st) => patch({ stageLabel: st.stageLabel, execStartedAt: st.execStartedAt || null }));
|
| 317 |
+
const item = { id, imageUrl: j.imageUrl, meta, elapsedSec: j.elapsedSec, createdAt: j.createdAt };
|
| 318 |
+
setResults(prev => prev.some(r => r.id === id) ? prev : [item, ...prev]);
|
| 319 |
+
setCurrent(prev => prev || item);
|
| 320 |
+
setJobs(prev => prev.filter(x => x.id !== id));
|
| 321 |
+
} catch (e) {
|
| 322 |
+
patch({ error: e.message });
|
| 323 |
+
}
|
| 324 |
+
};
|
| 325 |
+
const dismissJob = (id) => setJobs(prev => prev.filter(j => j.id !== id));
|
| 326 |
+
|
| 327 |
+
// μλ‘κ³ μΉ¨/μ¬μ μ μ μλ²μ λ¨μ μλ λ΄ μμ
볡ꡬ
|
| 328 |
+
useEffect(() => {
|
| 329 |
+
(async () => {
|
| 330 |
+
try {
|
| 331 |
+
const r = await fetch('/api/comfy/jobs', { headers: apiHeaders() });
|
| 332 |
+
if (!r.ok) return;
|
| 333 |
+
const { jobs: saved } = await r.json();
|
| 334 |
+
const done = saved.filter(j => j.status === 'done' && j.imageUrl)
|
| 335 |
+
.map(j => ({ id: j.id, imageUrl: j.imageUrl, meta: j.meta || {}, elapsedSec: j.elapsedSec, createdAt: j.createdAt }))
|
| 336 |
+
.sort((a, b) => b.createdAt - a.createdAt);
|
| 337 |
+
if (done.length) { setResults(done); setCurrent(prev => prev || done[0]); }
|
| 338 |
+
const pending = saved.filter(j => j.status !== 'done');
|
| 339 |
+
if (pending.length) {
|
| 340 |
+
setJobs(pending.map(j => ({ id: j.id, jobId: j.id, meta: j.meta || {}, stageLabel: j.stageLabel, startedAt: j.createdAt, execStartedAt: j.execStartedAt || null, error: j.error || null })));
|
| 341 |
+
for (const j of pending.filter(x => x.status === 'running')) {
|
| 342 |
+
const patch = (p) => setJobs(prev => prev.map(x => x.id === j.id ? { ...x, ...p } : x));
|
| 343 |
+
trackJob(j.id, j.id, j.meta || {}, patch);
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
} catch {}
|
| 347 |
+
})();
|
| 348 |
+
}, []);
|
| 349 |
+
|
| 350 |
+
// ββ Left: settings ββββββββββββββββββββββββββββββββββββββββ
|
| 351 |
+
const left = h('aside', { className: 'w-full lg:w-[420px] xl:w-[460px] shrink-0 h-full overflow-y-auto border-r border-[#2a2a2a] bg-[#1e1e1e]' },
|
| 352 |
+
h('div', { className: 'p-5 space-y-6' },
|
| 353 |
+
|
| 354 |
+
h('section', null,
|
| 355 |
+
h(SectionTitle, { right: h(Segmented, { options: AGE_OPTIONS, value: age, onChange: setAge }) }, 'μΌκ΅΄'),
|
| 356 |
+
h('div', { className: 'grid grid-cols-4 gap-2' },
|
| 357 |
+
presets.map(p => h(FaceTile, { key: p.id, preset: p, selected: !faceUpload && facePreset === p.id, onClick: () => { setFaceUpload(null); setFacePreset(p.id); } })),
|
| 358 |
+
h('button', { type: 'button', onClick: () => faceFileRef.current?.click(),
|
| 359 |
+
className: `relative rounded-xl overflow-hidden border-2 ${faceUpload ? 'border-brand-blue' : 'border-dashed border-[#3a3a3a] hover:border-[#4b5563] bg-[#242424]'}`, style: { aspectRatio: '1 / 1' } },
|
| 360 |
+
faceUpload
|
| 361 |
+
? h(React.Fragment, null, h('img', { src: faceUpload, className: 'w-full h-full object-cover' }),
|
| 362 |
+
h('span', { onClick: e => { e.stopPropagation(); setFaceUpload(null); }, className: 'absolute top-1 right-1 w-5 h-5 rounded-full bg-black/70 flex items-center justify-center' }, h(X, { size: 11 })),
|
| 363 |
+
h('div', { className: 'absolute bottom-0 inset-x-0 py-0.5 bg-black/60 text-[10.5px] text-center' }, 'μ
λ‘λ'))
|
| 364 |
+
: h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-1 text-gray-400' }, h(User, { size: 16 }), h('span', { className: 'text-[10.5px]' }, 'μ§μ μ
λ‘λ'))),
|
| 365 |
+
h('input', { ref: faceFileRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: async e => { const f = e.target.files?.[0]; if (f) { setFaceUpload(await fileToDataUrl(f, 1024)); setFaceUploadName(f.name); } e.target.value = ''; } }))),
|
| 366 |
+
|
| 367 |
+
h('section', null, h(SectionTitle, null, 'μ· μ ν'), h(Segmented, { options: SHOT_OPTIONS, value: shot, onChange: setShot, cols: 2 })),
|
| 368 |
+
h('section', null, h(SectionTitle, null, 'μΉ΄λ©λΌ μ΅κΈ'), h(Segmented, { options: ANGLE_OPTIONS, value: angle, onChange: setAngle, cols: 3 })),
|
| 369 |
+
h('section', null, h(SectionTitle, null, 'μμ '), h(Segmented, { options: GAZE_OPTIONS, value: gaze, onChange: setGaze })),
|
| 370 |
+
|
| 371 |
+
h('section', null,
|
| 372 |
+
h(SectionTitle, null, 'ν둬ννΈ μμ±'),
|
| 373 |
+
h('textarea', { value: prompt, onChange: e => setPrompt(e.target.value), rows: 3,
|
| 374 |
+
placeholder: 'μΆκ° μ§μμ¬ν (μ ν). μ: μμ μ£Όλ¨Έλμ λ£κ³ μ΄μ§ λ―Έμ, μλ§€λ₯Ό ν λ² μ μ΄ μ¬λ¦° μ€νμΌλ§',
|
| 375 |
+
className: 'w-full rounded-xl bg-[#242424] border border-[#333] px-3 py-2.5 text-[13px] text-gray-100 placeholder-gray-500 focus:outline-none focus:border-brand-blue' })),
|
| 376 |
+
|
| 377 |
+
h('section', null,
|
| 378 |
+
h(SectionTitle, { right: h('span', { className: 'text-[11px] text-gray-500' }, 'μμ°ν°Β·μμΒ·νμ μ€ 1κ° μ΄μ') }, 'μ΄λ―Έμ§ μ
λ‘λ'),
|
| 379 |
+
h('div', { className: 'grid grid-cols-4 gap-2' },
|
| 380 |
+
IMAGE_SLOTS.map(s => h(UploadTile, { key: s.key, slot: s, value: images[s.key], onChange: (v, name) => setImg(s.key, v, name) })))),
|
| 381 |
+
|
| 382 |
+
h('section', null,
|
| 383 |
+
h(SectionTitle, null, 'κΈΈμ΄ Β· ν'),
|
| 384 |
+
h('div', { className: 'flex gap-1.5 mb-3' },
|
| 385 |
+
DETAIL_GROUPS.map(g => h('button', {
|
| 386 |
+
key: g.key, type: 'button', onClick: () => setDetailTab(g.key),
|
| 387 |
+
className: `px-3 py-1.5 rounded-lg text-[12.5px] font-semibold transition-colors ${detailTab === g.key
|
| 388 |
+
? 'bg-brand-blue text-white'
|
| 389 |
+
: (images[g.key] ? 'bg-[#2a2a2a] text-gray-200 hover:bg-[#333]' : 'bg-[#242424] text-gray-500 hover:text-gray-300')}`
|
| 390 |
+
}, g.label, images[g.key] ? h('span', { className: `ml-1.5 inline-block w-1.5 h-1.5 rounded-full align-middle ${detailTab === g.key ? 'bg-white' : 'bg-brand-blue'}` }) : null))),
|
| 391 |
+
(() => {
|
| 392 |
+
const g = DETAIL_GROUPS.find(x => x.key === detailTab);
|
| 393 |
+
const rows = [['κΈΈμ΄', g.length], ['ν', g.fit]];
|
| 394 |
+
return h('div', { key: g.key, className: 'space-y-2 animate-fadeIn' },
|
| 395 |
+
rows.map(([label, k]) => h('div', { key: k, className: 'grid grid-cols-[52px_1fr] items-center gap-2' },
|
| 396 |
+
h('span', { className: 'text-[12px] text-gray-400' }, label),
|
| 397 |
+
h('div', { className: 'flex flex-wrap gap-1.5' },
|
| 398 |
+
DETAIL_OPTIONS[k].options.map(o => h('button', {
|
| 399 |
+
key: o, type: 'button', onClick: () => setDetails(d => ({ ...d, [k]: o })),
|
| 400 |
+
className: `px-3 py-1.5 rounded-lg text-[12.5px] font-medium border transition-colors ${details[k] === o
|
| 401 |
+
? 'bg-brand-blue border-brand-blue text-white'
|
| 402 |
+
: 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}`
|
| 403 |
+
}, o))))),
|
| 404 |
+
!images[g.key] && h('p', { className: 'text-[11px] text-gray-500 pt-1' }, `${g.label} μ΄λ―Έμ§λ₯Ό μ¬λ¦¬μ§ μμΌλ©΄ μ΄ μ€μ μ μ¬μ©λμ§ μμμ.`));
|
| 405 |
+
})()),
|
| 406 |
+
|
| 407 |
+
h('div', { className: 'pt-3 pb-3 sticky bottom-0 bg-[#1e1e1e] border-t border-[#2a2a2a] -mx-5 px-5' },
|
| 408 |
+
missing.length > 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `νμ: ${missing.join(', ')}`),
|
| 409 |
+
activeJobs.length > 0 && missing.length === 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `${activeJobs.length}건 μ§ν μ€ β μ€μ μ λ°κΏ λ°λ‘ λ€μ μ»·μ κ±Έμ΄λ μ μμ΄μ`),
|
| 410 |
+
h('button', { type: 'button', onClick: handleGenerate, disabled: !canGenerate,
|
| 411 |
+
className: `w-full h-12 rounded-xl font-semibold text-[14px] flex items-center justify-center gap-2 transition-colors ${canGenerate ? 'bg-brand-blue hover:bg-brand-hover text-white' : 'bg-[#2a2a2a] text-gray-500 cursor-not-allowed'}` },
|
| 412 |
+
h(Sparkles, { size: 16 }),
|
| 413 |
+
activeJobs.length > 0 ? `λ£©λΆ μμ± (${activeJobs.length}건 μ§ν μ€)` : 'λ£©λΆ μμ±'))));
|
| 414 |
+
|
| 415 |
+
// ββ Right: result βββββββββββββββββββββββββββββββββββββββββ
|
| 416 |
+
const right = h('main', { className: 'flex-1 h-full overflow-y-auto' },
|
| 417 |
+
h('div', { className: 'max-w-5xl mx-auto p-6 lg:p-8' },
|
| 418 |
+
!health?.ok && health && h('div', { className: 'mb-5 rounded-xl border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-[13px] text-amber-200 flex gap-2' },
|
| 419 |
+
h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, health.error || 'Comfy λΈλ¦¬μ§ μ€μ μ νμΈν΄μ£ΌμΈμ.')),
|
| 420 |
+
health?.ok && health.loginRequired === false && h('div', { className: 'mb-5 rounded-xl border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-[13px] text-amber-200 flex gap-2' },
|
| 421 |
+
h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, 'HF OAuthκ° μ°κ²°λμ§ μμ λ‘κ·ΈμΈ μμ΄ λꡬλ μμ±ν μ μλ μνμ
λλ€. READMEμ hf_oauth μ€μ κ³Ό Space μ¬μμμ νμΈν΄μ£ΌμΈμ.')),
|
| 422 |
+
error && h('div', { className: 'mb-5 rounded-xl border border-red-500/40 bg-red-500/10 px-4 py-3 text-[13px] text-red-200 flex gap-2 animate-fadeIn' },
|
| 423 |
+
h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', { className: 'break-all' }, error)),
|
| 424 |
+
|
| 425 |
+
jobs.length > 0 && h('div', { className: 'mb-5 rounded-xl border border-[#2a2a2a] bg-[#202020] overflow-hidden animate-fadeIn' },
|
| 426 |
+
h('div', { className: 'px-4 py-2.5 border-b border-[#2a2a2a] text-[12.5px] font-semibold text-gray-300 flex items-center gap-2' },
|
| 427 |
+
h(RefreshCw, { size: 13, className: activeJobs.length ? 'animate-spin text-brand-blue' : 'text-gray-500' }),
|
| 428 |
+
`μ§ν μ€ ${activeJobs.length}건`, jobs.length - activeJobs.length > 0 ? h('span', { className: 'text-red-300 font-normal' }, ` Β· μ€ν¨ ${jobs.length - activeJobs.length}건`) : null),
|
| 429 |
+
jobs.map((j, i) => h('div', { key: j.id, className: `px-4 py-2.5 flex items-center gap-3 text-[12.5px] ${i > 0 ? 'border-t border-[#262626]' : ''}` },
|
| 430 |
+
h('div', { className: `w-1.5 h-1.5 rounded-full shrink-0 ${j.error ? 'bg-red-400' : 'bg-brand-blue pulse-ring relative'}` }),
|
| 431 |
+
h('div', { className: 'flex-1 min-w-0' },
|
| 432 |
+
h('div', { className: 'text-gray-100 truncate' }, `${j.meta.face} Β· ${j.meta.shot} Β· ${j.meta.angle} Β· ${j.meta.gaze}`, j.meta.prompt ? h('span', { className: 'text-gray-500' }, ` Β· "${j.meta.prompt}"`) : null),
|
| 433 |
+
h('div', { className: j.error ? 'text-red-300 break-all' : 'text-gray-400' },
|
| 434 |
+
j.error ? j.error : (j.execStartedAt ? `${j.stageLabel} Β· ${fmtSec((Date.now() - j.execStartedAt) / 1000)}` : `${j.stageLabel} Β· λκΈ° ${fmtSec((Date.now() - j.startedAt) / 1000)}`))),
|
| 435 |
+
j.error && h('button', { type: 'button', onClick: () => dismissJob(j.id), className: 'text-gray-500 hover:text-white' }, h(X, { size: 14 }))))),
|
| 436 |
+
|
| 437 |
+
h('div', { className: 'grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_200px] gap-6' },
|
| 438 |
+
// λ©μΈ λ·°μ΄
|
| 439 |
+
h('div', { className: 'rounded-2xl bg-[#202020] border border-[#2a2a2a] overflow-hidden relative', style: { minHeight: '60vh' } },
|
| 440 |
+
!current && activeJobs.length > 0
|
| 441 |
+
? h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-5' },
|
| 442 |
+
h('div', { className: 'shimmer absolute inset-0 opacity-60' }),
|
| 443 |
+
h('div', { className: 'relative pulse-ring w-14 h-14 rounded-full bg-brand-blue/20 flex items-center justify-center' }, h(Sparkles, { size: 22, className: 'text-brand-blue' })),
|
| 444 |
+
h('div', { className: 'relative text-center' },
|
| 445 |
+
h('div', { className: 'text-[15px] font-semibold text-gray-100' }, activeJobs[0].stageLabel),
|
| 446 |
+
h('div', { className: 'mt-1 text-[12.5px] text-gray-400 flex items-center justify-center gap-1' }, h(Clock, { size: 12 }),
|
| 447 |
+
activeJobs[0].execStartedAt ? `${fmtSec((Date.now() - activeJobs[0].execStartedAt) / 1000)} κ²½κ³Ό Β· λ³΄ν΅ 1~2λΆ μμ` : 'μ€ν μμλ₯Ό κΈ°λ€λ¦¬λ μ€')),
|
| 448 |
+
h('p', { className: 'relative text-[11.5px] text-gray-500 max-w-xs text-center' }, 'μ΄ νμ λ«μ§ λ§μΈμ. μμ±μ΄ λλλ©΄ μ¬κΈ°μ μ΄λ―Έμ§κ° νμλ©λλ€.'))
|
| 449 |
+
: current
|
| 450 |
+
? h('div', { className: 'animate-fadeIn flex flex-col' },
|
| 451 |
+
h('div', { className: 'flex justify-center bg-[#1c1c1c]' },
|
| 452 |
+
h('div', { className: 'relative inline-block' },
|
| 453 |
+
h('img', { src: current.imageUrl, onClick: () => setLightbox(true), title: 'ν΄λ¦νλ©΄ ν¬κ² 보기',
|
| 454 |
+
className: 'max-h-[78vh] w-auto max-w-full block bg-white cursor-zoom-in', alt: 'μμ± κ²°κ³Ό' }),
|
| 455 |
+
aiLabel && h('div', { className: 'ai-label-overlay' }, AI_LABEL_TEXT),
|
| 456 |
+
h('button', { type: 'button', onClick: () => setLightbox(true), title: 'ν¬κ² 보기',
|
| 457 |
+
className: 'absolute bottom-3 right-3 w-9 h-9 rounded-lg bg-black/55 hover:bg-black/75 text-white flex items-center justify-center' }, h(Maximize2, { size: 16 })))),
|
| 458 |
+
h('div', { className: 'flex items-center justify-between gap-3 px-4 py-3 border-t border-[#2a2a2a]' },
|
| 459 |
+
h('label', { className: 'flex items-center gap-2 cursor-pointer select-none text-[12.5px] text-gray-300' },
|
| 460 |
+
h('button', { type: 'button', role: 'switch', 'aria-checked': aiLabel, onClick: () => setAiLabel(v => !v),
|
| 461 |
+
className: `relative w-9 h-5 rounded-full transition-colors ${aiLabel ? 'bg-brand-blue' : 'bg-[#3a3a3a]'}` },
|
| 462 |
+
h('span', { className: `absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white transition-transform ${aiLabel ? 'translate-x-4' : ''}` })),
|
| 463 |
+
h('span', null, "'AI μμ± μ΄λ―Έμ§' νκΈ°"),
|
| 464 |
+
h('span', { className: 'text-gray-500' }, aiLabel ? 'νλ©΄Β·λ€μ΄λ‘λμ ν¬ν¨' : 'νκΈ° μμ')),
|
| 465 |
+
h('button', { type: 'button', onClick: () => downloadWithLabel(current.imageUrl, `spao_${current.meta.shot}_${current.meta.angle}_${current.id}.png`, aiLabel),
|
| 466 |
+
className: 'h-10 px-4 rounded-xl bg-brand-blue hover:bg-brand-hover text-white text-[13px] font-semibold flex items-center gap-1.5' }, h(Download, { size: 15 }), 'λ€μ΄λ‘λ')))
|
| 467 |
+
: h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center text-gray-500 gap-2' },
|
| 468 |
+
h(Upload, { size: 28, className: 'opacity-50' }),
|
| 469 |
+
h('p', { className: 'text-[13.5px]' }, 'μΌμͺ½μμ μΌκ΅΄Β·μμμ κ³ λ₯΄κ³ λ£©λΆ μμ±μ λλ₯΄λ©΄'),
|
| 470 |
+
h('p', { className: 'text-[13.5px]' }, 'ν λ²μ λͺ¨λΈμ»·μ΄ μμ±λ©λλ€.'))),
|
| 471 |
+
// νμ€ν 리
|
| 472 |
+
h('div', null,
|
| 473 |
+
h('h3', { className: 'text-[13px] font-semibold text-gray-300 mb-2.5' }, `μ΄λ² μΈμ
κ²°κ³Ό ${results.length ? `(${results.length})` : ''}`),
|
| 474 |
+
results.length === 0
|
| 475 |
+
? h('p', { className: 'text-[12px] text-gray-500' }, 'μμ§ μμ')
|
| 476 |
+
: h('div', { className: 'grid grid-cols-3 md:grid-cols-1 gap-2' },
|
| 477 |
+
results.map(r => h('button', { key: r.id, type: 'button', onClick: () => setCurrent(r),
|
| 478 |
+
className: `relative rounded-xl overflow-hidden border-2 ${current?.id === r.id ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}` },
|
| 479 |
+
h('img', { src: r.imageUrl, className: 'w-full h-auto block bg-white' }),
|
| 480 |
+
h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-black/65 text-[10.5px] text-left leading-tight' },
|
| 481 |
+
h('div', null, `${r.meta.face ? r.meta.face + ' Β· ' : ''}${r.meta.shot} Β· ${r.meta.angle}`),
|
| 482 |
+
h('div', { className: 'text-gray-300' }, `${r.meta.gaze} Β· ${fmtSec(r.elapsedSec)}`))))))),
|
| 483 |
+
|
| 484 |
+
current && h('div', { className: 'mt-5 text-[12px] text-gray-500' },
|
| 485 |
+
`${current.meta.age} Β· ${current.meta.shot} Β· ${current.meta.angle} Β· ${current.meta.gaze}`, current.meta.prompt ? ` Β· "${current.meta.prompt}"` : '')));
|
| 486 |
+
|
| 487 |
+
// ββ Header ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 488 |
+
const header = h('header', { className: 'h-14 shrink-0 border-b border-[#2a2a2a] bg-[#1a1a1a] flex items-center justify-between px-5' },
|
| 489 |
+
h('div', { className: 'flex items-center gap-5' },
|
| 490 |
+
h('div', { className: 'flex items-center gap-3' },
|
| 491 |
+
h('div', { className: 'w-8 h-8 rounded-lg bg-brand-blue flex items-center justify-center' }, h(Sparkles, { size: 16, className: 'text-white' })),
|
| 492 |
+
h('div', { className: 'text-[15px] font-bold tracking-tight' }, 'SPAO AI λ£©λΆ μμ±κΈ°')),
|
| 493 |
+
user.oauth_enabled && h('div', { className: 'flex items-center gap-2 text-[12.5px] pl-5 border-l border-[#2a2a2a]' },
|
| 494 |
+
user.is_logged_in
|
| 495 |
+
? h(React.Fragment, null,
|
| 496 |
+
h('span', { className: 'text-gray-300' }, user.name || user.username),
|
| 497 |
+
h('a', { href: user.logout_url, className: 'text-gray-500 hover:text-white' }, 'λ‘κ·Έμμ'))
|
| 498 |
+
: h('a', { href: user.login_url, className: 'px-3 py-1.5 rounded-lg bg-[#2a2a2a] hover:bg-[#333] text-gray-100' }, 'π€ Hugging Faceλ‘ λ‘κ·ΈμΈ'))),
|
| 499 |
+
h('div', null,
|
| 500 |
+
health && !health.ok && h('span', { className: 'inline-flex items-center gap-1.5 text-[12.5px] text-amber-400' },
|
| 501 |
+
h('span', { className: 'w-1.5 h-1.5 rounded-full bg-amber-400' }), 'Comfy μ€μ νμ')));
|
| 502 |
+
|
| 503 |
+
const lightboxEl = lightbox && current && h('div', {
|
| 504 |
+
className: 'fixed inset-0 z-50 bg-black/90 flex items-center justify-center animate-fadeIn cursor-zoom-out',
|
| 505 |
+
onClick: () => setLightbox(false) },
|
| 506 |
+
h('img', { src: current.imageUrl, alt: 'μμ± κ²°κ³Ό νλ', onClick: e => e.stopPropagation(),
|
| 507 |
+
className: 'max-w-[96vw] max-h-[96vh] object-contain bg-white cursor-default shadow-2xl' }),
|
| 508 |
+
aiLabel && h('div', { className: 'absolute top-4 right-16 text-[12px] text-gray-300 font-light pointer-events-none' }, AI_LABEL_TEXT),
|
| 509 |
+
h('button', { type: 'button', onClick: () => setLightbox(false), title: 'λ«κΈ° (Esc)',
|
| 510 |
+
className: 'absolute top-4 right-4 w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 text-white flex items-center justify-center' }, h(X, { size: 18 })),
|
| 511 |
+
h('div', { className: 'absolute bottom-4 left-1/2 -translate-x-1/2 flex gap-2', onClick: e => e.stopPropagation() },
|
| 512 |
+
h('button', { type: 'button', onClick: () => downloadWithLabel(current.imageUrl, `spao_${current.meta.shot}_${current.meta.angle}_${current.id}.png`, aiLabel),
|
| 513 |
+
className: 'h-10 px-4 rounded-xl bg-brand-blue hover:bg-brand-hover text-white text-[13px] font-semibold flex items-center gap-1.5' }, h(Download, { size: 15 }), 'λ€μ΄λ‘λ')));
|
| 514 |
+
|
| 515 |
+
return h('div', { className: 'h-screen flex flex-col bg-[#1a1a1a]' }, header,
|
| 516 |
+
h('div', { className: 'flex-1 flex flex-col lg:flex-row min-h-0' }, left, right), lightboxEl);
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
ReactDOM.createRoot(document.getElementById('root')).render(h(App));
|
| 520 |
+
</script>
|
| 521 |
+
</body>
|
| 522 |
+
</html>
|
server (26).py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|