Cell 1 now detects an existing /content/luke_scribe/.git and runs git fetch + checkout feat/full-platform + pull --ff-only instead of rm -rf + clone, so re-running the notebook updates instead of wiping local changes.
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'
import os, subprocess
if os.path.isdir('/content/luke_scribe/.git'):
# 이미 클론된 레포 → 최신 브랜치로 갱신 (pull)
print('기존 레포 감지 → pull로 갱신')
subprocess.run(['git', 'fetch', 'origin'], cwd='/content/luke_scribe', check=True)
subprocess.run(['git', 'checkout', 'feat/full-platform'], cwd='/content/luke_scribe', check=True)
subprocess.run(['git', 'pull', '--ff-only', 'origin', 'feat/full-platform'], cwd='/content/luke_scribe', check=True)
else:
# 최초 실행 → 클론
subprocess.run(['git', 'clone', '-b', 'feat/full-platform', REPO], cwd='/content', check=True)
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) 설치 — Colab은 시스템 pip가 표준 (venv는 Colab에서 ensurepip 오류로 실패할 수 있음)
!pip install -q --upgrade pip
!pip install -q -e '.[engine,api]'
!pip install -q edge-tts # 샘플 음성 생성용
print('설치 완료')
!which luke-scribe && luke-scribe --help 2>&1 | head -8
In [ ]:
# 4) detect — GPU 감지 / 능력 등급 / 정밀도 / 워커수
!luke-scribe detect
In [ ]:
# 5) 테스트 스위트
!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 큐, 백그라운드 — Colab에서는 %%bash --bg 또는 nohup 사용)
!mkdir -p /content/logs
!nohup luke-scribe serve --port 8000 > /content/logs/server.log 2>&1 &
import time, urllib.request
ok = False
for _ in range(40):
try:
urllib.request.urlopen('http://localhost:8000/health', timeout=1)
ok = True
break
except Exception:
time.sleep(1)
print('서버 기동 OK' if ok else '서버 기동 실패 — 로그:')
if not ok:
print(open('/content/logs/server.log').read()[-1500:])
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