Spaces:
Sleeping
Sleeping
Download index.html from sunyoung00/CLOVIS: direct link, hf CLI and curl.
- Browser
- Download file 65.4 kB
-
https://huggingface.co/spaces/sunyoung00/CLOVIS/resolve/main/index.html
- Command line
-
hf download hf://spaces/sunyoung00/CLOVIS/index.html
-
curl -L -o index.html https://huggingface.co/spaces/sunyoung00/CLOVIS/resolve/main/index.html
65.4 kB
| <html lang="ko" class="dark"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>CLOVIS AI ๋ฃฉ๋ถ ์์ฑ๊ธฐ</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script> | |
| tailwind.config = { darkMode: 'class', theme: { extend: { colors: { brand: { blue: '#3B82F6', hover: '#2563EB' } } } } } | |
| </script> | |
| <link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin /> | |
| <link rel="stylesheet" crossorigin href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css" /> | |
| <style> | |
| * { font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; } | |
| body { -webkit-font-smoothing: antialiased; background: #1a1a1a; color: #f9fafb; margin: 0; overflow: hidden; } | |
| ::-webkit-scrollbar { width: 6px; height: 6px; } | |
| ::-webkit-scrollbar-track { background: #1a1a1a; } | |
| ::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; } | |
| ::-webkit-scrollbar-thumb:hover { background: #4b5563; } | |
| @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } | |
| @keyframes shimmer { 0% { background-position: -600px 0; } 100% { background-position: 600px 0; } } | |
| @keyframes pulseRing { 0% { transform: scale(0.85); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } } | |
| .animate-fadeIn { animation: fadeIn .25s ease-out; } | |
| .shimmer { background: linear-gradient(90deg, #232323 0%, #2c2c2c 40%, #232323 80%); background-size: 600px 100%; animation: shimmer 1.6s linear infinite; } | |
| .pulse-ring::before { content: ''; position: absolute; inset: -6px; border-radius: 9999px; border: 2px solid #3B82F6; animation: pulseRing 1.4s ease-out infinite; } | |
| .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; } | |
| .drop-active { border-color: #3B82F6 ; background: rgba(59,130,246,.08) ; } | |
| textarea { resize: vertical; } | |
| </style> | |
| <script type="importmap"> | |
| { "imports": { | |
| "react": "https://esm.sh/react@19.1.0", | |
| "react/": "https://esm.sh/react@19.1.0/", | |
| "react-dom/": "https://esm.sh/react-dom@19.1.0/", | |
| "lucide-react": "https://esm.sh/lucide-react@0.462.0?external=react" | |
| } } | |
| </script> | |
| </head> | |
| <body> | |
| <div id="root"></div> | |
| <script type="module"> | |
| import React, { useState, useEffect, useRef, useCallback } from 'react'; | |
| import ReactDOM from 'react-dom/client'; | |
| import { Download, X, Upload, Sparkles, RefreshCw, AlertTriangle, Clock, Check, ImagePlus, User, Maximize2, ChevronDown } from 'lucide-react'; | |
| const h = React.createElement; | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| // Constants โ ์ํฌํ๋ก์ฐ(SPAO.json) CustomCombo ์ต์ ๊ณผ 1:1 | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const SHOT_OPTIONS = ['์ ์ ์ปท', '์๋ฐ์ ์ปท', 'ํ๋ฐ์ ์ปท']; // ํ๋ ์์ ํญ์ ์ท ๊ท์น์ด ์ ํจ (๋ ํผ๋ฐ์ค๋ ํฌ์ฆ ์ฐธ๊ณ ์ฉ) | |
| const ANGLE_OPTIONS = ['์ ๋ฉด', '๋ฐ์ธก๋ฉด', '์ธก๋ฉด', '๋ก์ฐ์ต๊ธ', 'ํ์ด์ต๊ธ', 'ํ๋ฉด', '๋ ํผ๋ฐ์ค ๋ฐ๋ฆ']; | |
| const GAZE_OPTIONS = ['์นด๋ฉ๋ผ ์์', '์์ฐ์ค๋ฌ์ด ์์ ', '๋ ํผ๋ฐ์ค ๋ฐ๋ฆ']; | |
| const AGE_OPTIONS = ['์ฑ์ธ', 'ํค์ฆ']; | |
| const DETAIL_GROUPS = [ | |
| { key: 'outer', label: '์์ฐํฐ', length: 'outer_length', fit: 'outer_fit' }, | |
| { key: 'top', label: '์์', length: 'top_length', fit: 'top_fit' }, | |
| { key: 'bottom', label: 'ํ์', length: 'bottom_length', fit: 'bottom_fit' }, | |
| ]; | |
| const DETAIL_OPTIONS = { | |
| outer_length: { label: '์์ฐํฐ ๊ธธ์ด', options: ['ํ๋ฆฌ', '๊ณจ๋ฐ', 'ํ๋ฒ ์ง'], def: '๊ณจ๋ฐ' }, | |
| outer_fit: { label: '์์ฐํฐ ํ', options: ['์ฌ๋ฆผ', 'ํ์ค', '์ค๋ฒ'], def: 'ํ์ค' }, | |
| top_length: { label: '์์ ๊ธธ์ด', options: ['ํ๋ฆฌ', '๊ณจ๋ฐ', 'ํ๋ฒ ์ง'], def: '๊ณจ๋ฐ' }, | |
| top_fit: { label: '์์ ํ', options: ['์ฌ๋ฆผ', 'ํ์ค', '์ค๋ฒ'], def: '์ค๋ฒ' }, | |
| bottom_length: { label: 'ํ์ ๊ธธ์ด', options: ['ํ๋ฒ ์ง', '๋ฌด๋ฆ', '์ข ์๋ฆฌ', '๋ฐ๋ชฉ', '์ ๋ฐ'], def: '์ ๋ฐ' }, | |
| bottom_fit: { label: 'ํ์ ํ', options: ['์ฌ๋ฆผ', 'ํ์ค', '์ค๋ฒ'], def: '์ค๋ฒ' }, | |
| }; | |
| const ADULT_FACE_PRESETS = [ | |
| { id: 'preset_17', label: '์ฌ์ฑ 1', url: '/face_preset_17.png' }, | |
| { id: 'preset_18', label: '์ฌ์ฑ 2', url: '/face_preset_18.png' }, | |
| { id: 'preset_19', label: '์ฌ์ฑ 3', url: '/face_preset_19.png' }, | |
| ]; | |
| // CLOVIS ๋ ํค์ฆ ๋ผ์ธ์ด ์์ด ํค์ฆ ํ๋ฆฌ์ ยท์ฐ๋ น ํ ๊ธ์ ๋ ธ์ถํ์ง ์์ (์ํฌํ๋ก์ฐ age ์ฝค๋ณด์๋ '์ฑ์ธ' ๊ณ ์ ์ ๋ฌ) | |
| const IMAGE_SLOTS = [ | |
| { key: 'outer', label: '์์ฐํฐ', required: false }, | |
| { key: 'top', label: '์์', required: false }, | |
| { key: 'bottom', label: 'ํ์', required: false, hint: '์ํผ์ค๋ ์ฌ๊ธฐ' }, | |
| { key: 'shoes', label: '์ ๋ฐ', required: false }, | |
| { key: 'inner', label: '์ด๋์จ์ด', required: false }, | |
| { key: 'belt', label: '๋ฒจํธ', required: false }, | |
| { key: 'background', label: '๋ฐฐ๊ฒฝ', required: false, hint: '๋น์ฐ๋ฉด ๊ธฐ๋ณธ ์คํ๋์ค' }, | |
| { key: 'pose', label: '๋ ํผ๋ฐ์ค ํฌ์ฆ', required: false, hint: 'ํฌ์ฆ ์ฐธ๊ณ ์ฉ ยท ๊ตฌ๋๋ ์ท ์ ํ ๊ธฐ์ค' }, | |
| ]; | |
| // ๋ํ ์ผ ์ฐธ์กฐ: ํด๋ก์ฆ์ ์ ์์ฑ ๋ชจ๋ธ์ ์ง์ ์ฐธ์กฐ๋ก ์ ๋ฌ (์ ์ฒด ์ต๋ 4์ฅ) | |
| // ์ท๋ง๋ค ์ฌ๋กฏ 2๊ฐ(a/b), ์ฌ๋กฏ๋ณ๋ก ์ข ๋ฅ๋ฅผ ๊ณ ๋ฆ โ ์ข ๋ฅ๋ comfy_client.DETAIL_KIND_EN ํค์ 1:1 | |
| const DETAIL_MAX = 4; | |
| const DETAIL_SLOTS = ['a', 'b']; | |
| // ์ท ์ข ๋ฅ๋ณ ๋ํ ์ผ ํญ๋ชฉ โ key ๋ comfy_client.DETAIL_KIND_EN ๊ณผ 1:1. short: ์นฉ ํ์, label: ํดํ | |
| const K = { | |
| texture: { key: 'texture', short: '์กฐ์ง๊ฐ', label: '์๋จ ์กฐ์ง๊ฐ (์ท ์ ์ฒด์ ๋ฐ์)' }, | |
| logo: { key: 'logo', short: '๋ก๊ณ ', label: '๋ก๊ณ ยทํ๋ฆฐํธ (๋ฉ์ธ ์ฌ์ง๊ณผ ๊ฐ์ ์์น)' }, | |
| neckline: { key: 'neckline', short: '๋ฅ๋ผ์ธ', label: '๋ฅ๋ผ์ธยท์นด๋ผ' }, | |
| collar: { key: 'collar', short: '์นด๋ผยทํ๋', label: '์นด๋ผยทํ๋ยท๋ผํ ' }, | |
| sleeve: { key: 'sleeve', short: '์๋งค', label: '์๋งคยท์ปคํ์ค' }, | |
| hem: { key: 'hem', short: '๋ฐ๋จ', label: '๋ฐ๋จยทํด ๋ง๊ฐ' }, | |
| waist: { key: 'waist', short: 'ํ๋ฆฌ', label: 'ํ๋ฆฌ (์จ์ด์คํธ๋ฐด๋ยท๋ฒจํธ๋ฃจํยท๋๋ก์คํธ๋ง)' }, | |
| pocket: { key: 'pocket', short: 'ํฌ์ผ', label: 'ํฌ์ผ (ํํยท์คํฐ์นยทํ๋ฉ)' }, | |
| closure: { key: 'closure', short: '์งํผยท๋ฒํผ', label: '์งํผยท๋ฒํผยท์ค๋ ' }, | |
| trim: { key: 'trim', short: '๋ถ์์ฌ', label: '๋ถ์์ฌ (๋ผ๋ฒจยทํญยท์ํ ๋ฑ)' }, | |
| material: { key: 'material', short: '์์ฌ', label: '์์ฌยท์ง๊ฐ (๊ฐ์ฃฝยท์ค์จ์ด๋ยท๋ฉ์ ๋ฑ, ์ ์ฒด์ ๋ฐ์)' }, | |
| sole: { key: 'sole', short: '๋ฐ์ฐฝ', label: '๋ฐ์ฐฝยท์์์' }, | |
| lacing: { key: 'lacing', short: '๋', label: '๋ยท์์ผ๋ ยท์คํฌ' }, | |
| heel: { key: 'heel', short: '๋ค์ถ', label: '๋ค์ถยทํํญยท๋ฐ๋ชฉ' }, | |
| buckle: { key: 'buckle', short: '๋ฒํด', label: '๋ฒํด' }, | |
| edge: { key: 'edge', short: '์คํฐ์น', label: '์คํฐ์นยท์ฃ์งยท๋ฒจํธํ' }, | |
| }; | |
| const DETAIL_KINDS_BY_GARMENT = { | |
| outer: [K.texture, K.logo, K.collar, K.sleeve, K.hem, K.pocket, K.closure, K.trim], | |
| top: [K.texture, K.logo, K.neckline, K.sleeve, K.hem, K.pocket, K.trim], | |
| bottom: [K.texture, K.logo, K.waist, K.hem, K.pocket, K.closure, K.trim], | |
| shoes: [K.material, K.logo, K.sole, K.lacing, K.heel, K.trim], | |
| inner: [K.texture, K.logo, K.neckline, K.sleeve, K.hem], | |
| belt: [K.material, K.buckle, K.logo, K.edge], | |
| }; | |
| // ์ฌ๋กฏ ๊ธฐ๋ณธ๊ฐ: ์ผ์ชฝ = ์์ฌ/์กฐ์ง๊ฐ, ์ค๋ฅธ์ชฝ = ๋ก๊ณ (๋ฒจํธ๋ ๋ฒํด) | |
| const defaultKind = (g, slot) => { | |
| const list = DETAIL_KINDS_BY_GARMENT[g] || []; | |
| if (slot === 'a') return list[0]?.key; | |
| return g === 'belt' ? 'buckle' : (list.find(k => k.key === 'logo') || list[1] || list[0])?.key; | |
| }; | |
| const DETAIL_GARMENTS = [ | |
| { key: 'outer', label: '์์ฐํฐ' }, { key: 'top', label: '์์' }, { key: 'bottom', label: 'ํ์' }, | |
| { key: 'shoes', label: '์ ๋ฐ' }, { key: 'inner', label: '์ด๋์จ์ด' }, { key: 'belt', label: '๋ฒจํธ' }, | |
| ]; | |
| // AI ํ๊ธฐ โ ์ ์ฅ ์ ์บ๋ฒ์ค์ ์ฝ์ (๊ธฐ์กด ์ฑ๊ณผ ๋์ผ ๊ท๊ฒฉ) | |
| const AI_LABEL_TEXT = 'AI ์์ฑ ์ด๋ฏธ์ง'; | |
| const AI_LABEL_FONT_PT = 28; | |
| const AI_LABEL_MARGIN_PT = 12 * (28 / 10); | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| // Helpers | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const fileToDataUrl = (file, maxSide = 1536) => new Promise((resolve, reject) => { | |
| const reader = new FileReader(); | |
| reader.onerror = reject; | |
| reader.onload = () => { | |
| const img = new Image(); | |
| img.onerror = reject; | |
| img.onload = () => { | |
| const scale = Math.min(1, maxSide / Math.max(img.width, img.height)); | |
| const w = Math.round(img.width * scale), hgt = Math.round(img.height * scale); | |
| const canvas = document.createElement('canvas'); | |
| canvas.width = w; canvas.height = hgt; | |
| const ctx = canvas.getContext('2d'); | |
| const keepPng = /png|webp/i.test(file.type); | |
| if (!keepPng) { ctx.fillStyle = '#fff'; ctx.fillRect(0, 0, w, hgt); } | |
| ctx.drawImage(img, 0, 0, w, hgt); | |
| resolve(keepPng ? canvas.toDataURL('image/png') : canvas.toDataURL('image/jpeg', 0.92)); | |
| }; | |
| img.src = reader.result; | |
| }; | |
| reader.readAsDataURL(file); | |
| }); | |
| const drawAiDisclosureOnCanvas = (ctx, width, height) => { | |
| ctx.save(); | |
| ctx.textAlign = 'right'; ctx.textBaseline = 'top'; ctx.fillStyle = '#3c3c3c'; | |
| ctx.font = `300 ${AI_LABEL_FONT_PT}pt 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif`; | |
| const ptToPx = 96 / 72; | |
| const m = Math.max(AI_LABEL_MARGIN_PT * ptToPx, Math.min(width, height) * 0.028, 18); | |
| ctx.fillText(AI_LABEL_TEXT, width - m, m); | |
| ctx.restore(); | |
| }; | |
| async function downloadWithLabel(imageUrl, filename, withLabel = true) { | |
| const img = new Image(); | |
| await new Promise((res, rej) => { img.onload = res; img.onerror = rej; img.src = imageUrl; }); | |
| const canvas = document.createElement('canvas'); | |
| canvas.width = img.naturalWidth; canvas.height = img.naturalHeight; | |
| const ctx = canvas.getContext('2d'); | |
| ctx.drawImage(img, 0, 0); | |
| if (withLabel) drawAiDisclosureOnCanvas(ctx, canvas.width, canvas.height); | |
| const a = document.createElement('a'); | |
| a.href = canvas.toDataURL('image/png'); a.download = filename; a.click(); | |
| } | |
| const sleep = (ms) => new Promise(r => setTimeout(r, ms)); | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| // ์ฑ๋ ์ฌ์ด์ฆ ๋ด๋ณด๋ด๊ธฐ โ ์์ฑ์ 3:4 ์๋ณธ ํ ๋ฒ, ์ฑ๋ ๊ท๊ฒฉ์ ์ ์ฅ ์ ๋ณํ | |
| // ์ฌ๋ฐฑ์ AI ์ฌ์์ฑ์ด ์๋๋ผ ์๋ณธ ๊ฐ์ฅ์๋ฆฌ ํฝ์ ์ ์ค(ํ) ๋จ์๋ก ์ฐ์ฅํด ์ฑ์ (์๋ณธ ํฝ์ ๋ฌด์์ค) | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const EXPORT_PRESETS = [ | |
| { key: 'original', label: '์๋ณธ', desc: '1536ร2048', w: null, h: null, suffix: '' }, | |
| { key: 'mall', label: '์ด๋๋๋ชฐยท๋ค์ด๋ฒยท์ฌ๋ฐฉ๋ท', desc: '1400ร1400', w: 1400, h: 1400, suffix: '_1400x1400' }, | |
| { key: 'zigzag', label: '์ง๊ทธ์ฌ๊ทธ', desc: '1080ร1296', w: 1080, h: 1296, suffix: '_1080x1296' }, | |
| ]; | |
| // ๋์ ์บ๋ฒ์ค์ (์คยทํฌ ๋ฐ์ํด) ์๋ณธ์ ๊ทธ๋ฆฌ๊ณ , ๋จ๋ ์ข์ฐ ์ฌ๋ฐฑ์ ๊ฐ์ฅ์๋ฆฌ 1px ์ด์ ๋๋ ค ์ฑ์ด๋ค. | |
| function renderChannelCanvas(img, W, H, zoom, offX, offY, withLabel) { | |
| const sw = img.naturalWidth, sh = img.naturalHeight; | |
| const s = Math.min(W / sw, H / sh) * zoom; | |
| const dw = sw * s, dh = sh * s; | |
| // ํฌ ํด๋จํ: ์ปค๋ฒ ์ ๋๋ ์ถ์ ์ค์ ๊ณ ์ , ์ปค๋ฒ๋๋ ์ถ์ ๋นํ์ด ์ ์๊ธฐ๋ ๋ฒ์๋ก ์ ํ | |
| let dx = dw >= W ? Math.min(0, Math.max(W - dw, (W - dw) / 2 + offX)) : (W - dw) / 2; | |
| let dy = dh >= H ? Math.min(0, Math.max(H - dh, (H - dh) / 2 + offY)) : (H - dh) / 2; | |
| const canvas = document.createElement('canvas'); | |
| canvas.width = W; canvas.height = H; | |
| const ctx = canvas.getContext('2d'); | |
| ctx.imageSmoothingQuality = 'high'; | |
| ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, W, H); | |
| // ๋ณด์ด๋ ์๋ณธ ์ธ๋ก ๊ตฌ๊ฐ (์ฌ๋ฐฑ ์ค์ ์์ ๊ฐ์ ํ์์ ์๊ธฐ ์ํด) | |
| const sy0 = Math.max(0, -dy / s), syh = Math.min(sh - sy0, H / s); | |
| const padL = Math.ceil(Math.max(0, dx)), padR = Math.ceil(Math.max(0, W - (dx + dw))); | |
| if (padL > 0) ctx.drawImage(img, 0, sy0, 1, syh, 0, 0, padL, H); | |
| if (padR > 0) ctx.drawImage(img, sw - 1, sy0, 1, syh, W - padR, 0, padR, H); | |
| ctx.drawImage(img, dx, dy, dw, dh); | |
| if (withLabel) drawAiDisclosureOnCanvas(ctx, W, H); | |
| return canvas; | |
| } | |
| function ExportModal({ current, aiLabel, onClose }) { | |
| const [preset, setPreset] = useState('mall'); | |
| const [zoom, setZoom] = useState(1); | |
| const [off, setOff] = useState({ x: 0, y: 0 }); | |
| const imgRef = useRef(null); | |
| const [ready, setReady] = useState(false); | |
| const canvasRef = useRef(null); | |
| const dragRef = useRef(null); | |
| const p = EXPORT_PRESETS.find(x => x.key === preset); | |
| useEffect(() => { // ์๋ณธ ๋ก๋ (1ํ) | |
| const img = new Image(); | |
| img.onload = () => { imgRef.current = img; setReady(true); }; | |
| img.src = current.imageUrl; | |
| }, [current.imageUrl]); | |
| useEffect(() => { setZoom(1); setOff({ x: 0, y: 0 }); }, [preset]); | |
| useEffect(() => { // ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ ๋ | |
| const img = imgRef.current, cv = canvasRef.current; | |
| if (!ready || !img || !cv || !p.w) return; | |
| const out = renderChannelCanvas(img, p.w, p.h, zoom, off.x, off.y, aiLabel); | |
| cv.width = out.width; cv.height = out.height; | |
| cv.getContext('2d').drawImage(out, 0, 0); | |
| }, [ready, preset, zoom, off, aiLabel]); | |
| const startDrag = (e) => { | |
| if (!p.w) return; | |
| e.preventDefault(); | |
| dragRef.current = { x: e.clientX, y: e.clientY, ox: off.x, oy: off.y }; | |
| const scale = p.h / (canvasRef.current?.getBoundingClientRect().height || p.h); | |
| const move = (ev) => { | |
| const d = dragRef.current; if (!d) return; | |
| setOff({ x: d.ox + (ev.clientX - d.x) * scale, y: d.oy + (ev.clientY - d.y) * scale }); | |
| }; | |
| const up = () => { dragRef.current = null; window.removeEventListener('pointermove', move); window.removeEventListener('pointerup', up); }; | |
| window.addEventListener('pointermove', move); window.addEventListener('pointerup', up); | |
| }; | |
| const save = () => { | |
| const base = `clovis_${current.meta.shot}_${current.meta.angle}_${current.id}`; | |
| if (!p.w) { downloadWithLabel(current.imageUrl, `${base}.png`, aiLabel); return; } | |
| const out = renderChannelCanvas(imgRef.current, p.w, p.h, zoom, off.x, off.y, aiLabel); | |
| const a = document.createElement('a'); | |
| a.href = out.toDataURL('image/png'); a.download = `${base}${p.suffix}.png`; a.click(); | |
| }; | |
| return h('div', { className: 'fixed inset-0 z-50 bg-black/80 flex items-center justify-center animate-fadeIn', onClick: onClose }, | |
| h('div', { className: 'bg-[#222] rounded-2xl border border-[#333] w-[min(720px,94vw)] max-h-[92vh] overflow-y-auto p-5 flex flex-col gap-4', onClick: e => e.stopPropagation() }, | |
| h('div', { className: 'flex items-center justify-between' }, | |
| h('h3', { className: 'text-[15px] font-semibold' }, '๋ค์ด๋ก๋ โ ์ฑ๋ ์ฌ์ด์ฆ'), | |
| h('button', { type: 'button', onClick: onClose, className: 'text-gray-500 hover:text-white' }, h(X, { size: 18 }))), | |
| // ์ฑ๋ ์ ํ | |
| h('div', { className: 'grid grid-cols-3 gap-2' }, EXPORT_PRESETS.map(x => | |
| h('button', { key: x.key, type: 'button', onClick: () => setPreset(x.key), | |
| className: `rounded-xl border px-2 py-2.5 text-center transition-colors ${preset === x.key ? 'border-brand-blue bg-brand-blue/10' : 'border-[#3a3a3a] hover:border-[#4b5563]'}` }, | |
| h('div', { className: `text-[12.5px] font-semibold leading-tight ${preset === x.key ? 'text-white' : 'text-gray-300'}` }, x.label), | |
| h('div', { className: 'text-[11px] text-gray-500 mt-0.5' }, x.desc)))), | |
| // ๋ฏธ๋ฆฌ๋ณด๊ธฐ | |
| p.w | |
| ? h('div', { className: 'flex flex-col items-center gap-3' }, | |
| h('div', { className: 'relative' }, | |
| h('canvas', { ref: canvasRef, onPointerDown: startDrag, | |
| className: 'max-h-[52vh] w-auto max-w-full rounded-lg border border-[#3a3a3a] bg-white cursor-grab active:cursor-grabbing select-none touch-none' }), | |
| h('div', { className: 'absolute bottom-2 left-1/2 -translate-x-1/2 text-[10.5px] text-gray-400 bg-black/55 rounded-full px-2.5 py-0.5 pointer-events-none' }, '๋๋๊ทธ๋ก ์์น ์กฐ์ ')), | |
| h('div', { className: 'w-full max-w-[420px] flex items-center gap-3' }, | |
| h('span', { className: 'text-[11.5px] text-gray-500 shrink-0' }, '๋ชจ๋ธ ํฌ๊ธฐ'), | |
| h('input', { type: 'range', min: 100, max: 180, value: Math.round(zoom * 100), | |
| onChange: e => setZoom(e.target.value / 100), className: 'flex-1 accent-[#3B82F6]' }), | |
| h('span', { className: 'text-[11.5px] text-gray-400 w-10 text-right font-mono' }, `${Math.round(zoom * 100)}%`), | |
| h('button', { type: 'button', onClick: () => { setZoom(1); setOff({ x: 0, y: 0 }); }, | |
| className: 'text-[11.5px] text-gray-500 hover:text-gray-300 shrink-0' }, '์ด๊ธฐํ')), | |
| h('p', { className: 'text-[11.5px] text-gray-500 text-center leading-relaxed m-0' }, | |
| '100% = ์ ์ฒด๊ฐ ๋ค ๋ค์ด๊ฐ๋ ์ํ (์ข์ฐ๋ ๋ฐฐ๊ฒฝ ์ฐ์ฅ). ์ฌ๋ผ์ด๋๋ฅผ ์ฌ๋ฆฌ๋ฉด ์์๋ ์ฌ๋ฐฑ๋ถํฐ ์๋ฆฌ๋ฉฐ ๋ชจ๋ธ์ด ์ปค์ง๋๋ค.')) | |
| : h('p', { className: 'text-[12.5px] text-gray-400 text-center py-6 m-0' }, '์์ฑ๋ ์๋ณธ(1536ร2048)์ ๊ทธ๋๋ก ์ ์ฅํฉ๋๋ค.'), | |
| // ์ ์ฅ | |
| h('div', { className: 'flex items-center justify-between gap-3' }, | |
| h('span', { className: 'text-[11.5px] text-gray-500' }, aiLabel ? "'AI ์์ฑ ์ด๋ฏธ์ง' ํ๊ธฐ ํฌํจ" : 'AI ํ๊ธฐ ์์'), | |
| h('button', { type: 'button', onClick: save, | |
| className: 'h-10 px-5 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 }), p.w ? `${p.desc} ์ ์ฅ` : '์๋ณธ ์ ์ฅ')))); | |
| } | |
| // ๋น๋ก๊ทธ์ธ ์ฌ์ฉ์๋ ์์ ์ ๋ค์ ๋ถ๋ฌ์ฌ ์ ์๋๋ก ๋ธ๋ผ์ฐ์ ๋ณ ID๋ฅผ ๋ณด๊ด (๋ก๊ทธ์ธ ์์ ์๋ฒ๊ฐ ๊ณ์ ๋ช ์ผ๋ก ๋ฌถ์) | |
| const CLIENT_ID = (() => { | |
| try { | |
| let id = localStorage.getItem('clovis_client_id'); | |
| if (!id) { id = crypto.randomUUID(); localStorage.setItem('clovis_client_id', id); } | |
| return id; | |
| } catch { return 'c-' + Math.random().toString(36).slice(2); } | |
| })(); | |
| const apiHeaders = (json = false) => ({ 'X-Client-Id': CLIENT_ID, ...(json ? { 'Content-Type': 'application/json' } : {}) }); | |
| // ์ ์ถ โ jobId โ ํด๋ง. ๊ธด HTTP ์ฐ๊ฒฐ์ ์ก๊ณ ์์ง ์์ผ๋ฏ๋ก Space ํ๋ก์ ํ์์์๊ณผ ๋ฌด๊ด. | |
| async function submitToComfy(payload) { | |
| const res = await fetch('/api/comfy/generate', { method: 'POST', headers: apiHeaders(true), body: JSON.stringify(payload) }); | |
| if (!res.ok) { const e = await res.json().catch(() => ({})); throw new Error(e.detail || `HTTP ${res.status}`); } | |
| return (await res.json()).jobId; | |
| } | |
| async function pollComfyJob(jobId, onProgress) { | |
| let misses = 0; | |
| while (true) { | |
| await sleep(3000); | |
| let r; | |
| try { r = await fetch(`/api/comfy/jobs/${jobId}`, { headers: apiHeaders() }); } catch { if (++misses > 10) throw new Error('์๋ฒ ์๋ต์ด ์์ต๋๋ค.'); continue; } | |
| if (r.status === 404) throw new Error('์์ ์ ๋ณด๋ฅผ ์์ด๋ฒ๋ ธ์ต๋๋ค (์๋ฒ ์ฌ์์). ๋ค์ ์๋ํด์ฃผ์ธ์.'); | |
| if (!r.ok) { if (++misses > 10) throw new Error(`HTTP ${r.status}`); continue; } | |
| misses = 0; | |
| const j = await r.json(); | |
| onProgress?.(j); | |
| if (j.status === 'done') return j; | |
| if (j.status === 'cancelled') return null; // ์ฌ์ฉ์ ์ทจ์ โ ์กฐ์ฉํ ์ข ๋ฃ | |
| if (j.status === 'error') throw new Error(j.error || '์์ฑ ์คํจ'); | |
| } | |
| } | |
| const fmtSec = (s) => { s = Math.round(s || 0); return s >= 60 ? `${Math.floor(s / 60)}๋ถ ${s % 60}์ด` : `${s}์ด`; }; | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| // UI atoms | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const SectionTitle = ({ children, right }) => h('div', { className: 'flex items-center justify-between mb-2.5' }, | |
| h('h3', { className: 'text-[13px] font-semibold text-gray-200 tracking-tight' }, children), right || null); | |
| const Segmented = ({ options, value, onChange, cols }) => h('div', { | |
| className: `grid gap-1.5`, style: { gridTemplateColumns: `repeat(${cols || options.length}, minmax(0, 1fr))` } }, | |
| options.map(o => h('button', { | |
| key: o, type: 'button', onClick: () => onChange(o), | |
| className: `px-2 py-2 rounded-lg text-[12.5px] font-medium border transition-colors ${value === o | |
| ? 'bg-brand-blue border-brand-blue text-white' | |
| : 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}` | |
| }, o))); | |
| const UploadTile = ({ slot, value, onChange, disabled }) => { | |
| const inputRef = useRef(null); | |
| const [drag, setDrag] = useState(false); | |
| const handleFiles = async (files) => { | |
| const f = files?.[0]; if (!f || !f.type.startsWith('image/')) return; | |
| onChange(await fileToDataUrl(f), f.name); | |
| }; | |
| return h('div', { | |
| className: `relative rounded-xl border overflow-hidden group ${drag ? 'drop-active' : ''} ${value ? 'border-[#3a3a3a]' : 'border-dashed border-[#3a3a3a] bg-[#212121] hover:border-[#4b5563]'}`, | |
| style: { aspectRatio: '3 / 4' }, | |
| onDragOver: e => { e.preventDefault(); setDrag(true); }, onDragLeave: () => setDrag(false), | |
| onDrop: e => { e.preventDefault(); setDrag(false); if (!disabled) handleFiles(e.dataTransfer.files); }, | |
| onClick: () => !disabled && !value && inputRef.current?.click(), | |
| }, | |
| h('input', { ref: inputRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: e => { handleFiles(e.target.files); e.target.value = ''; } }), | |
| value | |
| ? h(React.Fragment, null, | |
| h('img', { src: value, className: 'w-full h-full object-cover bg-white', alt: slot.label }), | |
| !disabled && h('button', { type: 'button', onClick: e => { e.stopPropagation(); onChange(null, null); }, | |
| 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 })), | |
| 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)) | |
| : h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-1 text-gray-500 cursor-pointer' }, | |
| h(ImagePlus, { size: 18 }), | |
| h('span', { className: 'text-[11.5px] text-gray-300' }, slot.label, slot.required && h('span', { className: 'text-brand-blue ml-0.5' }, '*')), | |
| slot.hint && h('span', { className: 'text-[10px] text-gray-500 px-2 text-center leading-tight' }, slot.hint)) | |
| ); | |
| }; | |
| const DetailTile = ({ value, onChange, disabled }) => { | |
| const inputRef = useRef(null); | |
| const handleFiles = async (files) => { | |
| const f = files?.[0]; if (!f || !f.type.startsWith('image/')) return; | |
| onChange(await fileToDataUrl(f, 1024), f.name); | |
| }; | |
| return h('div', { | |
| className: `relative w-full rounded-lg overflow-hidden group ${value ? 'border border-[#3a3a3a]' : 'border border-dashed border-[#3a3a3a] bg-[#212121] hover:border-[#4b5563]'} ${disabled ? 'opacity-60 border-[#333]' : ''}`, | |
| style: { aspectRatio: '1 / 1' }, | |
| onDragOver: e => e.preventDefault(), onDrop: e => { e.preventDefault(); if (!disabled) handleFiles(e.dataTransfer.files); }, | |
| onClick: () => !disabled && !value && inputRef.current?.click(), | |
| }, | |
| h('input', { ref: inputRef, type: 'file', accept: 'image/*', className: 'hidden', onChange: e => { handleFiles(e.target.files); e.target.value = ''; } }), | |
| value | |
| ? h(React.Fragment, null, | |
| h('img', { src: value, className: 'w-full h-full object-cover bg-white' }), | |
| !disabled && h('button', { type: 'button', onClick: e => { e.stopPropagation(); onChange(null, null); }, | |
| className: 'absolute top-1 right-1 w-5 h-5 rounded-full bg-black/70 text-white flex items-center justify-center opacity-0 group-hover:opacity-100' }, h(X, { size: 11 }))) | |
| : h('div', { className: 'absolute inset-0 flex items-center justify-center text-gray-600 cursor-pointer' }, h(ImagePlus, { size: 14 }))); | |
| }; | |
| const FaceTile = ({ preset, selected, onClick }) => h('button', { | |
| type: 'button', onClick, title: preset.label, | |
| className: `relative rounded-xl overflow-hidden border-2 transition-colors ${selected ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}`, | |
| style: { aspectRatio: '1 / 1' } }, | |
| h('img', { src: preset.url, className: 'w-full h-full object-cover', alt: preset.label }), | |
| 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' })), | |
| 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)); | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| // App | |
| // โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| function App() { | |
| const [user, setUser] = useState({ username: 'anonymous', is_logged_in: false, oauth_enabled: false }); | |
| const [health, setHealth] = useState(null); | |
| const age = '์ฑ์ธ'; // CLOVIS: ์ฑ์ธ ๊ณ ์ | |
| const [facePreset, setFacePreset] = useState('preset_17'); | |
| const [detailKinds, setDetailKinds] = useState({}); // 'outer:a' โ kind key | |
| const [faceUpload, setFaceUpload] = useState(null); | |
| const [shot, setShot] = useState('์ ์ ์ปท'); | |
| const [angle, setAngle] = useState('๋ฐ์ธก๋ฉด'); | |
| const [gaze, setGaze] = useState('์์ฐ์ค๋ฌ์ด ์์ '); | |
| const [prompt, setPrompt] = useState(''); | |
| const [details, setDetails] = useState(Object.fromEntries(Object.entries(DETAIL_OPTIONS).map(([k, v]) => [k, v.def]))); | |
| const [detailTab, setDetailTab] = useState('top'); | |
| const [images, setImages] = useState({}); | |
| const [imageNames, setImageNames] = useState({}); // ์ฌ๋กฏ๋ณ ์๋ณธ ํ์ผ๋ช (Dataset ๋ก๊ทธยท์คํ์ผ์ฝ๋ ์ง๊ณ์ฉ) | |
| const [faceUploadName, setFaceUploadName] = useState(null); | |
| const [poseSpec, setPoseSpec] = useState(''); // ํฌ์ฆ ์ง์ ๋ฌธ์ฅ (๋น์ฐ๋ฉด GPT ๋น์ ์ด ๋ ํผ๋ฐ์ค์์ ์๋ ์ถ์ถ) | |
| const [jobs, setJobs] = useState([]); // ์งํ ์ค/์คํจ ์์ [{id, jobId, meta, stageLabel, startedAt, error}] | |
| const [tick, setTick] = useState(0); // ๊ฒฝ๊ณผ์๊ฐ ํ์์ฉ 1์ด ํ์ด๋จธ | |
| const [results, setResults] = useState([]); // [{id, imageUrl, meta, elapsedSec}] | |
| const [current, setCurrent] = useState(null); | |
| const [error, setError] = useState(null); | |
| const [aiLabel, setAiLabel] = useState(true); | |
| const [lightbox, setLightbox] = useState(false); // ๊ฒฐ๊ณผ ์ด๋ฏธ์ง ํ๋ ๋ณด๊ธฐ | |
| const [exportOpen, setExportOpen] = useState(false); // ์ฑ๋ ์ฌ์ด์ฆ ๋ค์ด๋ก๋ ๋ชจ๋ฌ | |
| const [resultTab, setResultTab] = useState('session'); // 'session' | 'history' | |
| const [hist, setHist] = useState({ items: null, loading: false, error: null, truncated: false }); | |
| const [showSpecs, setShowSpecs] = useState(false); // ์์ ๋ถ์ ๊ฒฐ๊ณผ / ์ต์ข ํ๋กฌํํธ ํผ์น๊ธฐ | |
| useEffect(() => { | |
| if (!lightbox) return; | |
| const onKey = (e) => { if (e.key === 'Escape') setLightbox(false); }; | |
| window.addEventListener('keydown', onKey); | |
| return () => window.removeEventListener('keydown', onKey); | |
| }, [lightbox]); | |
| const faceFileRef = useRef(null); | |
| useEffect(() => { | |
| fetch('/api/whoami').then(r => r.ok ? r.json() : null).then(d => d && setUser(d)).catch(() => {}); | |
| fetch('/api/comfy/health').then(r => r.ok ? r.json() : { ok: false, error: '๋ธ๋ฆฌ์ง ๋ผ์ฐํธ๊ฐ ์์ต๋๋ค' }).then(setHealth).catch(() => setHealth({ ok: false, error: '์ํ ํ์ธ ์คํจ' })); | |
| }, []); | |
| const activeJobs = jobs.filter(j => !j.error); | |
| useEffect(() => { | |
| if (activeJobs.length === 0) return; | |
| const id = setInterval(() => setTick(t => t + 1), 1000); | |
| return () => clearInterval(id); | |
| }, [activeJobs.length]); | |
| const presets = ADULT_FACE_PRESETS; | |
| const setImg = (key, v, name) => { | |
| setImages(prev => ({ ...prev, [key]: v })); setImageNames(prev => ({ ...prev, [key]: v ? (name || null) : null })); | |
| if (key === 'pose' && !v) { if (angle === '๋ ํผ๋ฐ์ค ๋ฐ๋ฆ') setAngle('๋ฐ์ธก๋ฉด'); if (gaze === '๋ ํผ๋ฐ์ค ๋ฐ๋ฆ') setGaze('์์ฐ์ค๋ฌ์ด ์์ '); } | |
| }; | |
| const kindOf = (g, slot) => { // ์ ์ฅ๋ ๊ฐ์ด ๊ทธ ์ท ์ข ๋ฅ์ ์์ผ๋ฉด ๊ธฐ๋ณธ๊ฐ์ผ๋ก | |
| const list = DETAIL_KINDS_BY_GARMENT[g] || []; | |
| const v = detailKinds[`${g}:${slot}`]; | |
| return list.some(k => k.key === v) ? v : defaultKind(g, slot); | |
| }; | |
| const detailList = DETAIL_GARMENTS.flatMap(g => DETAIL_SLOTS.map(slot => ({ garment: g.key, kind: kindOf(g.key, slot), image: images[`detail:${g.key}:${slot}`], filename: imageNames[`detail:${g.key}:${slot}`] }))) | |
| .filter(x => x.image && images[x.garment]); | |
| const detailCount = detailList.length; | |
| const missing = []; | |
| if (!images.outer && !images.top && !images.bottom) missing.push('์์ 1๊ฐ ์ด์ (์์ฐํฐยท์์ยทํ์)'); | |
| const canGenerate = missing.length === 0 && (faceUpload || facePreset) && health?.ok; | |
| // ํ๋์ payload ๋ก ์์ 1๊ฑด ์์. payload ๋ ๊ฒฐ๊ณผ์ ํจ๊ป ๋ณด๊ด๋์ด "์ด ์ค์ ์ผ๋ก ๋ค์ ์์ฑ"์ ์ฐ์ธ๋ค. | |
| const startJob = async (payload, meta) => { | |
| const id = Date.now().toString(36) + Math.random().toString(36).slice(2, 5); | |
| setJobs(prev => [...prev, { id, meta, payload, stageLabel: '์์ฒญ ์ ์ก ์ค', startedAt: Date.now() }]); | |
| const patch = (p) => setJobs(prev => prev.map(j => j.id === id ? { ...j, ...p } : j)); | |
| let jobId; | |
| try { | |
| jobId = await submitToComfy(payload); | |
| } catch (e) { | |
| patch({ error: e.message }); return; | |
| } | |
| patch({ jobId, stageLabel: '๋๊ธฐ ์ค' }); | |
| await trackJob(id, jobId, meta, patch, payload); | |
| }; | |
| const buildPayload = () => { | |
| const meta = { shot, angle, gaze, age, prompt, face: faceUpload ? '์ ๋ก๋' : (presets.find(p => p.id === facePreset)?.label || facePreset) }; | |
| const mainImages = Object.fromEntries(Object.entries(images).filter(([k, v]) => v && !k.startsWith('detail:'))); | |
| return { face: faceUpload || facePreset, faceFilename: faceUpload ? faceUploadName : null, images: mainImages, imageFilenames: imageNames, | |
| details: detailList.slice(0, DETAIL_MAX).map(x => ({ garment: x.garment, kind: x.kind, image: x.image, filename: x.filename || null })), | |
| poseSpec: (images.pose || poseSpec.trim()) ? poseSpec.trim() : '', | |
| options: { shot, angle, gaze, age, ...details }, prompt, meta }; | |
| }; | |
| const handleGenerate = () => { | |
| if (user.oauth_enabled && !user.is_logged_in) { alert("๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค. ์ฐ์ธก ์๋จ์ 'Hugging Face๋ก ๋ก๊ทธ์ธ' ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์."); return; } | |
| if (!canGenerate) return; | |
| setError(null); | |
| const payload = buildPayload(); | |
| startJob(payload, payload.meta); | |
| }; | |
| // ์ง๋ ๊ธฐ๋ก: HF Dataset ์ ์๊ตฌ ์ ์ฅ๋ ๋ณธ์ธ ์์ฑ ์ด๋ ฅ (์ธ์ ๊ณผ ๋ฌด๊ดํ๊ฒ ์ ์ง๋จ) | |
| const loadHistory = async (refresh = false) => { | |
| setHist(prev => ({ ...prev, loading: true, error: null })); | |
| try { | |
| const r = await fetch(`/api/my/history${refresh ? '?refresh=1' : ''}`, { headers: apiHeaders() }); | |
| if (!r.ok) throw new Error(r.status === 401 ? '๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.' : '๊ธฐ๋ก์ ๋ถ๋ฌ์ค์ง ๋ชปํ์ต๋๋ค.'); | |
| const j = await r.json(); | |
| const items = (j.items || []).map(it => ({ | |
| id: `hist_${it.ts}`, history: true, | |
| imageUrl: it.imageUrl, thumbUrl: it.thumbUrl || it.imageUrl, | |
| meta: { shot: it.shot, angle: it.angle, gaze: it.gaze, age: '์ฑ์ธ', face: it.face, prompt: it.prompt }, | |
| elapsedSec: it.elapsed, createdAt: it.time, finalPrompt: it.fullPrompt || null, | |
| garmentSpecs: null, poseSpec: null, | |
| })); | |
| setHist({ items, loading: false, error: null, truncated: !!j.truncated }); | |
| } catch (e) { | |
| setHist(prev => ({ ...prev, loading: false, error: e.message })); | |
| } | |
| }; | |
| useEffect(() => { if (resultTab === 'history' && hist.items === null && !hist.loading) loadHistory(); }, [resultTab]); | |
| // ์ธ์ ๊ฒฐ๊ณผ ์ญ์ : ํ๋ฉด์์ ์ ๊ฑฐ + ์๋ฒ ๋ณด๊ด๋ถ๋ ์ญ์ ํด ์๋ก๊ณ ์นจ ๋ณต๊ตฌ๋ฅผ ๋ง์ | |
| const deleteResult = async (r) => { | |
| if (!confirm('์ด ๊ฒฐ๊ณผ๋ฅผ ์ง์ธ๊น์? ๋๋๋ฆด ์ ์์ด์.')) return; | |
| setResults(prev => { | |
| const next = prev.filter(x => x.id !== r.id); | |
| setCurrent(cur => (cur?.id === r.id ? (next[0] || null) : cur)); | |
| return next; | |
| }); | |
| try { if (r.jobId) await fetch(`/api/comfy/jobs/${r.jobId}`, { method: 'DELETE', headers: apiHeaders() }); } catch {} | |
| }; | |
| // ์ธ์ ๊ฒฐ๊ณผ์ ๋ณด๊ด๋ payload ๋ก ๋์ผ ์กฐ๊ฑด ์ฌ์์ฑ (ํ์ฌ ํผ ์ํ๋ ๊ฑด๋๋ฆฌ์ง ์์) | |
| const regenFrom = (r) => { | |
| if (user.oauth_enabled && !user.is_logged_in) { alert("๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค."); return; } | |
| if (!r?.payload) return; | |
| startJob(r.payload, r.meta); | |
| }; | |
| // ์๋ฒ ์์ ์ ์๋ฃ๊น์ง ๋ฐ๋ผ๊ฐ๋ฉฐ ๊ฒฐ๊ณผ/์๋ฌ๋ฅผ ๋ฐ์ (์ ์์ฒญ๊ณผ ์๋ก๊ณ ์นจ ๋ณต๊ตฌ ๋ ๋ค ์ฌ์ฉ) | |
| const trackJob = async (id, jobId, meta, patch, payload = null) => { | |
| try { | |
| const j = await pollComfyJob(jobId, (st) => patch({ stageLabel: st.stageLabel, execStartedAt: st.execStartedAt || null })); | |
| if (!j) { setJobs(prev => prev.filter(x => x.id !== id)); return; } // ์ทจ์๋จ | |
| const item = { id, jobId, imageUrl: j.imageUrl, meta, payload, elapsedSec: j.elapsedSec, createdAt: j.createdAt, garmentSpecs: j.garmentSpecs || null, finalPrompt: j.finalPrompt || null, poseSpec: j.poseSpec || null }; | |
| setResults(prev => prev.some(r => r.id === id) ? prev : [item, ...prev]); | |
| setCurrent(prev => prev || item); | |
| setJobs(prev => prev.filter(x => x.id !== id)); | |
| } catch (e) { | |
| patch({ error: e.message }); | |
| } | |
| }; | |
| const dismissJob = (id) => setJobs(prev => prev.filter(j => j.id !== id)); | |
| const cancelJob = async (job) => { // ์งํ ์ค ์์ ์ทจ์: ์๋ฒ์ ์์ฒญ ํ ์นด๋ ์ ๊ฑฐ (ํด๋ง๋ cancelled ๋ฅผ ๋ณด๊ณ ๋ฉ์ถค) | |
| setJobs(prev => prev.map(x => x.id === job.id ? { ...x, cancelling: true, stageLabel: '์ทจ์ ์ค' } : x)); | |
| try { if (job.jobId) await fetch(`/api/comfy/jobs/${job.jobId}/cancel`, { method: 'POST', headers: apiHeaders() }); } catch {} | |
| setJobs(prev => prev.filter(x => x.id !== job.id)); | |
| }; | |
| // ์๋ก๊ณ ์นจ/์ฌ์ ์ ์ ์๋ฒ์ ๋จ์ ์๋ ๋ด ์์ ๋ณต๊ตฌ | |
| useEffect(() => { | |
| (async () => { | |
| try { | |
| const r = await fetch('/api/comfy/jobs', { headers: apiHeaders() }); | |
| if (!r.ok) return; | |
| const { jobs: saved } = await r.json(); | |
| const done = saved.filter(j => j.status === 'done' && j.imageUrl) | |
| .map(j => ({ id: j.id, jobId: j.id, imageUrl: j.imageUrl, meta: j.meta || {}, elapsedSec: j.elapsedSec, createdAt: j.createdAt, garmentSpecs: j.garmentSpecs || null, finalPrompt: j.finalPrompt || null, poseSpec: j.poseSpec || null })) | |
| .sort((a, b) => b.createdAt - a.createdAt); | |
| if (done.length) { setResults(done); setCurrent(prev => prev || done[0]); } | |
| const pending = saved.filter(j => j.status !== 'done' && j.status !== 'cancelled'); | |
| if (pending.length) { | |
| 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 }))); | |
| for (const j of pending.filter(x => x.status === 'running')) { | |
| const patch = (p) => setJobs(prev => prev.map(x => x.id === j.id ? { ...x, ...p } : x)); | |
| trackJob(j.id, j.id, j.meta || {}, patch); | |
| } | |
| } | |
| } catch {} | |
| })(); | |
| }, []); | |
| // โโ Left: settings โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| 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]' }, | |
| h('div', { className: 'p-5 space-y-6' }, | |
| h('section', null, | |
| h(SectionTitle, null, '์ผ๊ตด'), | |
| h('div', { className: 'grid grid-cols-4 gap-2' }, | |
| presets.map(p => h(FaceTile, { key: p.id, preset: p, selected: !faceUpload && facePreset === p.id, onClick: () => { setFaceUpload(null); setFacePreset(p.id); } })), | |
| h('button', { type: 'button', onClick: () => faceFileRef.current?.click(), | |
| 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' } }, | |
| faceUpload | |
| ? h(React.Fragment, null, h('img', { src: faceUpload, className: 'w-full h-full object-cover' }), | |
| 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 })), | |
| h('div', { className: 'absolute bottom-0 inset-x-0 py-0.5 bg-black/60 text-[10.5px] text-center' }, '์ ๋ก๋')) | |
| : 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]' }, '์ง์ ์ ๋ก๋'))), | |
| 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 = ''; } }))), | |
| h('section', null, h(SectionTitle, null, '์ท ์ ํ'), h(Segmented, { options: SHOT_OPTIONS, value: shot, cols: 3, onChange: setShot })), | |
| h('section', null, | |
| h(SectionTitle, { right: images.pose && h('span', { className: 'text-[11px] text-gray-500' }, "'๋ ํผ๋ฐ์ค ๋ฐ๋ฆ' = ํฌ์ฆ ์ฌ์ง์ ์ต๊ธ") }, '์นด๋ฉ๋ผ ์ต๊ธ'), | |
| h(Segmented, { options: images.pose ? ANGLE_OPTIONS : ANGLE_OPTIONS.filter(o => o !== '๋ ํผ๋ฐ์ค ๋ฐ๋ฆ'), value: angle, onChange: setAngle, cols: 4 })), | |
| h('section', null, h(SectionTitle, null, '์์ '), h(Segmented, { options: images.pose ? GAZE_OPTIONS : GAZE_OPTIONS.filter(o => o !== '๋ ํผ๋ฐ์ค ๋ฐ๋ฆ'), value: gaze, onChange: setGaze })), | |
| h('section', null, | |
| h(SectionTitle, null, 'ํ๋กฌํํธ ์์ฑ'), | |
| h('textarea', { value: prompt, onChange: e => setPrompt(e.target.value), rows: 3, | |
| placeholder: '์ถ๊ฐ ์ง์์ฌํญ (์ ํ). ์: ์์ ์ฃผ๋จธ๋์ ๋ฃ๊ณ ์ด์ง ๋ฏธ์, ์๋งค๋ฅผ ํ ๋ฒ ์ ์ด ์ฌ๋ฆฐ ์คํ์ผ๋ง', | |
| 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' })), | |
| h('section', null, | |
| h(SectionTitle, { right: h('span', { className: 'text-[11px] text-gray-500' }, '์์ฐํฐยท์์ยทํ์ ์ค 1๊ฐ ์ด์') }, '์ด๋ฏธ์ง ์ ๋ก๋'), | |
| h('div', { className: 'grid grid-cols-4 gap-2' }, | |
| IMAGE_SLOTS.map(s => h(UploadTile, { key: s.key, slot: s, value: images[s.key], onChange: (v, name) => setImg(s.key, v, name) })))), | |
| (images.pose || poseSpec) && (health?.ok && health.poseText !== false) && h('section', { className: 'animate-fadeIn' }, | |
| h(SectionTitle, { right: h('span', { className: 'text-[11px] text-gray-500' }, '๋น์ฐ๋ฉด ๋ ํผ๋ฐ์ค์์ ์๋ ์ถ์ถ') }, 'ํฌ์ฆ ์ง์ (์ ํ)'), | |
| h('textarea', { value: poseSpec, onChange: e => setPoseSpec(e.target.value), rows: 3, | |
| placeholder: '์: ์ค๋ฅธํ์ ๋ค์ด ์๋ฑ์ ์ค๋ฅธ์ชฝ ๊ด์๋์ด์ ๊ฐ๋ณ๊ฒ ๋๋ค. ์ผํ์ ์์ฐ์ค๋ฝ๊ฒ ๋ด๋ฆฌ๊ณ ์ฒด์ค์ ์ผ๋ฐ์. ๋ชธํต์ ์นด๋ฉ๋ผ ์ชฝ์ผ๋ก ์ด์ง ์ฐ์ธก.', | |
| className: 'w-full rounded-xl bg-[#242424] border border-[#333] px-3 py-2.5 text-[12.5px] text-gray-100 placeholder-gray-500 focus:outline-none focus:border-brand-blue' }), | |
| h('p', { className: 'text-[11px] text-gray-500 mt-1.5 leading-relaxed' }, '๋ ํผ๋ฐ์ค ํฌ์ฆ๋ฅผ ๋ฌธ์ฅ์ผ๋ก ๋ฐ๊ฟ ํ๋กฌํํธ ๋งจ ๋์ ์ต์ฐ์ ์ง์๋ก ๋ฃ์ด์. ๊ฒฐ๊ณผ๊ฐ ๋์ค๋ฉด ์๋ ํจ๋์์ ์๋ ์ถ์ถ๋ ๋ฌธ์ฅ์ ํ์ธํ๊ณ , ํ๋ฆฐ ๋ถ๋ถ์ ์ฌ๊ธฐ์ ๊ณ ์ณ ๋ค์ ์์ฑํ ์ ์์ด์.')), | |
| h('section', null, | |
| h(SectionTitle, null, '๊ธธ์ด ยท ํ'), | |
| h('div', { className: 'flex gap-1.5 mb-3' }, | |
| DETAIL_GROUPS.map(g => h('button', { | |
| key: g.key, type: 'button', onClick: () => setDetailTab(g.key), | |
| className: `px-3 py-1.5 rounded-lg text-[12.5px] font-semibold transition-colors ${detailTab === g.key | |
| ? 'bg-brand-blue text-white' | |
| : (images[g.key] ? 'bg-[#2a2a2a] text-gray-200 hover:bg-[#333]' : 'bg-[#242424] text-gray-500 hover:text-gray-300')}` | |
| }, 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))), | |
| (() => { | |
| const g = DETAIL_GROUPS.find(x => x.key === detailTab); | |
| const rows = [['๊ธธ์ด', g.length], ['ํ', g.fit]]; | |
| return h('div', { key: g.key, className: 'space-y-2 animate-fadeIn' }, | |
| rows.map(([label, k]) => h('div', { key: k, className: 'grid grid-cols-[52px_1fr] items-center gap-2' }, | |
| h('span', { className: 'text-[12px] text-gray-400' }, label), | |
| h('div', { className: 'flex flex-wrap gap-1.5' }, | |
| DETAIL_OPTIONS[k].options.map(o => h('button', { | |
| key: o, type: 'button', onClick: () => setDetails(d => ({ ...d, [k]: o })), | |
| className: `px-3 py-1.5 rounded-lg text-[12.5px] font-medium border transition-colors ${details[k] === o | |
| ? 'bg-brand-blue border-brand-blue text-white' | |
| : 'bg-[#242424] border-[#333] text-gray-300 hover:border-[#4b5563] hover:text-white'}` | |
| }, o))))), | |
| !images[g.key] && h('p', { className: 'text-[11px] text-gray-500 pt-1' }, `${g.label} ์ด๋ฏธ์ง๋ฅผ ์ฌ๋ฆฌ์ง ์์ผ๋ฉด ์ด ์ค์ ์ ์ฌ์ฉ๋์ง ์์์.`)); | |
| })()), | |
| h('section', null, | |
| h(SectionTitle, { right: h('span', { className: `text-[11px] ${detailCount >= DETAIL_MAX ? 'text-amber-400' : 'text-gray-500'}` }, `์ ํ ยท ${detailCount}/${DETAIL_MAX}์ฅ`) }, '๋ํ ์ผ ์ฐธ์กฐ'), | |
| health?.ok && health.detailCuts === false | |
| ? h('p', { className: 'text-[11.5px] text-gray-500' }, 'ํ์ฌ ๋ฐฐํฌ๋ ์ํฌํ๋ก์ฐ(workflow_api.json)์ ๋ํ ์ผ ์ฐธ์กฐ ์ ๋ ฅ์ด ์์ด ์ฌ์ฉํ ์ ์์ด์. v5 ์ํฌํ๋ก์ฐ๋ฅผ Export (API)ํด์ ๊ต์ฒดํด์ฃผ์ธ์.') | |
| : h(React.Fragment, null, | |
| h('p', { className: 'text-[11px] text-gray-500 mb-2.5 leading-relaxed' }, 'ํด๋ก์ฆ์ ์ ์ฌ๋ฆฌ๊ณ ์ด๋ค ๋ถ์์ธ์ง ๊ณจ๋ผ์ฃผ์ธ์ (์ท ์ข ๋ฅ๋ณ๋ก ํญ๋ชฉ์ด ๋ฌ๋ผ์). ์กฐ์ง๊ฐยท์์ฌ๋ ์ท ์ ์ฒด์, ๋๋จธ์ง๋ ๊ทธ ๋ถ์์๋ง ๋ฐ์ํ๊ณ ์ค๋ฃจ์ฃ์ ๋ฉ์ธ ์ฌ์ง ๊ทธ๋๋ก ์ ์งํ๋๋ก ์ ๋ฌ๋ผ์. ์ฐธ์กฐ๊ฐ ๋ง์ผ๋ฉด ์ ํ๋๊ฐ ๋จ์ด์ ธ์ ์ ์ฒด 4์ฅ๊น์ง๋ง.'), | |
| h('div', { className: 'grid grid-cols-2 gap-x-4 gap-y-2.5' }, | |
| DETAIL_GARMENTS.map(g => { | |
| const enabled = !!images[g.key]; | |
| return h('div', { key: g.key, className: 'flex items-center gap-2' }, | |
| h('span', { className: `w-14 shrink-0 text-[12px] ${enabled ? 'text-gray-300' : 'text-gray-600'}`, title: enabled ? '' : `${g.label} ์ด๋ฏธ์ง๋ฅผ ๋จผ์ ์ฌ๋ ค์ฃผ์ธ์` }, g.label), | |
| DETAIL_SLOTS.map(slot => { | |
| const id = `${g.key}:${slot}`; | |
| const cur = images[`detail:${id}`]; | |
| const kind = kindOf(g.key, slot); | |
| const kindList = DETAIL_KINDS_BY_GARMENT[g.key] || []; | |
| const kindObj = kindList.find(k => k.key === kind) || kindList[0]; | |
| return h('div', { key: slot, className: 'w-16 flex flex-col items-center gap-1' }, | |
| h(DetailTile, { value: cur, disabled: !enabled || (!cur && detailCount >= DETAIL_MAX), onChange: (v, name) => setImg(`detail:${id}`, v, name) }), | |
| // ์ข ๋ฅ ์ ํ ์นฉ โ ๋ค์ดํฐ๋ธ select ๋ฅผ ๋ฒํผ์ฒ๋ผ ๋ณด์ด๊ฒ (appearance-none + ์ปค์คํ ํ์ดํ) | |
| h('div', { className: 'relative w-full', title: enabled ? `${kindObj.label} ยท ํด๋ฆญํด์ ๋ถ์ ๋ณ๊ฒฝ` : '' }, | |
| h('select', { | |
| value: kind, disabled: !enabled, | |
| onChange: e => setDetailKinds(prev => ({ ...prev, [id]: e.target.value })), | |
| style: { appearance: 'none', WebkitAppearance: 'none', MozAppearance: 'none' }, | |
| className: `w-full h-6 rounded-md border text-[10.5px] font-medium pl-1.5 pr-5 cursor-pointer focus:outline-none focus:border-brand-blue transition-colors | |
| ${cur ? 'bg-brand-blue/15 border-brand-blue/60 text-blue-200 hover:bg-brand-blue/25' | |
| : 'bg-[#2a2a2a] border-[#3f3f3f] text-gray-300 hover:border-[#5a5a5a] hover:bg-[#303030]'} | |
| disabled:opacity-40 disabled:cursor-default` | |
| }, kindList.map(k => h('option', { key: k.key, value: k.key, className: 'bg-[#242424] text-gray-200' }, k.short))), | |
| h(ChevronDown, { size: 12, className: `absolute right-1 top-1/2 -translate-y-1/2 pointer-events-none ${cur ? 'text-blue-200' : 'text-gray-400'}` }))); | |
| })); | |
| })))), | |
| h('div', { className: 'pt-3 pb-3 sticky bottom-0 bg-[#1e1e1e] border-t border-[#2a2a2a] -mx-5 px-5' }, | |
| missing.length > 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `ํ์: ${missing.join(', ')}`), | |
| activeJobs.length > 0 && missing.length === 0 && h('p', { className: 'text-[11.5px] text-gray-500 mb-2' }, `${activeJobs.length}๊ฑด ์งํ ์ค โ ์ค์ ์ ๋ฐ๊ฟ ๋ฐ๋ก ๋ค์ ์ปท์ ๊ฑธ์ด๋ ์ ์์ด์`), | |
| h('button', { type: 'button', onClick: handleGenerate, disabled: !canGenerate, | |
| 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'}` }, | |
| h(Sparkles, { size: 16 }), | |
| activeJobs.length > 0 ? `๋ฃฉ๋ถ ์์ฑ (${activeJobs.length}๊ฑด ์งํ ์ค)` : '๋ฃฉ๋ถ ์์ฑ')))); | |
| // โโ Right: result โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const right = h('main', { className: 'flex-1 h-full overflow-y-auto' }, | |
| h('div', { className: 'max-w-5xl mx-auto p-6 lg:p-8' }, | |
| !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' }, | |
| h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, health.error || 'Comfy ๋ธ๋ฆฌ์ง ์ค์ ์ ํ์ธํด์ฃผ์ธ์.')), | |
| 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' }, | |
| h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', null, 'HF OAuth๊ฐ ์ฐ๊ฒฐ๋์ง ์์ ๋ก๊ทธ์ธ ์์ด ๋๊ตฌ๋ ์์ฑํ ์ ์๋ ์ํ์ ๋๋ค. README์ hf_oauth ์ค์ ๊ณผ Space ์ฌ์์์ ํ์ธํด์ฃผ์ธ์.')), | |
| 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' }, | |
| h(AlertTriangle, { size: 16, className: 'shrink-0 mt-0.5' }), h('span', { className: 'break-all' }, error)), | |
| jobs.length > 0 && h('div', { className: 'mb-5 rounded-xl border border-[#2a2a2a] bg-[#202020] overflow-hidden animate-fadeIn' }, | |
| 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' }, | |
| h(RefreshCw, { size: 13, className: activeJobs.length ? 'animate-spin text-brand-blue' : 'text-gray-500' }), | |
| `์งํ ์ค ${activeJobs.length}๊ฑด`, jobs.length - activeJobs.length > 0 ? h('span', { className: 'text-red-300 font-normal' }, ` ยท ์คํจ ${jobs.length - activeJobs.length}๊ฑด`) : null), | |
| 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]' : ''}` }, | |
| h('div', { className: `w-1.5 h-1.5 rounded-full shrink-0 ${j.error ? 'bg-red-400' : 'bg-brand-blue pulse-ring relative'}` }), | |
| h('div', { className: 'flex-1 min-w-0' }, | |
| 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), | |
| h('div', { className: j.error ? 'text-red-300 break-all' : 'text-gray-400' }, | |
| j.error ? j.error : (j.execStartedAt ? `${j.stageLabel} ยท ${fmtSec((Date.now() - j.execStartedAt) / 1000)}` : `${j.stageLabel} ยท ๋๊ธฐ ${fmtSec((Date.now() - j.startedAt) / 1000)}`))), | |
| j.error | |
| ? h('button', { type: 'button', title: '์ง์ฐ๊ธฐ', onClick: () => dismissJob(j.id), className: 'text-gray-500 hover:text-white' }, h(X, { size: 14 })) | |
| : h('button', { type: 'button', title: '์์ ์ทจ์', disabled: j.cancelling, onClick: () => cancelJob(j), | |
| className: 'shrink-0 text-[11.5px] px-2.5 py-1 rounded-lg border border-[#3a3a3a] text-gray-400 hover:text-red-300 hover:border-red-400/50 disabled:opacity-50 transition-colors' }, | |
| j.cancelling ? '์ทจ์ ์คโฆ' : '์ทจ์')))), | |
| h('div', { className: 'grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_200px] gap-6' }, | |
| // ๋ฉ์ธ ๋ทฐ์ด | |
| h('div', { className: 'rounded-2xl bg-[#202020] border border-[#2a2a2a] overflow-hidden relative', style: { minHeight: '60vh' } }, | |
| !current && activeJobs.length > 0 | |
| ? h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center gap-5' }, | |
| h('div', { className: 'shimmer absolute inset-0 opacity-60' }), | |
| 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' })), | |
| h('div', { className: 'relative text-center' }, | |
| h('div', { className: 'text-[15px] font-semibold text-gray-100' }, activeJobs[0].stageLabel), | |
| h('div', { className: 'mt-1 text-[12.5px] text-gray-400 flex items-center justify-center gap-1' }, h(Clock, { size: 12 }), | |
| activeJobs[0].execStartedAt ? `${fmtSec((Date.now() - activeJobs[0].execStartedAt) / 1000)} ๊ฒฝ๊ณผ ยท ๋ณดํต 1~2๋ถ ์์` : '์คํ ์์๋ฅผ ๊ธฐ๋ค๋ฆฌ๋ ์ค')), | |
| h('p', { className: 'relative text-[11.5px] text-gray-500 max-w-xs text-center' }, '์ด ํญ์ ๋ซ์ง ๋ง์ธ์. ์์ฑ์ด ๋๋๋ฉด ์ฌ๊ธฐ์ ์ด๋ฏธ์ง๊ฐ ํ์๋ฉ๋๋ค.')) | |
| : current | |
| ? h('div', { className: 'animate-fadeIn flex flex-col' }, | |
| h('div', { className: 'flex justify-center bg-[#1c1c1c]' }, | |
| h('div', { className: 'relative inline-block' }, | |
| h('img', { src: current.imageUrl, onClick: () => setLightbox(true), title: 'ํด๋ฆญํ๋ฉด ํฌ๊ฒ ๋ณด๊ธฐ', | |
| className: 'max-h-[78vh] w-auto max-w-full block bg-white cursor-zoom-in', alt: '์์ฑ ๊ฒฐ๊ณผ' }), | |
| aiLabel && h('div', { className: 'ai-label-overlay' }, AI_LABEL_TEXT), | |
| h('button', { type: 'button', onClick: () => setLightbox(true), title: 'ํฌ๊ฒ ๋ณด๊ธฐ', | |
| 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 })))), | |
| h('div', { className: 'flex items-center justify-between gap-3 px-4 py-3 border-t border-[#2a2a2a]' }, | |
| h('label', { className: 'flex items-center gap-2 cursor-pointer select-none text-[12.5px] text-gray-300' }, | |
| h('button', { type: 'button', role: 'switch', 'aria-checked': aiLabel, onClick: () => setAiLabel(v => !v), | |
| className: `relative w-9 h-5 rounded-full transition-colors ${aiLabel ? 'bg-brand-blue' : 'bg-[#3a3a3a]'}` }, | |
| h('span', { className: `absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white transition-transform ${aiLabel ? 'translate-x-4' : ''}` })), | |
| h('span', null, "'AI ์์ฑ ์ด๋ฏธ์ง' ํ๊ธฐ"), | |
| h('span', { className: 'text-gray-500' }, aiLabel ? 'ํ๋ฉดยท๋ค์ด๋ก๋์ ํฌํจ' : 'ํ๊ธฐ ์์')), | |
| h('button', { type: 'button', onClick: () => setExportOpen(true), | |
| 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 }), '๋ค์ด๋ก๋'))) | |
| : h('div', { className: 'absolute inset-0 flex flex-col items-center justify-center text-gray-500 gap-2' }, | |
| h(Upload, { size: 28, className: 'opacity-50' }), | |
| h('p', { className: 'text-[13.5px]' }, '์ผ์ชฝ์์ ์ผ๊ตดยท์์์ ๊ณ ๋ฅด๊ณ ๋ฃฉ๋ถ ์์ฑ์ ๋๋ฅด๋ฉด'), | |
| h('p', { className: 'text-[13.5px]' }, 'ํ ๋ฒ์ ๋ชจ๋ธ์ปท์ด ์์ฑ๋ฉ๋๋ค.'))), | |
| // ํ์คํ ๋ฆฌ (์ด๋ฒ ์ธ์ / ์ง๋ ๊ธฐ๋ก) | |
| h('div', null, | |
| h('div', { className: 'flex items-center gap-1 mb-2.5' }, | |
| h('button', { type: 'button', onClick: () => setResultTab('session'), | |
| className: `px-2.5 py-1 rounded-lg text-[12px] font-semibold transition-colors ${resultTab === 'session' ? 'bg-[#2f2f2f] text-white' : 'text-gray-500 hover:text-gray-300'}` }, | |
| `์ด๋ฒ ์ธ์ ${results.length ? `(${results.length})` : ''}`), | |
| h('button', { type: 'button', onClick: () => setResultTab('history'), | |
| className: `px-2.5 py-1 rounded-lg text-[12px] font-semibold transition-colors ${resultTab === 'history' ? 'bg-[#2f2f2f] text-white' : 'text-gray-500 hover:text-gray-300'}` }, | |
| '์ง๋ ๊ธฐ๋ก'), | |
| resultTab === 'history' && h('button', { type: 'button', title: '๊ธฐ๋ก ์๋ก๊ณ ์นจ', onClick: () => loadHistory(true), disabled: hist.loading, | |
| className: 'ml-auto text-gray-500 hover:text-gray-300 disabled:opacity-50' }, | |
| h(RefreshCw, { size: 13, className: hist.loading ? 'animate-spin' : '' }))), | |
| resultTab === 'history' | |
| ? (hist.loading && hist.items === null | |
| ? h('p', { className: 'text-[12px] text-gray-500' }, '๊ธฐ๋ก ๋ถ๋ฌ์ค๋ ์คโฆ') | |
| : hist.error | |
| ? h('p', { className: 'text-[12px] text-red-400' }, hist.error) | |
| : !hist.items || hist.items.length === 0 | |
| ? h('p', { className: 'text-[12px] text-gray-500' }, '์ ์ฅ๋ ๊ธฐ๋ก ์์') | |
| : h('div', null, | |
| h('div', { className: 'grid grid-cols-3 md:grid-cols-1 gap-2' }, | |
| hist.items.map(r => h('button', { key: r.id, type: 'button', onClick: () => setCurrent(r), | |
| className: `w-full relative rounded-xl overflow-hidden border-2 ${current?.id === r.id ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}` }, | |
| h('img', { src: r.thumbUrl, loading: 'lazy', className: 'w-full h-auto block bg-white' }), | |
| h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-black/65 text-[10.5px] text-left leading-tight' }, | |
| h('div', null, `${r.meta.face ? r.meta.face + ' ยท ' : ''}${r.meta.shot} ยท ${r.meta.angle}`), | |
| h('div', { className: 'text-gray-300' }, r.createdAt))))), | |
| hist.truncated && h('p', { className: 'text-[11px] text-gray-500 mt-2' }, '์ต๊ทผ 60๊ฑด๊น์ง ํ์ โ ์ ์ฒด๋ ํต๊ณ ๋์๋ณด๋์์'))) | |
| : results.length === 0 | |
| ? h('p', { className: 'text-[12px] text-gray-500' }, '์์ง ์์') | |
| : h('div', { className: 'grid grid-cols-3 md:grid-cols-1 gap-2' }, | |
| results.map(r => h('div', { key: r.id, className: 'relative group' }, | |
| h('button', { type: 'button', onClick: () => setCurrent(r), | |
| className: `w-full relative rounded-xl overflow-hidden border-2 ${current?.id === r.id ? 'border-brand-blue' : 'border-transparent hover:border-[#4b5563]'}` }, | |
| h('img', { src: r.imageUrl, className: 'w-full h-auto block bg-white' }), | |
| h('div', { className: 'absolute bottom-0 inset-x-0 px-2 py-1 bg-black/65 text-[10.5px] text-left leading-tight' }, | |
| h('div', null, `${r.meta.face ? r.meta.face + ' ยท ' : ''}${r.meta.shot} ยท ${r.meta.angle}`), | |
| h('div', { className: 'text-gray-300' }, `${r.meta.gaze} ยท ${fmtSec(r.elapsedSec)}`))), | |
| h('div', { className: 'absolute top-1.5 right-1.5 hidden group-hover:flex gap-1' }, | |
| r.payload && h('button', { type: 'button', onClick: (e) => { e.stopPropagation(); regenFrom(r); }, title: '์ด ์ค์ ์ผ๋ก ๋ค์ ์์ฑ', | |
| className: 'w-7 h-7 rounded-lg bg-black/60 hover:bg-brand-blue text-white flex items-center justify-center transition-colors' }, | |
| h(RefreshCw, { size: 13 })), | |
| h('button', { type: 'button', onClick: (e) => { e.stopPropagation(); deleteResult(r); }, title: '์ด ๊ฒฐ๊ณผ ์ง์ฐ๊ธฐ', | |
| className: 'w-7 h-7 rounded-lg bg-black/60 hover:bg-red-500 text-white flex items-center justify-center transition-colors' }, | |
| h(X, { size: 13 })))))))), | |
| current && h('div', { className: 'mt-5 text-[12px] text-gray-500' }, | |
| `${current.history ? `์ง๋ ๊ธฐ๋ก (${current.createdAt}) ยท ` : ''}${current.meta.age} ยท ${current.meta.shot} ยท ${current.meta.angle} ยท ${current.meta.gaze}`, current.meta.prompt ? ` ยท "${current.meta.prompt}"` : ''), | |
| current && (current.garmentSpecs || current.finalPrompt || current.poseSpec) && h('div', { className: 'mt-3 rounded-xl border border-[#2a2a2a] bg-[#202020]' }, | |
| h('button', { type: 'button', onClick: () => setShowSpecs(v => !v), className: 'w-full flex items-center justify-between px-4 py-2.5 text-[12.5px] font-semibold text-gray-300 hover:text-white' }, | |
| h('span', null, 'ํฌ์ฆ ๋ถ์ ยท ์์ ๋ถ์ ยท ์ต์ข ํ๋กฌํํธ'), h('span', { className: 'text-gray-500 font-normal' }, showSpecs ? '์ ๊ธฐ' : 'ํผ์น๊ธฐ')), | |
| showSpecs && h('div', { className: 'px-4 pb-4 space-y-3 animate-fadeIn' }, | |
| current.poseSpec && h('div', null, | |
| h('div', { className: 'flex items-center justify-between mb-1' }, | |
| h('div', { className: 'text-[11px] text-gray-500' }, 'ํฌ์ฆ ๋ถ์ (๋ ํผ๋ฐ์ค โ ๋ฌธ์ฅ, ํ๋กฌํํธ ์ต์ฐ์ ์ง์)'), | |
| h('button', { type: 'button', onClick: () => { setPoseSpec(current.poseSpec); document.querySelector('aside')?.scrollTo({ top: 0, behavior: 'smooth' }); }, | |
| className: 'text-[11px] text-brand-blue hover:underline' }, '์ด ๋ฌธ์ฅ์ ์์ ํด์ ๋ค์ ์์ฑ')), | |
| h('pre', { className: 'text-[11.5px] text-gray-200 whitespace-pre-wrap break-words bg-[#1a1a1a] rounded-lg p-3 max-h-40 overflow-y-auto' }, current.poseSpec)), | |
| current.garmentSpecs && h('div', null, | |
| h('div', { className: 'text-[11px] text-gray-500 mb-1' }, 'GPT ๋น์ ์์ ๋ถ์ (GARMENT SPECS)'), | |
| h('pre', { className: 'text-[11.5px] text-gray-200 whitespace-pre-wrap break-words bg-[#1a1a1a] rounded-lg p-3 max-h-48 overflow-y-auto' }, current.garmentSpecs)), | |
| current.finalPrompt && h('div', null, | |
| h('div', { className: 'text-[11px] text-gray-500 mb-1' }, 'GPT-image์ ์ ๋ฌ๋ ์ต์ข ํ๋กฌํํธ'), | |
| h('pre', { className: 'text-[11.5px] text-gray-300 whitespace-pre-wrap break-words bg-[#1a1a1a] rounded-lg p-3 max-h-64 overflow-y-auto' }, current.finalPrompt)))))); | |
| // โโ Header โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const header = h('header', { className: 'h-14 shrink-0 border-b border-[#2a2a2a] bg-[#1a1a1a] flex items-center justify-between px-5' }, | |
| h('div', { className: 'flex items-center gap-5' }, | |
| h('div', { className: 'flex items-center gap-3' }, | |
| h('div', { className: 'w-8 h-8 rounded-lg bg-brand-blue flex items-center justify-center' }, h(Sparkles, { size: 16, className: 'text-white' })), | |
| h('div', { className: 'text-[15px] font-bold tracking-tight' }, 'CLOVIS AI ๋ฃฉ๋ถ ์์ฑ๊ธฐ')), | |
| user.oauth_enabled && h('div', { className: 'flex items-center gap-2 text-[12.5px] pl-5 border-l border-[#2a2a2a]' }, | |
| user.is_logged_in | |
| ? h(React.Fragment, null, | |
| h('span', { className: 'text-gray-300' }, user.name || user.username), | |
| h('a', { href: user.logout_url, className: 'text-gray-500 hover:text-white' }, '๋ก๊ทธ์์')) | |
| : h('a', { href: user.login_url, className: 'px-3 py-1.5 rounded-lg bg-[#2a2a2a] hover:bg-[#333] text-gray-100' }, '๐ค Hugging Face๋ก ๋ก๊ทธ์ธ'))), | |
| h('div', null, | |
| health && !health.ok && h('span', { className: 'inline-flex items-center gap-1.5 text-[12.5px] text-amber-400' }, | |
| h('span', { className: 'w-1.5 h-1.5 rounded-full bg-amber-400' }), 'Comfy ์ค์ ํ์'))); | |
| const lightboxEl = lightbox && current && h('div', { | |
| className: 'fixed inset-0 z-50 bg-black/90 flex items-center justify-center animate-fadeIn cursor-zoom-out', | |
| onClick: () => setLightbox(false) }, | |
| h('img', { src: current.imageUrl, alt: '์์ฑ ๊ฒฐ๊ณผ ํ๋', onClick: e => e.stopPropagation(), | |
| className: 'max-w-[96vw] max-h-[96vh] object-contain bg-white cursor-default shadow-2xl' }), | |
| aiLabel && h('div', { className: 'absolute top-4 right-16 text-[12px] text-gray-300 font-light pointer-events-none' }, AI_LABEL_TEXT), | |
| h('button', { type: 'button', onClick: () => setLightbox(false), title: '๋ซ๊ธฐ (Esc)', | |
| 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 })), | |
| h('div', { className: 'absolute bottom-4 left-1/2 -translate-x-1/2 flex gap-2', onClick: e => e.stopPropagation() }, | |
| h('button', { type: 'button', onClick: () => { setLightbox(false); setExportOpen(true); }, | |
| 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 }), '๋ค์ด๋ก๋'))); | |
| const exportEl = exportOpen && current && h(ExportModal, { current, aiLabel, onClose: () => setExportOpen(false) }); | |
| return h('div', { className: 'h-screen flex flex-col bg-[#1a1a1a]' }, header, | |
| h('div', { className: 'flex-1 flex flex-col lg:flex-row min-h-0' }, left, right), lightboxEl, exportEl); | |
| } | |
| ReactDOM.createRoot(document.getElementById('root')).render(h(App)); | |
| </script> | |
| </body> | |
| </html> | |