Ofiroz91 commited on
Commit
0adbfae
โ€ข
1 Parent(s): 39d9fac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -21
app.py CHANGED
@@ -1,11 +1,14 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
  from pydub import AudioSegment
4
  import os
5
  import tempfile
 
 
 
 
6
 
7
- # ื™ืฆื™ืจืช pipeline ืœืชืžืœื•ืœ ื•ืœืกื™ื›ื•ื
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
- # ื—ืœื•ืงืช ื”ืื•ื“ื™ื• ืœืงื˜ืขื™ื ืฉืœ 30 ืฉื ื™ื•ืช
20
- segments = split_audio(audio_file)
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,