Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyannote.audio import Pipeline
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
# ืฉืืืคืช ื-Token ืื-Secret
|
6 |
+
hf_token = os.getenv("HF_TOKEN")
|
7 |
+
|
8 |
+
# ืืขืื ืช ืืืืื ืขื ื-Token
|
9 |
+
pipeline = Pipeline.from_pretrained(
|
10 |
+
"pyannote/speaker-diarization",
|
11 |
+
use_auth_token=hf_token
|
12 |
+
)
|
13 |
+
|
14 |
+
# ืคืื ืงืฆืื ืืืืืื ืืืืจืื
|
15 |
+
def diarize(audio):
|
16 |
+
diarization = pipeline(audio)
|
17 |
+
result = []
|
18 |
+
for turn, _, speaker in diarization.itertracks(yield_label=True):
|
19 |
+
result.append(f"{speaker}: {turn.start:.1f}s - {turn.end:.1f}s")
|
20 |
+
return "\n".join(result)
|
21 |
+
|
22 |
+
# ืืืฉืง ืืฉืชืืฉ ืขื Gradio
|
23 |
+
interface = gr.Interface(
|
24 |
+
fn=diarize,
|
25 |
+
inputs="audio",
|
26 |
+
outputs="text",
|
27 |
+
title="Speaker Diarization",
|
28 |
+
description="Upload an audio file to detect speakers and their timestamps."
|
29 |
+
)
|
30 |
+
|
31 |
+
interface.launch()
|