mazesmazes commited on
Commit
0834b82
·
verified ·
1 Parent(s): f1a4b23

Deploy demo to HF Space

Browse files
Files changed (3) hide show
  1. README.md +5 -4
  2. __pycache__/app.cpython-312.pyc +0 -0
  3. app.py +26 -4
README.md CHANGED
@@ -5,7 +5,7 @@ colorFrom: purple
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: "6.26.0"
8
- python_version: "3.11"
9
  app_file: app.py
10
  pinned: false
11
  license: mit
@@ -19,7 +19,7 @@ tags:
19
  - qwen3.5
20
  - lora
21
  - mlp
22
- suggested_hardware: cpu-basic
23
  preload_from_hub:
24
  - mazesmazes/tiny-audio
25
  - ibm-granite/granite-speech-5.0-470m-turboctc
@@ -55,11 +55,12 @@ The model bridges audio and text with a trained projector and LoRA adapters:
55
  1. **Upload an audio file** (WAV, MP3, etc.) or **record directly** using your microphone
56
  2. Click **"Transcribe"** to convert speech to text
57
  3. The transcription will appear in the output box
58
- 4. Optionally tick **Word Timestamps** or **Speaker Diarization**. If you know how many people are speaking, set **Number of Speakers**: auto-detection can split one voice into several speakers on short clips
59
 
60
  ## Limitations
61
 
62
- - Best results on clips under 30 seconds
 
63
  - Optimized for English language
64
  - Best performance with clear speech and minimal background noise
65
 
 
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: "6.26.0"
8
+ python_version: "3.10"
9
  app_file: app.py
10
  pinned: false
11
  license: mit
 
19
  - qwen3.5
20
  - lora
21
  - mlp
22
+ suggested_hardware: zero-a10g
23
  preload_from_hub:
24
  - mazesmazes/tiny-audio
25
  - ibm-granite/granite-speech-5.0-470m-turboctc
 
55
  1. **Upload an audio file** (WAV, MP3, etc.) or **record directly** using your microphone
56
  2. Click **"Transcribe"** to convert speech to text
57
  3. The transcription will appear in the output box
58
+ 4. Optionally tick **Word Timestamps** or **Speaker Diarization**. If you know how many people are speaking, set **Number of Speakers**: it caps how many speakers are kept
59
 
60
  ## Limitations
61
 
62
+ - Plain transcription works best on clips up to about 19 seconds (the training length); with timestamps or diarization on, longer audio is transcribed in chunks automatically
63
+ - Each request gets up to 120 seconds of GPU time
64
  - Optimized for English language
65
  - Best performance with clear speech and minimal background noise
66
 
__pycache__/app.cpython-312.pyc CHANGED
Binary files a/__pycache__/app.cpython-312.pyc and b/__pycache__/app.cpython-312.pyc differ
 
app.py CHANGED
@@ -9,6 +9,18 @@ Gradio app for ASR model with support for:
9
 
10
  import os
11
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Fix OpenMP environment variable if invalid
13
  if not os.environ.get("OMP_NUM_THREADS", "").isdigit():
14
  os.environ["OMP_NUM_THREADS"] = "1"
@@ -19,6 +31,7 @@ os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
19
  # Disable tokenizer parallelism warning
20
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
21
 
 
22
  from typing import Annotated
23
 
24
  import gradio as gr
@@ -86,6 +99,16 @@ def create_demo(model_path="mazesmazes/tiny-audio"):
86
  trust_remote_code=True,
87
  device=device,
88
  )
 
 
 
 
 
 
 
 
 
 
89
 
90
  def process_audio(audio, show_timestamps, show_diarization, num_speakers=0):
91
  """Process audio file for transcription."""
@@ -98,13 +121,12 @@ def create_demo(model_path="mazesmazes/tiny-audio"):
98
  kwargs["return_timestamps"] = True
99
  if show_diarization:
100
  kwargs["return_speakers"] = True
101
- # Auto-detection tends to over-split short clips; a known count
102
- # pins the clustering. 0 means auto.
103
  if num_speakers and int(num_speakers) > 0:
104
  kwargs["num_speakers"] = int(num_speakers)
105
 
106
- # Transcribe the audio
107
- result = pipe(audio, **kwargs)
108
 
109
  # Format outputs
110
  transcript = result.get("text", "")
 
9
 
10
  import os
11
 
12
+ # ZeroGPU: `spaces` must be imported before anything that touches CUDA (torch,
13
+ # transformers). It is preinstalled on Spaces; locally the decorator is a no-op.
14
+ try:
15
+ import spaces
16
+
17
+ gpu = spaces.GPU(duration=120)
18
+ except ImportError:
19
+
20
+ def gpu(fn):
21
+ return fn
22
+
23
+
24
  # Fix OpenMP environment variable if invalid
25
  if not os.environ.get("OMP_NUM_THREADS", "").isdigit():
26
  os.environ["OMP_NUM_THREADS"] = "1"
 
31
  # Disable tokenizer parallelism warning
32
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
33
 
34
+ import sys
35
  from typing import Annotated
36
 
37
  import gradio as gr
 
99
  trust_remote_code=True,
100
  device=device,
101
  )
102
+ # Load the aligner and diarizer now, not on the first request: on ZeroGPU
103
+ # each request runs in a forked worker, so a model first loaded there is
104
+ # thrown away afterwards and reloaded on every call.
105
+ pipeline_module = sys.modules[type(pipe).__module__]
106
+ pipeline_module.QwenForcedAligner.get_instance()
107
+ pipeline_module.NemotronDiarizer.get_instance()
108
+
109
+ @gpu
110
+ def run_pipeline(audio, kwargs):
111
+ return pipe(audio, **kwargs)
112
 
113
  def process_audio(audio, show_timestamps, show_diarization, num_speakers=0):
114
  """Process audio file for transcription."""
 
121
  kwargs["return_timestamps"] = True
122
  if show_diarization:
123
  kwargs["return_speakers"] = True
124
+ # A known count caps the speakers Nemotron keeps. 0 means auto.
 
125
  if num_speakers and int(num_speakers) > 0:
126
  kwargs["num_speakers"] = int(num_speakers)
127
 
128
+ # Transcribe the audio (on the GPU, on ZeroGPU)
129
+ result = run_pipeline(audio, kwargs)
130
 
131
  # Format outputs
132
  transcript = result.get("text", "")