CPU-only dev env verified via mocks; the notebook runs the full real pipeline on Colab Pro T4: clone → ffmpeg/venv install → detect (GPU capability tier) → 127 unit/integration tests → sample TTS (KO+EN tech terms) → real faster-whisper transcription → hotword/postprocess → API smoke → benchmark.
12 KiB
12 KiB
In [ ]:
# 0) 런타임 확인 — T4 GPU가 활성 상태여야 합니다
!nvidia-smi
import sys
print('Python', sys.version.split()[0])
In [ ]:
# 1) 클론 (private 저장소면 GITEA_TOKEN 입력)
GITEA_TOKEN = '' # ← 필요 시 입력: https://git.lukehemmin.com/user/settings/applications
if GITEA_TOKEN:
REPO = f'https://{GITEA_TOKEN}@git.lukehemmin.com/lukehemmin/luke_scribe.git'
else:
REPO = 'https://git.lukehemmin.com/lukehemmin/luke_scribe.git'
!rm -rf luke_scribe
!git clone -b feat/full-platform {REPO}
import os
os.chdir('/content/luke_scribe')
print('클론 완료 →', os.getcwd())
!git log --oneline -1
In [ ]:
# 2) 시스템 패키지 (ffmpeg — ffprobe/정규화에 필수)
!apt-get update -qq && apt-get install -y -qq ffmpeg >/dev/null
!ffmpeg -version 2>&1 | head -1
!ffprobe -version 2>&1 | head -1
In [ ]:
# 3) venv + 설치 (GPU 추론은 engine+api만으로 충분 — Colab T4에 CUDA 런타임 내장)
!python3 -m venv .venv
!source .venv/bin/activate && pip install -q --upgrade pip
!source .venv/bin/activate && pip install -q -e '.[engine,api]'
!source .venv/bin/activate && pip install -q edge-tts # 샘플 음성 생성용
# 이후 셀에서 activate 없이 CLI 사용 가능하게 PATH 등록
import os
os.environ['PATH'] = '/content/luke_scribe/.venv/bin:' + os.environ['PATH']
print('설치 완료')
!luke-scribe --help 2>&1 | head -12
In [ ]:
# 4) detect — GPU 감지 / 능력 등급 / 정밀도 / 워커수
!luke-scribe detect
In [ ]:
# 5) 테스트 스위트
!source .venv/bin/activate && python -m pytest tests/ -q 2>&1 | tail -5
In [ ]:
# 6) 샘플 오디오 생성 (한국어 + 기술용어, 무료 TTS)
!mkdir -p samples
!edge-tts --voice ko-KR-SunHiNeural --text '오늘은 vLLM 서버를 Kubernetes 클러스터에 배포하는 방법을 설명합니다. GPU 가속 추론으로 대기 시간을 줄일 수 있습니다.' --write-media samples/colab-ko-en.mp3
!ffprobe -v error -show_entries format=duration -of json samples/colab-ko-en.mp3
In [ ]:
# 7) 실전 전사 — GPU 자동 감지 + 모델 다운로드 (large-v3-turbo)
# 첫 실행 시 Hugging Face에서 모델을 다운로드합니다 (turbo ≈ 1.6GB, 1~2분)
!time luke-scribe transcribe samples/colab-ko-en.mp3 --language ko --device auto
In [ ]:
# 8) hotword 포함 전사 (용어 보존 강화)
!luke-scribe transcribe samples/colab-ko-en.mp3 --language ko --device auto --hotword vLLM --hotword Kubernetes
In [ ]:
# 9) API 키 생성 (1회 출력)
!luke-scribe key --create --scopes transcribe,admin --file /content/api_keys.json
In [ ]:
# 10) 서버 기동 (in-proc 큐, 백그라운드)
import subprocess, time, os, json
env = dict(os.environ)
env['LUKESCRIBE_API_KEY_FILE'] = '/content/api_keys.json'
env['LUKESCRIBE_QUEUE_BACKEND'] = 'inproc'
proc = subprocess.Popen(
['luke-scribe', 'serve', '--port', '8000'],
env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
)
# 기동 대기
import urllib.request
for _ in range(30):
try:
urllib.request.urlopen('http://localhost:8000/health', timeout=1)
break
except Exception:
time.sleep(1)
print('서버 기동 OK')
In [ ]:
# 11) 업로드 → poll → 결과
import json, time, urllib.request, urllib.error
KEY = json.load(open('/content/api_keys.json'))['keys'][0]
# multipart 업로드 (curl 사용 — 간단)
import subprocess
r = subprocess.run(
['curl', '-s', '-X', 'POST', 'http://localhost:8000/v1/jobs',
'-H', f'X-API-Key: {KEY}',
'-F', 'file=@samples/colab-ko-en.mp3',
'-F', 'options={"language":"ko","formats":["json","srt"]}'],
capture_output=True, text=True,
)
job = json.loads(r.stdout)
print('생성:', job)
job_id = job['job_id']
# 완료까지 poll (워커 없이 in-proc이라 즉시 완료되지는 않음 → 여기선 생성까지만 확인)
print('job_id =', job_id)
In [ ]:
# 12) 브로커 + 워커 포함 전체 흐름 (in-proc)
# 서버의 in-proc 브로커에 enqueue된 job을 같은 프로세스의 워커가 소비하는 구조는
# 프로세스 분리 필요 → 여기서는 클라이언트에서 직접 Worker.drain() 호출로 검증
from luke_scribe.config import Settings
from luke_scribe.jobqueue.broker import InProcBroker
from luke_scribe.jobqueue.worker import Worker
from luke_scribe.jobqueue.jobs import Job
from luke_scribe.results.store import ResultStore
settings = Settings(_env_file=None, queue_backend='inproc',
results_dir='/content/results', model_cache_dir=None)
broker = InProcBroker(settings)
store = ResultStore(settings.results_dir)
job = Job(type='file', lane='batch', source_path='samples/colab-ko-en.mp3',
options={'model': 'large-v3-turbo', 'language': 'ko', 'device': 'auto'})
broker.enqueue(job)
worker = Worker(settings=settings, broker=broker, store=store)
worker.drain()
result = store.read_result(job.id)
print('status:', result.status)
print('text:', result.text[:120])
print('device:', result.execution.device, '| ct:', result.execution.compute_type, '| rtf:', result.timings.rtf)
In [ ]:
# 13) 벤치마크 — 샘플 manifest 사용 (선택, 시간 소요)
# 간단 manifest 생성
import yaml
manifest = {
'name': 'colab-quick',
'language': 'ko',
'targets': {'entity_preservation': 0.95, 'cer': 0.15},
'cases': [
{'name': 'ko-en-tech', 'audio': 'samples/colab-ko-en.mp3',
'expected_entities': ['vLLM', 'Kubernetes', 'GPU']},
],
}
yaml.safe_dump(manifest, open('/content/manifest.yaml', 'w'))
# 실행 (기본: turbo만 → 빠름)
!luke-scribe bench /content/manifest.yaml --models large-v3-turbo --device auto --repeats 2 --output /content/bench-report.json 2>&1 | tail -20