Files
kyeongmin 688ddbbb17 04. design_agent 추가 — 콘텐츠 시각 구조화 슬라이드 생성기
5단계 AI 파이프라인:
1. Kei 실장(Opus via Kei API) — 꼭지 추출 + 정보 구조 파악
2. 디자인 팀장 — FAISS 블록 검색 + Opus 추천 + Sonnet 블록 매핑
3. Kei 편집자(Kei API) — 도메인 전문 텍스트 정리
4. 디자인 실무자(Sonnet + Jinja2) — CSS 변수 조정 + HTML 조립
5. 디자인 팀장(Sonnet) — 균형 재검토 (최대 2회 루프)

블록 라이브러리 46개 (6 카테고리) + _legacy 13개
FAISS 블록 검색 (bge-m3, 1024차원)
SVG N개 동적 배치 (cos/sin 좌표 계산)
Pillow 이미지 크기 측정 + base64 인라인
컨테이너 예산 기반 블록 배치 (zone별 높이 px)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 18:47:13 +09:00

266 lines
7.5 KiB
HTML

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Design Agent — 슬라이드 생성기</title>
<link rel="preconnect" href="https://cdn.jsdelivr.net">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Pretendard Variable', sans-serif;
background: #f1f5f9;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 24px;
color: #1e293b;
}
h1 {
font-size: 1.5rem;
font-weight: 700;
margin-bottom: 16px;
}
.container {
width: 100%;
max-width: 1400px;
display: grid;
grid-template-columns: 400px 1fr;
gap: 24px;
flex: 1;
}
.input-panel {
background: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
gap: 12px;
}
.input-panel label {
font-weight: 600;
font-size: 0.9rem;
}
textarea {
width: 100%;
height: 400px;
border: 1px solid #e2e8f0;
border-radius: 6px;
padding: 12px;
font-family: inherit;
font-size: 0.85rem;
line-height: 1.6;
resize: vertical;
word-break: keep-all;
}
textarea:focus {
outline: none;
border-color: #2563eb;
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}
button {
padding: 12px 24px;
background: #2563eb;
color: white;
border: none;
border-radius: 6px;
font-size: 0.95rem;
font-weight: 600;
cursor: pointer;
font-family: inherit;
}
button:hover { background: #1d4ed8; }
button:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-download {
background: #16a34a;
margin-top: 8px;
}
.btn-download:hover { background: #15803d; }
.progress {
font-size: 0.85rem;
color: #64748b;
padding: 8px 0;
}
.preview-panel {
background: #e2e8f0;
border-radius: 8px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 12px;
overflow: auto;
}
.preview-label {
color: #64748b;
font-size: 0.85rem;
font-weight: 600;
}
.iframe-wrapper {
width: 100%;
aspect-ratio: 16 / 9;
position: relative;
overflow: hidden;
border-radius: 6px;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
background: white;
}
iframe {
width: 1280px;
height: 720px;
border: none;
background: white;
transform-origin: top left;
/* scale은 JS에서 컨테이너 너비에 맞게 동적 계산 */
}
.error {
color: #dc2626;
font-size: 0.85rem;
padding: 8px 12px;
background: #fef2f2;
border-radius: 6px;
display: none;
}
</style>
</head>
<body>
<h1>Design Agent — 슬라이드 생성기</h1>
<div class="container">
<div class="input-panel">
<label>콘텐츠 입력</label>
<textarea id="content" placeholder="슬라이드로 변환할 텍스트를 붙여넣으세요..."></textarea>
<button id="btn-generate" onclick="generate()">슬라이드 생성</button>
<div id="progress" class="progress"></div>
<div id="error" class="error"></div>
<button id="btn-download" class="btn-download" style="display:none" onclick="download()">HTML 다운로드</button>
</div>
<div class="preview-panel">
<div class="preview-label">미리보기</div>
<div class="iframe-wrapper" id="iframe-wrapper">
<iframe id="preview"></iframe>
</div>
</div>
</div>
<script>
let generatedHTML = '';
function scalePreview() {
const wrapper = document.getElementById('iframe-wrapper');
const iframe = document.getElementById('preview');
if (!wrapper || !iframe) return;
const wrapperWidth = wrapper.clientWidth;
const scale = wrapperWidth / 1280;
iframe.style.transform = 'scale(' + scale + ')';
wrapper.style.height = (720 * scale) + 'px';
}
window.addEventListener('resize', scalePreview);
window.addEventListener('load', scalePreview);
async function generate() {
const content = document.getElementById('content').value.trim();
if (!content) return;
const btn = document.getElementById('btn-generate');
const progress = document.getElementById('progress');
const error = document.getElementById('error');
const downloadBtn = document.getElementById('btn-download');
btn.disabled = true;
error.style.display = 'none';
downloadBtn.style.display = 'none';
progress.textContent = '시작 중...';
// 이미지 참조 감지 → 경로 입력 팝업
let basePath = '';
const hasImages = /!\[.*?\]\(.*?\)/.test(content);
if (hasImages) {
basePath = prompt(
'이미지가 포함된 콘텐츠입니다.\n' +
'이미지 파일이 있는 프로젝트 폴더 경로를 입력해주세요.\n' +
'예: D:\\ad-hoc\\kei\\content\n\n' +
'이미지 처리가 필요 없으면 취소를 누르세요.'
) || '';
}
try {
const response = await fetch('/api/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content, base_path: basePath }),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
// SSE 이벤트는 빈 줄(\n\n)로 구분
const parts = buffer.split(/\r?\n\r?\n/);
buffer = parts.pop() || '';
for (const part of parts) {
if (!part.trim()) continue;
// 각 이벤트에서 event: 와 data: 추출
let eventType = '';
let eventData = '';
for (const line of part.split(/\r?\n/)) {
if (line.startsWith('event:')) {
eventType = line.slice(6).trim();
} else if (line.startsWith('data:')) {
eventData = line.slice(5).trim();
}
}
if (!eventData) continue;
try {
const parsed = JSON.parse(eventData);
if (eventType === 'progress') {
progress.textContent = parsed;
} else if (eventType === 'result') {
generatedHTML = parsed;
document.getElementById('preview').srcdoc = generatedHTML;
downloadBtn.style.display = 'block';
progress.textContent = '완료!';
setTimeout(scalePreview, 100);
} else if (eventType === 'error') {
error.textContent = parsed;
error.style.display = 'block';
}
} catch (e) {
// ping 등 무시
}
}
}
} catch (e) {
error.textContent = '오류: ' + e.message;
error.style.display = 'block';
} finally {
btn.disabled = false;
}
}
function download() {
if (!generatedHTML) return;
const blob = new Blob(['\uFEFF' + generatedHTML], { type: 'text/html;charset=utf-8' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'slide-' + Date.now() + '.html';
a.click();
URL.revokeObjectURL(url);
}
</script>
</body>
</html>