Spaces:
Runtime error
Runtime error
Commit
·
d357f9b
1
Parent(s):
5c20ea7
Update transforming/whispertransform.py
Browse files- transforming/whispertransform.py +19 -14
transforming/whispertransform.py
CHANGED
@@ -40,22 +40,27 @@ class WhisperTransform(Transform):
|
|
40 |
print(f"Video title and url: {video.title} {video.url}")
|
41 |
audio_file = self._get_audio_from_video(yt)
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
def _get_audio_from_video(self, yt: Any) -> Path:
|
61 |
# TODO: Add credits
|
|
|
40 |
print(f"Video title and url: {video.title} {video.url}")
|
41 |
audio_file = self._get_audio_from_video(yt)
|
42 |
|
43 |
+
try:
|
44 |
+
result = self.model.transcribe(audio_file,
|
45 |
+
without_timestamps=self.without_timestamps)
|
46 |
+
except Exception as e:
|
47 |
+
print(f"Audio exception print: {e}")
|
48 |
+
pass
|
49 |
+
else:
|
50 |
+
transcription = result["text"]
|
51 |
+
|
52 |
+
data = []
|
53 |
+
for seg in result['segments']:
|
54 |
+
data.append(OrderedDict({'start': seg['start'], 'end': seg['end'],'text': seg['text']}))
|
55 |
|
56 |
+
os.remove(audio_file)
|
57 |
|
58 |
+
return YoutubeVideo(channel_name = video.channel_name,
|
59 |
+
url = video.url,
|
60 |
+
title = video.title,
|
61 |
+
description = video.description,
|
62 |
+
transcription = transcription,
|
63 |
+
segments = data)
|
64 |
|
65 |
def _get_audio_from_video(self, yt: Any) -> Path:
|
66 |
# TODO: Add credits
|