Nitzantry1's picture
Update app.py
30323fc verified
import gradio as gr
from pyannote.audio import Pipeline
import os
# ื˜ื•ืขืŸ ืืช ื”-Token ืžืžืขืจื›ืช ืžืฉืชื ื™ ื”ืกื‘ื™ื‘ื”
auth_token = os.getenv("HF_AUTH_TOKEN")
# ื˜ื•ืขืŸ ืืช ื”ืžื•ื“ืœ ืฉืœ Pyannote ืœื–ื™ื”ื•ื™ ื“ื•ื‘ืจื™ื ืขื ื”-Token
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization", use_auth_token=auth_token)
# ืคื•ื ืงืฆื™ื” ืœื‘ื™ืฆื•ืข ื–ื™ื”ื•ื™ ื“ื•ื‘ืจื™ื
def diarize(audio_file):
diarization = pipeline(audio_file)
segments = []
for turn, _, speaker in diarization.itertracks(yield_label=True):
segments.append({
"start": turn.start,
"end": turn.end,
"speaker": speaker
})
return segments
# ื”ื’ื“ืจืช ืžืžืฉืง Gradio
interface = gr.Interface(
fn=diarize,
inputs=gr.Audio(type="filepath"), # ืฉื™ืžื•ืฉ ื‘ืคืจืžื˜ืจ ื”ืžืชืื™ื ืฉืœ Gradio
outputs="json",
description="Upload an audio file to get speaker diarization (timestamps and speaker IDs only)."
)
# ื”ืจืฆืช ื”ืžืžืฉืง
interface.launch()