Spaces:
Runtime error
Runtime error
import os | |
import gradio as gr | |
from pyannote.audio import Pipeline | |
from faster_whisper import WhisperModel | |
# ืืชืงื ื ืฉื PyAnnote ืืืืื ืืขืืืื ืื ืืืชืงื | |
os.system('pip install pyannote.audio') | |
# ืืขืื ืช ื-Pipeline ืฉื PyAnnote ืืืืืจืืืฆืื | |
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization") | |
# ืืขืื ืช ืืืืื ืฉื Whisper ืืชืืืื | |
whisper_model = WhisperModel("openai/whisper-large", device="cuda") | |
# ืคืื ืงืฆืื ืฉืืืฆืขืช ืืืืจืืืฆืื ืืชืืืื | |
def diarize_and_transcribe(audio_file): | |
# ืฉืื 1: ืืืืจืืืฆืื | |
diarization = pipeline(audio_file) | |
# ืืฉืชื ื ืืฉืืืจ ืืช ืืชืืืื ืืืืื ืขื ืืืืข ืขื ืืืืืจืื | |
full_transcription = [] | |
# ืืขืืจ ืขื ืื ืืืงืืขืื ืฉื ืืฆืื ืขื ืืื ืืืืจืืืฆืื | |
for segment, _, speaker in diarization.itertracks(yield_label=True): | |
# ืืืจืช ืืงืืข ืืืื ืืคืืจืื ืืชืืื ืืชืืืื | |
start_time = segment.start | |
end_time = segment.end | |
# ืชืืืื ืืืงืืข ืืขืืจืช Whisper | |
segments, _ = whisper_model.transcribe(audio_file, language="he", task="transcribe", | |
segment_start=start_time, segment_end=end_time) | |
transcription = " ".join([seg.text for seg in segments]) | |
# ืืืกืคืช ืชืืฆืื ืืชืืืื ืืืืื | |
full_transcription.append(f"Speaker {speaker}: {transcription} (from {start_time:.2f} to {end_time:.2f})") | |
# ืืืืจืช ืืชืืืื ืืืื ืขื ืืืืงื ืืืืืจืื | |
return "\n".join(full_transcription) | |
# ืืฆืืจืช ืืืฉืง ืืจืืื | |
interface = gr.Interface( | |
fn=diarize_and_transcribe, | |
inputs=gr.Audio(source="upload", type="filepath"), | |
outputs="text", | |
title="Speaker Diarization and Transcription", | |
description="Upload an audio file to perform both speaker diarization and transcription." | |
) | |
# ืืจืฆืช ืืืคืืืงืฆืื | |
interface.launch() | |