Update app.py
Browse files
app.py
CHANGED
|
@@ -8,17 +8,14 @@ pipeline = Pipeline.from_pretrained(
|
|
| 8 |
"pyannote/speaker-diarization-community-1", token=os.getenv('HF_TOKEN')
|
| 9 |
)
|
| 10 |
|
| 11 |
-
def diarize(
|
| 12 |
"""
|
| 13 |
Perform speaker diarization on uploaded audio file.
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
| 17 |
-
tmp.write(audio_file.read())
|
| 18 |
-
tmp_path = tmp.name
|
| 19 |
|
| 20 |
# Run diarization
|
| 21 |
-
diarization = pipeline(
|
| 22 |
|
| 23 |
# Collect readable results
|
| 24 |
results = []
|
|
@@ -27,8 +24,6 @@ def diarize(audio_file):
|
|
| 27 |
f"{speaker}: {turn.start:.1f}s β {turn.end:.1f}s"
|
| 28 |
)
|
| 29 |
|
| 30 |
-
# Clean up
|
| 31 |
-
os.remove(tmp_path)
|
| 32 |
|
| 33 |
return "\n".join(results)
|
| 34 |
|
|
@@ -36,7 +31,7 @@ def diarize(audio_file):
|
|
| 36 |
# ποΈ Gradio interface
|
| 37 |
demo = gr.Interface(
|
| 38 |
fn=diarize,
|
| 39 |
-
inputs=gr.Audio(type="
|
| 40 |
outputs=gr.Textbox(label="Speaker Segments"),
|
| 41 |
title="ποΈ Speaker Diarization Demo",
|
| 42 |
description="Upload an audio file and detect who speaks when using Pyannote Audio."
|
|
|
|
| 8 |
"pyannote/speaker-diarization-community-1", token=os.getenv('HF_TOKEN')
|
| 9 |
)
|
| 10 |
|
| 11 |
+
def diarize(audio_file_path):
|
| 12 |
"""
|
| 13 |
Perform speaker diarization on uploaded audio file.
|
| 14 |
"""
|
| 15 |
+
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Run diarization
|
| 18 |
+
diarization = pipeline(audio_file_path)
|
| 19 |
|
| 20 |
# Collect readable results
|
| 21 |
results = []
|
|
|
|
| 24 |
f"{speaker}: {turn.start:.1f}s β {turn.end:.1f}s"
|
| 25 |
)
|
| 26 |
|
|
|
|
|
|
|
| 27 |
|
| 28 |
return "\n".join(results)
|
| 29 |
|
|
|
|
| 31 |
# ποΈ Gradio interface
|
| 32 |
demo = gr.Interface(
|
| 33 |
fn=diarize,
|
| 34 |
+
inputs=gr.Audio(type="filepath", label="Upload Audio (.wav)"),
|
| 35 |
outputs=gr.Textbox(label="Speaker Segments"),
|
| 36 |
title="ποΈ Speaker Diarization Demo",
|
| 37 |
description="Upload an audio file and detect who speaks when using Pyannote Audio."
|