Spaces:
Running on Zero
Running on Zero
Deploy demo to HF Space
Browse files- README.md +11 -14
- app.py +18 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -8,7 +8,7 @@ sdk_version: "6.26.0"
|
|
| 8 |
python_version: "3.12"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: true
|
| 11 |
-
license:
|
| 12 |
short_description: Fast English ASR with word timestamps and speaker labels
|
| 13 |
thumbnail: https://huggingface.co/spaces/mazesmazes/tiny-audio/resolve/main/thumbnail.png
|
| 14 |
models:
|
|
@@ -22,13 +22,12 @@ tags:
|
|
| 22 |
- word-timestamps
|
| 23 |
- speaker-diarization
|
| 24 |
- granite-speech
|
| 25 |
-
- qwen3
|
| 26 |
-
- lora
|
| 27 |
suggested_hardware: zero-a10g
|
| 28 |
preload_from_hub:
|
| 29 |
- mazesmazes/tiny-audio
|
| 30 |
-
- ibm-granite/granite-speech-5.0-470m-turboctc
|
| 31 |
-
- Qwen/Qwen3
|
| 32 |
- Qwen/Qwen3-ForcedAligner-0.6B-hf
|
| 33 |
- nvidia/Nemotron-3-Diarization
|
| 34 |
---
|
|
@@ -37,8 +36,8 @@ preload_from_hub:
|
|
| 37 |
|
| 38 |
This Space demonstrates an Automatic Speech Recognition (ASR) model that combines:
|
| 39 |
|
| 40 |
-
- **Granite Speech 5.0 470M encoder** for audio feature extraction
|
| 41 |
-
- **Qwen3
|
| 42 |
|
| 43 |
## Features
|
| 44 |
|
|
@@ -49,13 +48,12 @@ This Space demonstrates an Automatic Speech Recognition (ASR) model that combine
|
|
| 49 |
|
| 50 |
## Model Architecture
|
| 51 |
|
| 52 |
-
The model bridges audio and text with a trained projector and
|
| 53 |
|
| 54 |
-
1. **Audio Encoder**: Granite Speech 5.0 470M TurboCTC encoder (frozen)
|
| 55 |
1. **Projection Layer**: 2-layer MLP mapping audio features into the decoder's embedding space
|
| 56 |
-
(~
|
| 57 |
-
1. **Text Decoder**: Qwen3
|
| 58 |
-
with the projector
|
| 59 |
|
| 60 |
## Usage
|
| 61 |
|
|
@@ -67,8 +65,7 @@ The model bridges audio and text with a trained projector and LoRA adapters:
|
|
| 67 |
|
| 68 |
## Limitations
|
| 69 |
|
| 70 |
-
-
|
| 71 |
-
timestamps or diarization on, longer audio is transcribed in chunks automatically
|
| 72 |
- Requests run on ZeroGPU, which reserves GPU time from your daily quota in proportion to the
|
| 73 |
audio's length (20-120 s), so roughly up to five minutes of speech per request
|
| 74 |
- Optimized for English language
|
|
|
|
| 8 |
python_version: "3.12"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: true
|
| 11 |
+
license: cc-by-nc-sa-4.0
|
| 12 |
short_description: Fast English ASR with word timestamps and speaker labels
|
| 13 |
thumbnail: https://huggingface.co/spaces/mazesmazes/tiny-audio/resolve/main/thumbnail.png
|
| 14 |
models:
|
|
|
|
| 22 |
- word-timestamps
|
| 23 |
- speaker-diarization
|
| 24 |
- granite-speech
|
| 25 |
+
- qwen3
|
|
|
|
| 26 |
suggested_hardware: zero-a10g
|
| 27 |
preload_from_hub:
|
| 28 |
- mazesmazes/tiny-audio
|
| 29 |
+
- ibm-granite/granite-speech-5.0-470m-turboctc-nc
|
| 30 |
+
- Qwen/Qwen3-0.6B
|
| 31 |
- Qwen/Qwen3-ForcedAligner-0.6B-hf
|
| 32 |
- nvidia/Nemotron-3-Diarization
|
| 33 |
---
|
|
|
|
| 36 |
|
| 37 |
This Space demonstrates an Automatic Speech Recognition (ASR) model that combines:
|
| 38 |
|
| 39 |
+
- **Granite Speech 5.0 470M non-causal encoder** for audio feature extraction
|
| 40 |
+
- **Qwen3-0.6B decoder**, fully fine-tuned, for text generation
|
| 41 |
|
| 42 |
## Features
|
| 43 |
|
|
|
|
| 48 |
|
| 49 |
## Model Architecture
|
| 50 |
|
| 51 |
+
The model bridges audio and text with a trained projector and a fine-tuned decoder:
|
| 52 |
|
| 53 |
+
1. **Audio Encoder**: Granite Speech 5.0 470M TurboCTC non-causal encoder (frozen)
|
| 54 |
1. **Projection Layer**: 2-layer MLP mapping audio features into the decoder's embedding space
|
| 55 |
+
(~8.4M params)
|
| 56 |
+
1. **Text Decoder**: Qwen3-0.6B (~596M params), fully fine-tuned jointly with the projector
|
|
|
|
| 57 |
|
| 58 |
## Usage
|
| 59 |
|
|
|
|
| 65 |
|
| 66 |
## Limitations
|
| 67 |
|
| 68 |
+
- Audio longer than 28 seconds is transcribed in chunks cut at pauses
|
|
|
|
| 69 |
- Requests run on ZeroGPU, which reserves GPU time from your daily quota in proportion to the
|
| 70 |
audio's length (20-120 s), so roughly up to five minutes of speech per request
|
| 71 |
- Optimized for English language
|
app.py
CHANGED
|
@@ -322,6 +322,23 @@ def build_output_tabs() -> tuple[gr.Tabs, gr.Textbox, gr.HTML, gr.Dataframe, gr.
|
|
| 322 |
return tabs, output_text, conversation_output, timestamps_output, diarization_output
|
| 323 |
|
| 324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
def local_runner(model_path: str) -> Callable[[str, dict[str, Any]], dict[str, Any]]:
|
| 326 |
"""Run the pipeline in this process (on the GPU, on ZeroGPU)."""
|
| 327 |
from transformers import pipeline # noqa: PLC0415 -- server mode runs without it
|
|
@@ -333,6 +350,7 @@ def local_runner(model_path: str) -> Callable[[str, dict[str, Any]], dict[str, A
|
|
| 333 |
trust_remote_code=True,
|
| 334 |
device=pick_device(),
|
| 335 |
)
|
|
|
|
| 336 |
# Load the aligner and diarizer now, not on the first request: on ZeroGPU
|
| 337 |
# each request runs in a forked worker, so a model first loaded there is
|
| 338 |
# thrown away afterwards and reloaded on every call.
|
|
|
|
| 322 |
return tabs, output_text, conversation_output, timestamps_output, diarization_output
|
| 323 |
|
| 324 |
|
| 325 |
+
def merge_lora(model: Any) -> bool:
|
| 326 |
+
"""Fold the decoder's LoRA adapters into its base weights; whether there were any.
|
| 327 |
+
|
| 328 |
+
The pipeline otherwise decodes through live peft adapters: extra fp32
|
| 329 |
+
matmuls on six projections per layer, every token. Merging took decode from
|
| 330 |
+
20.6 to 36.7 tok/s on a Mac, and paired transcripts came back identical
|
| 331 |
+
(scripts/inference.py `merge_lora_adapters` has the measurement). The Space
|
| 332 |
+
only uploads demo/, so this is the same few lines rather than an import.
|
| 333 |
+
A PeftModel forwards `merge_and_unload` to its tuner; a plain decoder has none.
|
| 334 |
+
"""
|
| 335 |
+
merge = getattr(model.language_model, "merge_and_unload", None)
|
| 336 |
+
if merge is None:
|
| 337 |
+
return False
|
| 338 |
+
model.language_model = merge()
|
| 339 |
+
return True
|
| 340 |
+
|
| 341 |
+
|
| 342 |
def local_runner(model_path: str) -> Callable[[str, dict[str, Any]], dict[str, Any]]:
|
| 343 |
"""Run the pipeline in this process (on the GPU, on ZeroGPU)."""
|
| 344 |
from transformers import pipeline # noqa: PLC0415 -- server mode runs without it
|
|
|
|
| 350 |
trust_remote_code=True,
|
| 351 |
device=pick_device(),
|
| 352 |
)
|
| 353 |
+
merge_lora(pipe.model)
|
| 354 |
# Load the aligner and diarizer now, not on the first request: on ZeroGPU
|
| 355 |
# each request runs in a forked worker, so a model first loaded there is
|
| 356 |
# thrown away afterwards and reloaded on every call.
|
requirements.txt
CHANGED
|
@@ -8,6 +8,8 @@ torchaudio
|
|
| 8 |
peft
|
| 9 |
safetensors
|
| 10 |
numpy
|
|
|
|
|
|
|
| 11 |
soundfile
|
| 12 |
spaces
|
| 13 |
# Fast path for Qwen3.5's gated-delta-rule layers (transformers falls back to a
|
|
|
|
| 8 |
peft
|
| 9 |
safetensors
|
| 10 |
numpy
|
| 11 |
+
# Nemotron's streaming feature extractor (speaker diarization) imports it.
|
| 12 |
+
librosa
|
| 13 |
soundfile
|
| 14 |
spaces
|
| 15 |
# Fast path for Qwen3.5's gated-delta-rule layers (transformers falls back to a
|