Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import tempfile
|
| 3 |
import whisperx
|
| 4 |
-
from
|
| 5 |
import pandas as pd
|
| 6 |
import librosa
|
| 7 |
import soundfile as sf
|
|
@@ -25,9 +25,19 @@ Segment: Any = None
|
|
| 25 |
|
| 26 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 27 |
token = os.environ.get("HF_TOKEN")
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
model_name = "medium"
|
| 32 |
class TimelineItem(BaseModel):
|
| 33 |
start: float
|
|
@@ -192,7 +202,7 @@ def analyze_audio(audio_file: str,
|
|
| 192 |
if perform_diarization:
|
| 193 |
print("Performing speaker diarization (Requires HF_TOKEN)...")
|
| 194 |
try:
|
| 195 |
-
diarize_output =
|
| 196 |
for segment, _, label in diarize_output.itertracks(yield_label=True):
|
| 197 |
print(f"start={segment.start:.1f}s stop={segment.end:.1f}s {label}")
|
| 198 |
except Exception as e:
|
|
|
|
| 1 |
import os
|
| 2 |
import tempfile
|
| 3 |
import whisperx
|
| 4 |
+
from pyannote.audio import Pipeline
|
| 5 |
import pandas as pd
|
| 6 |
import librosa
|
| 7 |
import soundfile as sf
|
|
|
|
| 25 |
|
| 26 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 27 |
token = os.environ.get("HF_TOKEN")
|
| 28 |
+
try:
|
| 29 |
+
if token:
|
| 30 |
+
diarization_pipeline = Pipeline.from_pretrained(
|
| 31 |
+
"pyannote/speaker-diarization-3.1",
|
| 32 |
+
use_auth_token=token
|
| 33 |
+
)
|
| 34 |
+
diarization_pipeline.to(torch.device(device))
|
| 35 |
+
else:
|
| 36 |
+
diarization_pipeline = None
|
| 37 |
+
except Exception as e:
|
| 38 |
+
print(f"Error loading pyannote pipeline: {type(e).__name__}: {e}. Diarization will be skipped.")
|
| 39 |
+
diarization_pipeline = None
|
| 40 |
+
global_diarizer = diarization_pipeline
|
| 41 |
model_name = "medium"
|
| 42 |
class TimelineItem(BaseModel):
|
| 43 |
start: float
|
|
|
|
| 202 |
if perform_diarization:
|
| 203 |
print("Performing speaker diarization (Requires HF_TOKEN)...")
|
| 204 |
try:
|
| 205 |
+
diarize_output = global_diarizer(audio_for_model)
|
| 206 |
for segment, _, label in diarize_output.itertracks(yield_label=True):
|
| 207 |
print(f"start={segment.start:.1f}s stop={segment.end:.1f}s {label}")
|
| 208 |
except Exception as e:
|