Spaces:
Sleeping
Sleeping
switch faster-whisper to CPU int8 (base) — no CUDA libs; free CPU Space
Browse filesFiles changed (3)
- README.md+6-9
- app.py+15-31
- requirements.txt-2
22 unmodified lines2324252627282930313233344 unmodified lines394041424344454647484950515222 unmodified lines## How it works- **Transcribe** with **faster-whisper** (`small`, float16) on **Hugging Face ZeroGPU** — the GPU is heldonly for the transcription itself.- **Summarize** with one **Claude** call using **forced tool-use**, so the summary + action items comeback as schema-valid JSON every time (no brittle parsing).- **Two-stage pipeline:** transcription (GPU) → summarization (CPU/API), so the GPU is released beforethe network call.## Two tiers- **Free (this demo)** — short clips → transcript + summary + action items.4 unmodified lines```bashpip install -r requirements.txtexport ANTHROPIC_API_KEY=sk-ant-... # for the summary + action itemspython app.py # http://127.0.0.1:7860 (transcription needs a CUDA GPU)```The `spaces` import is shimmed to a no-op locally, so the UI builds without a GPU — but transcriptionrequires CUDA + faster-whisper.## Deploy (Hugging Face Space)1. Create a **Gradio** Space, hardware **ZeroGPU**.2. Add secrets **`ANTHROPIC_API_KEY`** (summary) and, if models are gated, **`HF_TOKEN`**.3. Push these files; point **notes.gritai.solutions** at the Space (CNAME → `hf.space`, DNS-only).---22 unmodified lines23242526272829303132334 unmodified lines38394041424344454647484922 unmodified lines## How it works- **Transcribe** with **faster-whisper** (`base`, int8) on **CPU** — reliable and quick for short clips,no GPU/CUDA libraries required.- **Summarize** with one **Claude** call using **forced tool-use**, so the summary + action items comeback as schema-valid JSON every time (no brittle parsing).- **Two-stage pipeline:** transcription → summarization, each a clean step.## Two tiers- **Free (this demo)** — short clips → transcript + summary + action items.4 unmodified lines```bashpip install -r requirements.txtexport ANTHROPIC_API_KEY=sk-ant-... # for the summary + action itemspython app.py # http://127.0.0.1:7860```## Deploy (Hugging Face Space)1. Create a **Gradio** Space — **CPU basic** hardware is enough (no GPU needed).2. Add secret **`ANTHROPIC_API_KEY`** for the summary + action items.3. Push these files; point **notes.gritai.solutions** at the Space (CNAME → `hf.space`, DNS-only).---
16 unmodified lines171819202122232425262728293031323334353637381 unmodified line40414243444546474849505152535455565758596061621 unmodified line64656667686970717273747576777816 unmodified linesimport gradio as grtry:import spaces # ZeroGPU runtime_HAS_SPACES = Trueexcept Exception:_HAS_SPACES = Falseclass spaces: # local no-op shim so the UI builds without GPU@staticmethoddef GPU(*a, **k):def wrap(fn):return fnreturn wrapWHISPER_SIZE = "small" # good accuracy/speed balance; float16 on ZeroGPUWHISPER_REPO = "Systran/faster-whisper-small"CLAUDE_MODEL = os.environ.get("ANTHROPIC_MODEL", "claude-haiku-4-5")MAX_TRANSCRIPT_CHARS = 24000 # keep the summarize call comfortably in-context1 unmodified linedef _get_model():"""Construct the faster-whisper model on CUDA (cached). Weights are pre-fetched at startup so thisonly loads from the warm disk cache, not the network, inside the GPU budget."""global _MODELif _MODEL is None:from faster_whisper import WhisperModel_MODEL = WhisperModel(WHISPER_SIZE, device="cuda", compute_type="float16")return _MODEL# Pre-fetch weights at startup, ONLY on the real Space (never during local UI preview).if _HAS_SPACES:try:from huggingface_hub import snapshot_downloadsnapshot_download(WHISPER_REPO)print("[startup] faster-whisper weights cached; GPU attaches per request", flush=True)except Exception as _e:print(f"[startup] whisper prefetch failed (will retry on first call): {_e}", flush=True)def _mmss(seconds):1 unmodified linereturn f"{seconds // 60:02d}:{seconds % 60:02d}"@spaces.GPU(duration=120)def _transcribe(audio_path):import torchif not torch.cuda.is_available():raise gr.Error("🎙️ Local UI preview — transcription runs on the ZeroGPU Space (needs a GPU). ""The controls and Studio waitlist here are live.")model = _get_model()segments, info = model.transcribe(audio_path, vad_filter=True, beam_size=5)rows = [(seg.start, seg.end, seg.text.strip()) for seg in segments]return rows, getattr(info, "language", "?")16 unmodified lines1718192021222324251 unmodified line2728293031323334353637383940414243444546471 unmodified line495051525354555657585960616216 unmodified linesimport gradio as grON_SPACE = bool(os.environ.get("SPACE_ID")) # True when running on a Hugging Face SpaceWHISPER_SIZE = "base" # int8 on CPU — fast + reliable for short clips, no CUDA libs neededCLAUDE_MODEL = os.environ.get("ANTHROPIC_MODEL", "claude-haiku-4-5")MAX_TRANSCRIPT_CHARS = 24000 # keep the summarize call comfortably in-context1 unmodified linedef _get_model():"""Construct the faster-whisper model on CPU (int8), cached. Runs anywhere — no GPU / CUDA libs."""global _MODELif _MODEL is None:from faster_whisper import WhisperModel_MODEL = WhisperModel(WHISPER_SIZE, device="cpu", compute_type="int8")return _MODEL# Warm the model at startup on the Space so the first request isn't slow.if ON_SPACE:try:_get_model()print("[startup] faster-whisper (base, cpu/int8) loaded", flush=True)except Exception as _e:print(f"[startup] whisper load failed (will retry on first call): {_e}", flush=True)def _mmss(seconds):1 unmodified linereturn f"{seconds // 60:02d}:{seconds % 60:02d}"def _transcribe(audio_path):try:model = _get_model()except ImportError:raise gr.Error("🎙️ Local UI preview — transcription runs on the Space (faster-whisper isn't installed here). ""The controls and Studio waitlist are live.")segments, info = model.transcribe(audio_path, vad_filter=True, beam_size=5)rows = [(seg.start, seg.end, seg.text.strip()) for seg in segments]return rows, getattr(info, "language", "?")
12345# gradio comes from the Space (sdk_version in README) — don't pin it here.spaces>=0.30torchfaster-whisper>=1.0anthropic>=0.40123# gradio comes from the Space (sdk_version in README) — don't pin it here.faster-whisper>=1.0anthropic>=0.40
README.md+6-9
app.py+15-31
requirements.txt-2