Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,28 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from pyannote.audio import Pipeline
|
| 3 |
|
| 4 |
+
# 讟讜注谉 讗转 讛诪讜讚诇 砖诇 Pyannote 诇讝讬讛讜讬 讚讜讘专讬诐
|
| 5 |
+
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization")
|
| 6 |
|
| 7 |
+
# 驻讜谞拽爪讬讛 诇讘讬爪讜注 讝讬讛讜讬 讚讜讘专讬诐
|
| 8 |
+
def diarize(audio_file):
|
| 9 |
+
diarization = pipeline(audio_file)
|
| 10 |
+
segments = []
|
| 11 |
+
for turn, _, speaker in diarization.itertracks(yield_label=True):
|
| 12 |
+
segments.append({
|
| 13 |
+
"start": turn.start,
|
| 14 |
+
"end": turn.end,
|
| 15 |
+
"speaker": speaker
|
| 16 |
+
})
|
| 17 |
+
return segments
|
| 18 |
+
|
| 19 |
+
# 讛讙讚专转 诪诪砖拽 Gradio
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=diarize,
|
| 22 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
| 23 |
+
outputs="json",
|
| 24 |
+
description="Upload an audio file to get speaker diarization (timestamps and speaker IDs only)."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# 讛专爪转 讛诪诪砖拽
|
| 28 |
+
interface.launch()
|