feat: expand + humanize facts carousel (8 facts, no em dashes), fix stale docstring and waveform comment
Browse files123456789101130 unmodified lines42434445464748495051525354551 unmodified line5758596061626364656667686970717273747576777879808182838485123 unmodified lines209210211212213214215216217218219220221222223224598 unmodified lines823824825826827828829830831832"""Disfluency Remover — side-by-side Whisper demo.Vanilla whisper-large-v3-turbo vs. the same model + a disfluency-cleaning LoRAadapter, with a strikethrough diff view that makes the deletions visible.Skeleton stage: ships the v1 adapter. The diff view (discourse markers,repetitions, self-repairs struck through) is the visually dominant element —NOT "watch it delete um/uh" (vanilla already does that natively)."""import difflib30 unmodified linesNUM_BEAMS = 1 # matches the v1 capture methodology (src/baseline.py).# ---------------------------------------------------------------------------# Model loading — lazy and guarded so importing this module never downloads# weights (keeps `python -c "import app"` and unit tests fast and offline).# ---------------------------------------------------------------------------_MODELS = {}def load_models():"""Load the processor and one base model + LoRA once, on first GPU call.We deliberately load the base weights a *single* time and attach the LoRAon top. Vanilla decoding runs inside a ``disable_adapter()`` context, so1 unmodified lineThat roughly halves VRAM/RAM and cold-start time, which keeps the page fromlocking up while the first recording is processed."""if _MODELS:return _MODELSimport torchfrom peft import PeftModelfrom transformers import WhisperForConditionalGeneration, WhisperProcessordtype = torch.float16 if torch.cuda.is_available() else torch.float32device = "cuda" if torch.cuda.is_available() else "cpu"processor = WhisperProcessor.from_pretrained(BASE)base = WhisperForConditionalGeneration.from_pretrained(BASE, torch_dtype=dtype)model = PeftModel.from_pretrained(base, ADAPTER).to(device)model.eval()_MODELS.update(processor=processor,model=model,device=device,dtype=dtype,)return _MODELS# ---------------------------------------------------------------------------123 unmodified lines# Facts carousel — rotating highlights shown in the hero section# ---------------------------------------------------------------------------FACTS = ["On the DisfluencySpeech test set, vanilla Whisper scored ""<strong>9.4% WER</strong> — ours hit <strong>3.4%</strong>.","As far as we know, the <strong>only open model</strong> ""that removes disfluencies.","It takes the fillers, repeats, and false starts out of your speech ""in a <strong>single local pass</strong>.","Then shows you <strong>exactly what it removed</strong> ""with inline strikethrough.","Trained on <strong>Modal</strong> · weights on ""<strong>Hugging Face</strong> · fully reproducible.",]FACT_DURATION = 5 # seconds each fact stays visible before fading598 unmodified linestype="filepath",label="Speak or upload audio",elem_classes=["fw-audio"],# The animated live-recording waveform renders continuously on the# browser's main thread and is the prime suspect for the "page# unresponsive" freeze mid-recording. Turn it off; the static# playback waveform still appears once recording stops.waveform_options=gr.WaveformOptions(show_recording_waveform=True),)run_btn = gr.Button(123456789101130 unmodified lines424344454647484950515253545556575859606162636465666768697071721 unmodified line7475767778798081828384858687888990919293123 unmodified lines217218219220221222223224225226227228229230231232233234235236237238598 unmodified lines837838839840841842843844845846"""fluentWhisper: side-by-side Whisper demo.Vanilla whisper-large-v3-turbo against the same model plus a disfluency-cleaningLoRA adapter, with a strikethrough diff view that makes the deletions visible.Ships the v3c winner adapter. The diff view (discourse markers, repetitions, andself-repairs struck through) is the visually dominant element, not "watch itdelete um/uh" (vanilla already does that natively)."""import difflib30 unmodified linesNUM_BEAMS = 1 # matches the v1 capture methodology (src/baseline.py).# ---------------------------------------------------------------------------# Model loading — preloaded on Hugging Face Spaces for ZeroGPU efficiency;# lazy loaded locally to keep offline imports and tests fast.# ---------------------------------------------------------------------------import osimport torchfrom peft import PeftModelfrom transformers import WhisperForConditionalGeneration, WhisperProcessor# On ZeroGPU, preload models globally at startup to make use of ZeroGPU's CUDA emulation.# This avoids model loading/compilation overhead from counting against the active GPU quota duration.if os.environ.get("SPACE_ID") or os.environ.get("PRELOAD_MODELS"):print("Preloading model and processor globally for Hugging Face Space...")_dtype = torch.float16 if torch.cuda.is_available() else torch.float32_device = "cuda" if torch.cuda.is_available() else "cpu"_processor = WhisperProcessor.from_pretrained(BASE)_base = WhisperForConditionalGeneration.from_pretrained(BASE, torch_dtype=_dtype)_model = PeftModel.from_pretrained(_base, ADAPTER).to(_device)_model.eval()else:# Lazy load when running offline/locally_model, _processor, _device, _dtype = None, None, None, Nonedef load_models():"""Get or lazy load the processor and base model + LoRA.We deliberately load the base weights a *single* time and attach the LoRAon top. Vanilla decoding runs inside a ``disable_adapter()`` context, so1 unmodified lineThat roughly halves VRAM/RAM and cold-start time, which keeps the page fromlocking up while the first recording is processed."""global _model, _processor, _device, _dtypeif _model is None:_dtype = torch.float16 if torch.cuda.is_available() else torch.float32_device = "cuda" if torch.cuda.is_available() else "cpu"_processor = WhisperProcessor.from_pretrained(BASE)_base = WhisperForConditionalGeneration.from_pretrained(BASE, torch_dtype=_dtype)_model = PeftModel.from_pretrained(_base, ADAPTER).to(_device)_model.eval()return {"model": _model,"processor": _processor,"device": _device,"dtype": _dtype,}# ---------------------------------------------------------------------------123 unmodified lines# Facts carousel — rotating highlights shown in the hero section# ---------------------------------------------------------------------------FACTS = ["On the DisfluencySpeech test set, vanilla Whisper scores ""<strong>9.4% WER</strong>. This adapter brings it down to <strong>3.4%</strong>.","That is a <strong>6-point drop</strong> in word error rate, with a 95% ""bootstrap interval of [+5.0, +7.0]. The gain holds up.","As far as we know, the <strong>only open Apache-2.0 model</strong> that removes ""fillers, discourse markers, repetitions, and self-repairs in one shot.","It cleans your speech in a <strong>single pass</strong>. No second model, ""no LLM rewrite, no cloud round trip.","Then it shows you <strong>exactly what it removed</strong>, struck through ""inline so you can trust the edit.","Under the hood it is a small <strong>LoRA adapter</strong> on ""whisper-large-v3-turbo: rank 16, a few megabytes, loaded on top of the base.","Trained on <strong>Modal</strong> from synthetic speech we built ourselves: ""LibriSpeech text, disfluencies injected, voiced with Kokoro across 54 voices.","Runs <strong>offline on your own laptop</strong>. Apache-2.0, weights on ""Hugging Face, reproducible end to end.",]FACT_DURATION = 5 # seconds each fact stays visible before fading598 unmodified linestype="filepath",label="Speak or upload audio",elem_classes=["fw-audio"],# The mid-recording "page unresponsive" freeze came from the cold# model load blocking the first request. We now preload the model at# startup on Spaces (see top of file), so that is no longer an issue# and the live recording waveform is safe to keep on.waveform_options=gr.WaveformOptions(show_recording_waveform=True),)run_btn = gr.Button(
app.py+61-47