Spaces:
Runtime error
Runtime error
juancopi81
commited on
Commit
•
a09bf24
1
Parent(s):
b56303a
Update transforming/whispertransform.py
Browse files- transforming/whispertransform.py +15 -25
transforming/whispertransform.py
CHANGED
@@ -30,36 +30,26 @@ class WhisperTransform(Transform):
|
|
30 |
"""Creates a new video with transcriptions created by Whisper.
|
31 |
"""
|
32 |
# Create a YouTube object
|
33 |
-
|
34 |
-
yt = YouTube(video.url)
|
35 |
-
except Exception as e:
|
36 |
-
print ("Video not available \n")
|
37 |
-
print(f"Exception: {e}")
|
38 |
-
|
39 |
print(f"Video title and url: {video.title} {video.url}")
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
except Exception as e:
|
46 |
-
print(f"Audio exception print: {e}")
|
47 |
-
|
48 |
-
else:
|
49 |
-
transcription = result["text"]
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
def _get_audio_from_video(self, yt: Any) -> Path:
|
65 |
# TODO: Add credits
|
|
|
30 |
"""Creates a new video with transcriptions created by Whisper.
|
31 |
"""
|
32 |
# Create a YouTube object
|
33 |
+
yt = YouTube(video.url)
|
|
|
|
|
|
|
|
|
|
|
34 |
print(f"Video title and url: {video.title} {video.url}")
|
35 |
|
36 |
+
audio_file = self._get_audio_from_video(yt)
|
37 |
+
result = self.model.transcribe(audio_file,
|
38 |
+
without_timestamps=self.without_timestamps)
|
39 |
+
transcription = result["text"]
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
data = []
|
42 |
+
for seg in result['segments']:
|
43 |
+
data.append(OrderedDict({'start': seg['start'], 'end': seg['end'],'text': seg['text']}))
|
44 |
|
45 |
+
os.remove(audio_file)
|
46 |
|
47 |
+
return YoutubeVideo(channel_name = video.channel_name,
|
48 |
+
url = video.url,
|
49 |
+
title = video.title,
|
50 |
+
description = video.description,
|
51 |
+
transcription = transcription,
|
52 |
+
segments = data)
|
53 |
|
54 |
def _get_audio_from_video(self, yt: Any) -> Path:
|
55 |
# TODO: Add credits
|