Patraskon commited on
Commit
e4f9d2f
1 Parent(s): 67e51a5

Add application file

Browse files
Files changed (2) hide show
  1. app.py +6 -3
  2. requirements.txt +2 -1
app.py CHANGED
@@ -5,6 +5,7 @@ from pytube import YouTube
5
  from pprint import pprint
6
  from moviepy.editor import VideoFileClip
7
  from transformers import pipeline
 
8
 
9
  # Load the Whisper model from Hugging Face
10
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
@@ -38,9 +39,11 @@ def create_audio_file(video_filename):
38
 
39
  def transcribe(audio_path):
40
  try:
41
- # Load the audio file and transcribe it using the Whisper model
42
- audio_file = open(audio_path, "rb")
43
- transcript = transcriber(audio_file)
 
 
44
  return transcript["text"], ""
45
  except Exception as e:
46
  return "", str(e)
 
5
  from pprint import pprint
6
  from moviepy.editor import VideoFileClip
7
  from transformers import pipeline
8
+ import librosa
9
 
10
  # Load the Whisper model from Hugging Face
11
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
 
39
 
40
  def transcribe(audio_path):
41
  try:
42
+ # Load the audio file and convert it to a numpy array
43
+ audio, _ = librosa.load(audio_path, sr=16000)
44
+
45
+ # Transcribe the audio using the Whisper model
46
+ transcript = transcriber(audio)
47
  return transcript["text"], ""
48
  except Exception as e:
49
  return "", str(e)
requirements.txt CHANGED
@@ -2,4 +2,5 @@ gradio
2
  pytube
3
  moviepy
4
  transformers
5
- torch
 
 
2
  pytube
3
  moviepy
4
  transformers
5
+ torch
6
+ librosa