Spaces:
Runtime error
Runtime error
LucFast
commited on
Commit
·
c357dd1
1
Parent(s):
3d11acf
update filepath to audio input
Browse files
app.py
CHANGED
@@ -26,17 +26,16 @@ class GradioInference():
|
|
26 |
"preferredcodec": "wav",
|
27 |
}
|
28 |
],
|
29 |
-
"outtmpl": "tmp
|
30 |
}
|
31 |
|
32 |
with YoutubeDL(ydl_opts) as ydl:
|
33 |
ydl.download(link)
|
34 |
-
return "tmp.wav"
|
35 |
|
36 |
|
37 |
def detect_lang(self):
|
38 |
# load audio and pad/trim it to fit 30 seconds
|
39 |
-
audio = whisper.load_audio("tmp.wav")
|
40 |
audio_segment = whisper.pad_or_trim(audio)
|
41 |
|
42 |
# make log-Mel spectrogram and move to the same device as the model
|
@@ -50,7 +49,7 @@ class GradioInference():
|
|
50 |
|
51 |
def __call__(self, link, lang, size, subs):
|
52 |
if self.yt is None:
|
53 |
-
|
54 |
|
55 |
if size != self.current_size:
|
56 |
self.loaded_model = whisper.load_model(size)
|
@@ -66,7 +65,7 @@ class GradioInference():
|
|
66 |
del options["task"]
|
67 |
transcribe_options = dict(task="transcribe", **options)
|
68 |
translate_options = dict(task="translate", **options)
|
69 |
-
results = self.loaded_model.transcribe("tmp.wav",
|
70 |
|
71 |
if subs == "None":
|
72 |
return results["text"]
|
|
|
26 |
"preferredcodec": "wav",
|
27 |
}
|
28 |
],
|
29 |
+
"outtmpl": f"{os.path.curdir}/tmp.%(ext)s",
|
30 |
}
|
31 |
|
32 |
with YoutubeDL(ydl_opts) as ydl:
|
33 |
ydl.download(link)
|
|
|
34 |
|
35 |
|
36 |
def detect_lang(self):
|
37 |
# load audio and pad/trim it to fit 30 seconds
|
38 |
+
audio = whisper.load_audio(f"{os.path.curdir}/tmp.wav")
|
39 |
audio_segment = whisper.pad_or_trim(audio)
|
40 |
|
41 |
# make log-Mel spectrogram and move to the same device as the model
|
|
|
49 |
|
50 |
def __call__(self, link, lang, size, subs):
|
51 |
if self.yt is None:
|
52 |
+
self.download_videos(link)
|
53 |
|
54 |
if size != self.current_size:
|
55 |
self.loaded_model = whisper.load_model(size)
|
|
|
65 |
del options["task"]
|
66 |
transcribe_options = dict(task="transcribe", **options)
|
67 |
translate_options = dict(task="translate", **options)
|
68 |
+
results = self.loaded_model.transcribe(f"{os.path.curdir}/tmp.wav", **transcribe_options)
|
69 |
|
70 |
if subs == "None":
|
71 |
return results["text"]
|