1e2c004dd4
plan: ~/.claude/plans/luminous-sprouting-hamster.md §3
스키마:
- migrations/147_audio_segments_table.sql: audio_segments (STT 타임스탬프
세그먼트)
- migrations/148_audio_segments_idx.sql: (document_id, start_s) idx
- migrations/149_document_media_cols.sql: documents.thumbnail_path +
needs_conversion
- migrations/150_queue_stage_stt.sql: process_stage += 'stt'
- migrations/151_queue_stage_thumbnail.sql: process_stage += 'thumbnail'
- app/models/audio_segment.py, document.py (thumbnail_path/needs_conversion)
서비스:
- services/stt/{Dockerfile, requirements.txt, server.py} — faster-whisper
large-v3 GPU 컨테이너. /transcribe (filePath/langs/beamSize) +
/health + /ready (cuda device_count + model_loaded). NFC/NFD 경로
resolver (OCR 교훈).
- docker-compose.yml: stt-service 추가 (GPU 1 예약, :3300, NAS ro mount,
stt_models volume, start_period 300s), fastapi env 에 STT_ENDPOINT.
파이프라인 (의존 §1 category):
- app/workers/stt_worker.py 신규: stage='stt' pickup → STT_ENDPOINT 호출 →
extracted_text + audio_segments 저장. Timeout 30분.
- app/workers/thumbnail_worker.py 신규: ffmpeg 50% 지점 1장 →
PKM/Videos/.thumbs/{id}.jpg + thumbnail_path 세팅.
needs_conversion=true 는 skip.
- app/workers/file_watcher.py 확장: PKM/{Inbox, Recordings, Videos}
스캔. 확장자→category, audio→stage=stt, video .mp4/.webm→
stage=thumbnail, video .mov/.mkv/.avi→needs_conversion=true + stage
없음. settings.roon_library_path prefix skip.
- app/workers/queue_consumer.py 확장: stt + thumbnail workers 등록,
BATCH_SIZE(stt=1, thumbnail=3), next_stages 에 stt→[classify] 추가
(audio 는 extract 건너뜀).
- app/Dockerfile: ffmpeg 추가 (썸네일 subprocess 용).
API (의존 §1):
- /api/audio/{id}/segments — AudioSegment ORDER BY start_s
- /api/video/{id}/thumbnail — thumbnail_path FileResponse (쿼리 토큰)
- /api/documents/{id}/file: media_types 에 audio/video mime 포함 (§2
커밋에 이미 포함). Starlette FileResponse 가 Range 자동.
- upload_document: .mov/.mkv/.avi 웹 업로드 거부 (error_code
unsupported_codec). NAS 드롭은 file_watcher 가 quarantine 수용.
프론트:
- AudioPlayer.svelte: HTML5 audio + 전사 세그먼트 sticky 패널 + 줄
클릭 seek. activeIdx 하이라이트.
- VideoPlayer.svelte: HTML5 video direct play + needs_conversion 안내
카드. poster 는 thumbnail endpoint.
- /audio (목록 grid) + /audio/[id] (플레이어)
- /video (썸네일 grid + 변환 필요 배지) + /video/[id] (플레이어)
- Sidebar.svelte: Mic/Film 아이콘 + audio/video 네비 활성, count
배지 (§2 /stats/category-counts 재사용).
설정:
- app/core/config.py: stt_endpoint + roon_library_path.
DoD 배포 후 smoke: /ready cuda:true, 회의 mp3 transcribe, audio
extract 없이 classify 진행(queue 회귀), /audio 재생, .mp4 재생,
.mov 웹 400, .mov NAS quarantine, Sidebar 네비 + count.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
157 lines
5.0 KiB
Python
157 lines
5.0 KiB
Python
"""설정 로딩 — config.yaml + credentials.env"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class UploadConfig(BaseModel):
|
|
max_bytes: int = 100_000_000
|
|
content_length_slack_ratio: float = 1.05
|
|
stream_chunk_bytes: int = 1_048_576
|
|
|
|
|
|
class AIModelConfig(BaseModel):
|
|
endpoint: str
|
|
model: str
|
|
max_tokens: int = 4096
|
|
timeout: int = 60
|
|
daily_budget_usd: float | None = None
|
|
require_explicit_trigger: bool = False
|
|
|
|
|
|
class AIConfig(BaseModel):
|
|
gateway_endpoint: str
|
|
primary: AIModelConfig
|
|
fallback: AIModelConfig
|
|
premium: AIModelConfig
|
|
embedding: AIModelConfig
|
|
vision: AIModelConfig
|
|
rerank: AIModelConfig
|
|
# Phase 3.5a: exaone classifier (optional — 없으면 score-only gate)
|
|
classifier: AIModelConfig | None = None
|
|
# Phase 3.5b: exaone verifier (optional — 없으면 grounding-only)
|
|
verifier: AIModelConfig | None = None
|
|
|
|
|
|
class Settings(BaseModel):
|
|
# DB
|
|
database_url: str = ""
|
|
|
|
# AI
|
|
ai: AIConfig | None = None
|
|
|
|
# NAS
|
|
nas_mount_path: str = "/documents"
|
|
nas_pkm_root: str = "/documents/PKM"
|
|
|
|
# 인증
|
|
jwt_secret: str = ""
|
|
totp_secret: str = ""
|
|
|
|
# Phase 3.5: eval runner shared secret — X-Source=eval / X-Eval-Case-Id 헤더 신뢰 검증.
|
|
# 비어있으면 모든 eval 헤더 거부 (부재 = 비활성).
|
|
eval_runner_token: str = ""
|
|
|
|
# kordoc
|
|
kordoc_endpoint: str = "http://kordoc-service:3100"
|
|
|
|
# OCR (Surya)
|
|
ocr_endpoint: str = "http://ocr-service:3200"
|
|
|
|
# STT (faster-whisper, §3)
|
|
stt_endpoint: str = "http://stt-service:3300"
|
|
|
|
# §3 file_watcher: Roon 음원 경로 (prefix match 로 skip).
|
|
# 빈 문자열이면 skip 없음. 예: "/documents/PKM/../Music/roon-library" 또는
|
|
# NFS 경유 별도 마운트된 Roon 라이브러리.
|
|
roon_library_path: str = ""
|
|
|
|
# 분류 체계
|
|
taxonomy: dict = {}
|
|
document_types: list[str] = []
|
|
|
|
# 업로드 한도 (authoritative policy)
|
|
upload: UploadConfig = UploadConfig()
|
|
|
|
|
|
def load_settings() -> Settings:
|
|
"""config.yaml + 환경변수에서 설정 로딩"""
|
|
# 환경변수 (docker-compose에서 주입)
|
|
database_url = os.getenv("DATABASE_URL", "")
|
|
jwt_secret = os.getenv("JWT_SECRET", "")
|
|
totp_secret = os.getenv("TOTP_SECRET", "")
|
|
eval_runner_token = os.getenv("EVAL_RUNNER_TOKEN", "")
|
|
kordoc_endpoint = os.getenv("KORDOC_ENDPOINT", "http://kordoc-service:3100")
|
|
ocr_endpoint = os.getenv("OCR_ENDPOINT", "http://ocr-service:3200")
|
|
stt_endpoint = os.getenv("STT_ENDPOINT", "http://stt-service:3300")
|
|
roon_library_path = os.getenv("ROON_LIBRARY_PATH", "")
|
|
|
|
# config.yaml — Docker 컨테이너 내부(/app/config.yaml) 또는 프로젝트 루트
|
|
config_path = Path("/app/config.yaml")
|
|
if not config_path.exists():
|
|
config_path = Path(__file__).parent.parent.parent / "config.yaml"
|
|
ai_config = None
|
|
nas_mount = "/documents"
|
|
nas_pkm = "/documents/PKM"
|
|
|
|
if config_path.exists():
|
|
with open(config_path) as f:
|
|
raw = yaml.safe_load(f)
|
|
|
|
if "ai" in raw:
|
|
ai_raw = raw["ai"]
|
|
ai_config = AIConfig(
|
|
gateway_endpoint=ai_raw.get("gateway", {}).get("endpoint", ""),
|
|
primary=AIModelConfig(**ai_raw["models"]["primary"]),
|
|
fallback=AIModelConfig(**ai_raw["models"]["fallback"]),
|
|
premium=AIModelConfig(**ai_raw["models"]["premium"]),
|
|
embedding=AIModelConfig(**ai_raw["models"]["embedding"]),
|
|
vision=AIModelConfig(**ai_raw["models"]["vision"]),
|
|
rerank=AIModelConfig(**ai_raw["models"]["rerank"]),
|
|
classifier=(
|
|
AIModelConfig(**ai_raw["models"]["classifier"])
|
|
if "classifier" in ai_raw.get("models", {})
|
|
else None
|
|
),
|
|
verifier=(
|
|
AIModelConfig(**ai_raw["models"]["verifier"])
|
|
if "verifier" in ai_raw.get("models", {})
|
|
else None
|
|
),
|
|
)
|
|
|
|
if "nas" in raw:
|
|
nas_mount = raw["nas"].get("mount_path", nas_mount)
|
|
nas_pkm = raw["nas"].get("pkm_root", nas_pkm)
|
|
|
|
taxonomy = raw.get("taxonomy", {}) if config_path.exists() and raw else {}
|
|
document_types = raw.get("document_types", []) if config_path.exists() and raw else []
|
|
upload_cfg = (
|
|
UploadConfig(**raw["upload"])
|
|
if config_path.exists() and raw and "upload" in raw
|
|
else UploadConfig()
|
|
)
|
|
|
|
return Settings(
|
|
database_url=database_url,
|
|
ai=ai_config,
|
|
nas_mount_path=nas_mount,
|
|
nas_pkm_root=nas_pkm,
|
|
jwt_secret=jwt_secret,
|
|
totp_secret=totp_secret,
|
|
eval_runner_token=eval_runner_token,
|
|
kordoc_endpoint=kordoc_endpoint,
|
|
ocr_endpoint=ocr_endpoint,
|
|
stt_endpoint=stt_endpoint,
|
|
roon_library_path=roon_library_path,
|
|
taxonomy=taxonomy,
|
|
document_types=document_types,
|
|
upload=upload_cfg,
|
|
)
|
|
|
|
|
|
settings = load_settings()
|