Spaces:
Runtime error
Runtime error
Nitzantry1
commited on
Commit
โข
dd2fd57
1
Parent(s):
16d67e4
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,50 @@
|
|
|
|
|
|
1 |
from pyannote.audio import Pipeline
|
2 |
from faster_whisper import WhisperModel
|
3 |
|
4 |
-
#
|
|
|
|
|
|
|
5 |
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization")
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
|
10 |
-
#
|
11 |
def diarize_and_transcribe(audio_file):
|
12 |
-
#
|
13 |
diarization = pipeline(audio_file)
|
14 |
|
15 |
-
#
|
16 |
-
|
|
|
|
|
17 |
for segment, _, speaker in diarization.itertracks(yield_label=True):
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
#
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
from pyannote.audio import Pipeline
|
4 |
from faster_whisper import WhisperModel
|
5 |
|
6 |
+
# ืืชืงื ื ืฉื PyAnnote ืืืืื ืืขืืืื ืื ืืืชืงื
|
7 |
+
os.system('pip install pyannote.audio')
|
8 |
+
|
9 |
+
# ืืขืื ืช ื-Pipeline ืฉื PyAnnote ืืืืืจืืืฆืื
|
10 |
pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization")
|
11 |
|
12 |
+
# ืืขืื ืช ืืืืื ืฉื Whisper ืืชืืืื
|
13 |
+
whisper_model = WhisperModel("openai/whisper-large", device="cuda")
|
14 |
|
15 |
+
# ืคืื ืงืฆืื ืฉืืืฆืขืช ืืืืจืืืฆืื ืืชืืืื
|
16 |
def diarize_and_transcribe(audio_file):
|
17 |
+
# ืฉืื 1: ืืืืจืืืฆืื
|
18 |
diarization = pipeline(audio_file)
|
19 |
|
20 |
+
# ืืฉืชื ื ืืฉืืืจ ืืช ืืชืืืื ืืืืื ืขื ืืืืข ืขื ืืืืืจืื
|
21 |
+
full_transcription = []
|
22 |
+
|
23 |
+
# ืืขืืจ ืขื ืื ืืืงืืขืื ืฉื ืืฆืื ืขื ืืื ืืืืจืืืฆืื
|
24 |
for segment, _, speaker in diarization.itertracks(yield_label=True):
|
25 |
+
# ืืืจืช ืืงืืข ืืืื ืืคืืจืื ืืชืืื ืืชืืืื
|
26 |
+
start_time = segment.start
|
27 |
+
end_time = segment.end
|
28 |
+
|
29 |
+
# ืชืืืื ืืืงืืข ืืขืืจืช Whisper
|
30 |
+
segments, _ = whisper_model.transcribe(audio_file, language="he", task="transcribe",
|
31 |
+
segment_start=start_time, segment_end=end_time)
|
32 |
+
transcription = " ".join([seg.text for seg in segments])
|
33 |
+
|
34 |
+
# ืืืกืคืช ืชืืฆืื ืืชืืืื ืืืืื
|
35 |
+
full_transcription.append(f"Speaker {speaker}: {transcription} (from {start_time:.2f} to {end_time:.2f})")
|
36 |
+
|
37 |
+
# ืืืืจืช ืืชืืืื ืืืื ืขื ืืืืงื ืืืืืจืื
|
38 |
+
return "\n".join(full_transcription)
|
39 |
+
|
40 |
+
# ืืฆืืจืช ืืืฉืง ืืจืืื
|
41 |
+
interface = gr.Interface(
|
42 |
+
fn=diarize_and_transcribe,
|
43 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
44 |
+
outputs="text",
|
45 |
+
title="Speaker Diarization and Transcription",
|
46 |
+
description="Upload an audio file to perform both speaker diarization and transcription."
|
47 |
+
)
|
48 |
+
|
49 |
+
# ืืจืฆืช ืืืคืืืงืฆืื
|
50 |
+
interface.launch()
|