Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from pyannote.audio import Pipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Initialize the diarization pipeline
|
| 6 |
+
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization-3.1", use_auth_token="YOUR_HF_TOKEN")
|
| 7 |
+
pipeline.to(torch.device("cuda" if torch.cuda.is_available() else "cpu"))
|
| 8 |
+
|
| 9 |
+
def diarize(audio):
|
| 10 |
+
diarization = pipeline({"waveform": audio, "sample_rate": 16000})
|
| 11 |
+
speaker1_segments = []
|
| 12 |
+
speaker2_segments = []
|
| 13 |
+
for segment, _, speaker in diarization.itertracks(yield_label=True):
|
| 14 |
+
if speaker == 'SPEAKER_1':
|
| 15 |
+
speaker1_segments.append((segment.start, segment.end))
|
| 16 |
+
elif speaker == 'SPEAKER_2':
|
| 17 |
+
speaker2_segments.append((segment.start, segment.end))
|
| 18 |
+
return speaker1_segments, speaker2_segments
|
| 19 |
+
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=diarize,
|
| 22 |
+
inputs=gr.Audio(source="upload", type="numpy"),
|
| 23 |
+
outputs=[
|
| 24 |
+
gr.Textbox(label="Speaker 1 Segments (start, end)"),
|
| 25 |
+
gr.Textbox(label="Speaker 2 Segments (start, end)")
|
| 26 |
+
],
|
| 27 |
+
title="Speaker Diarization",
|
| 28 |
+
description="Upload an audio file and get the segments where each speaker talks."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
interface.launch()
|