Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
from pydub import AudioSegment
|
4 |
import os
|
5 |
import tempfile
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base", task="transcribe")
|
9 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
|
11 |
def summarize_audio_or_video(file_path):
|
@@ -16,14 +19,9 @@ def summarize_audio_or_video(file_path):
|
|
16 |
else:
|
17 |
audio_file = file_path
|
18 |
|
19 |
-
#
|
20 |
-
segments =
|
21 |
-
|
22 |
-
# ืชืืืื ืื ืงืืข ืืืฆืืจืคืืช ืืชืืืื ืืกืืคื
|
23 |
-
transcript = ""
|
24 |
-
for segment in segments:
|
25 |
-
segment_text = transcriber(segment, return_timestamps=True)["text"]
|
26 |
-
transcript += " " + segment_text
|
27 |
|
28 |
# ืกืืืื ืืชืืืื
|
29 |
summary = summarizer(transcript, max_length=50, min_length=25, do_sample=False)[0]["summary_text"]
|
@@ -44,16 +42,6 @@ def convert_video_to_audio(video_file):
|
|
44 |
video.export(temp_audio, format="wav")
|
45 |
return temp_audio
|
46 |
|
47 |
-
def split_audio(audio_file, segment_length=30 * 1000): # 30 ืฉื ืืืช ืืืืืืฉื ืืืช
|
48 |
-
audio = AudioSegment.from_file(audio_file)
|
49 |
-
segments = []
|
50 |
-
for i in range(0, len(audio), segment_length):
|
51 |
-
segment = audio[i:i + segment_length]
|
52 |
-
temp_segment = tempfile.mktemp(suffix=".wav")
|
53 |
-
segment.export(temp_segment, format="wav")
|
54 |
-
segments.append(temp_segment)
|
55 |
-
return segments
|
56 |
-
|
57 |
# ืืืืจืช ืืืฉืง Gradio
|
58 |
interface = gr.Interface(
|
59 |
fn=summarize_audio_or_video,
|
|
|
1 |
import gradio as gr
|
2 |
+
from faster_whisper import WhisperModel
|
3 |
from pydub import AudioSegment
|
4 |
import os
|
5 |
import tempfile
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
# ืืืืจืช ืืืืื ืืชืืืื
|
9 |
+
model = WhisperModel("ivrit-ai/faster-whisper-v2-d4")
|
10 |
|
11 |
+
# ืืืืจืช pipeline ืืกืืืื
|
|
|
12 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
13 |
|
14 |
def summarize_audio_or_video(file_path):
|
|
|
19 |
else:
|
20 |
audio_file = file_path
|
21 |
|
22 |
+
# ืชืืืื ืืืืืื
|
23 |
+
segments, _ = model.transcribe(audio_file, language="he")
|
24 |
+
transcript = " ".join([segment.text for segment in segments])
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# ืกืืืื ืืชืืืื
|
27 |
summary = summarizer(transcript, max_length=50, min_length=25, do_sample=False)[0]["summary_text"]
|
|
|
42 |
video.export(temp_audio, format="wav")
|
43 |
return temp_audio
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# ืืืืจืช ืืืฉืง Gradio
|
46 |
interface = gr.Interface(
|
47 |
fn=summarize_audio_or_video,
|