palli23 commited on
Commit
6d11b37
·
1 Parent(s): c27f348

diarization1Mæló

Browse files
Files changed (2) hide show
  1. app.py +13 -7
  2. requirements.txt +4 -3
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py – FIXED ECAPA (SpeechBrain Native) + Whisper-small – ZeroGPU
2
  import os
3
  import gradio as gr
4
  import spaces
@@ -7,17 +7,21 @@ import numpy as np
7
  from pydub import AudioSegment
8
  from sklearn.cluster import AgglomerativeClustering
9
  from transformers import pipeline
10
- from speechbrain.inference.speaker import EncoderClassifier # ← Native SpeechBrain
11
  import torch
12
  import tempfile
13
 
 
 
 
 
14
  # ÞITT Whisper-small model
15
  ASR_MODEL = "palli23/whisper-small-sam_spjall"
16
 
17
- # SpeechBrain ECAPA (native – no Transformers error)
18
  embedder = EncoderClassifier.from_hparams(
19
  source="speechbrain/spkrec-ecapa-voxceleb",
20
- savedir="tmp_ecapa_cache" # local cache
21
  )
22
 
23
  # Hlaða ASR á GPU
@@ -51,8 +55,10 @@ def extract_speech_segments(path):
51
 
52
  def get_embedding(segment):
53
  with torch.no_grad():
54
- emb = embedder.encode_batch(torch.tensor(segment).unsqueeze(0).float() / 32768.0)
55
- return emb.squeeze().numpy()
 
 
56
 
57
  @spaces.GPU(duration=120)
58
  def transcribe_with_speakers(audio_path):
@@ -85,7 +91,7 @@ def transcribe_with_speakers(audio_path):
85
  # Interface
86
  with gr.Blocks() as demo:
87
  gr.Markdown("# Íslenskt ASR + Mælendagreining (WebRTC + ECAPA)")
88
- gr.Markdown("**Whisper-small + SpeechBrain ECAPA · Virkar á ZeroGPU**")
89
 
90
  audio = gr.Audio(type="filepath")
91
  btn = gr.Button("Transcribe með mælendum", variant="primary")
 
1
+ # app.py – FIXED SpeechBrain Torchaudio Error – ZeroGPU Compatible
2
  import os
3
  import gradio as gr
4
  import spaces
 
7
  from pydub import AudioSegment
8
  from sklearn.cluster import AgglomerativeClustering
9
  from transformers import pipeline
10
+ from speechbrain.inference.speaker import EncoderClassifier # Native SpeechBrain
11
  import torch
12
  import tempfile
13
 
14
+ # Skip backend check (fixes Torchaudio 2.9 error)
15
+ import warnings
16
+ warnings.filterwarnings("ignore", message="torchaudio.*")
17
+
18
  # ÞITT Whisper-small model
19
  ASR_MODEL = "palli23/whisper-small-sam_spjall"
20
 
21
+ # SpeechBrain ECAPA (native – with backend skip)
22
  embedder = EncoderClassifier.from_hparams(
23
  source="speechbrain/spkrec-ecapa-voxceleb",
24
+ savedir="tmp_ecapa_cache" # local cache to avoid re-download
25
  )
26
 
27
  # Hlaða ASR á GPU
 
55
 
56
  def get_embedding(segment):
57
  with torch.no_grad():
58
+ # Normalize to [-1, 1]
59
+ sig = torch.tensor(segment).float() / 32768.0
60
+ emb = embedder.encode_batch(sig.unsqueeze(0).to("cuda"))
61
+ return emb.squeeze().cpu().numpy()
62
 
63
  @spaces.GPU(duration=120)
64
  def transcribe_with_speakers(audio_path):
 
91
  # Interface
92
  with gr.Blocks() as demo:
93
  gr.Markdown("# Íslenskt ASR + Mælendagreining (WebRTC + ECAPA)")
94
+ gr.Markdown("**Whisper-small + SpeechBrain ECAPA · Fixed Torchaudio 2.9**")
95
 
96
  audio = gr.Audio(type="filepath")
97
  btn = gr.Button("Transcribe með mælendum", variant="primary")
requirements.txt CHANGED
@@ -1,10 +1,11 @@
1
  gradio
2
  transformers
3
- torch
4
- spaces
5
  speechbrain
6
  webrtcvad
7
  pydub
8
  numpy
9
  scikit-learn
10
- soundfile
 
 
1
  gradio
2
  transformers
3
+ torch==2.6.0
4
+ torchaudio==2.8.1 # ← FIX: Compatible with SpeechBrain (no list_audio_backends removal)
5
  speechbrain
6
  webrtcvad
7
  pydub
8
  numpy
9
  scikit-learn
10
+ soundfile
11
+ spaces