Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ from transformers import pipeline
|
|
2 |
import gradio as gr
|
3 |
from pytube import YouTube
|
4 |
from datasets import Dataset, Audio
|
|
|
|
|
5 |
|
6 |
pipe1 = pipeline(model="khalidey/ID2223_Lab2_Whisper_SV") # change to "your-username/the-name-you-picked"
|
7 |
pipe2 = pipeline('text-generation', model='birgermoell/swedish-gpt')
|
@@ -19,11 +21,21 @@ def youtube_link(url):
|
|
19 |
path = streams.first().download()
|
20 |
return path
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
def youtube_transcribe(url):
|
23 |
|
24 |
path = youtube_link(url)
|
|
|
25 |
|
26 |
-
audio_dataset = Dataset.from_dict({"audio": list(
|
27 |
text = pipe1(audio_dataset["audio"])["text"]
|
28 |
|
29 |
return text
|
|
|
2 |
import gradio as gr
|
3 |
from pytube import YouTube
|
4 |
from datasets import Dataset, Audio
|
5 |
+
import os
|
6 |
+
from moviepy.editor import AudioFileClip
|
7 |
|
8 |
pipe1 = pipeline(model="khalidey/ID2223_Lab2_Whisper_SV") # change to "your-username/the-name-you-picked"
|
9 |
pipe2 = pipeline('text-generation', model='birgermoell/swedish-gpt')
|
|
|
21 |
path = streams.first().download()
|
22 |
return path
|
23 |
|
24 |
+
def convert_to_wav(path):
|
25 |
+
|
26 |
+
sound = AudioFileClip(path)
|
27 |
+
|
28 |
+
segment = sound.subclip(0, int(sound.duration))
|
29 |
+
segment.write_audiofile(f"segment.wav")
|
30 |
+
|
31 |
+
return f"segment.wav"
|
32 |
+
|
33 |
def youtube_transcribe(url):
|
34 |
|
35 |
path = youtube_link(url)
|
36 |
+
path_wav = convert_to_wav(path)
|
37 |
|
38 |
+
audio_dataset = Dataset.from_dict({"audio": list(path_wav)}).cast_column("audio", Audio(sampling_rate=16000))
|
39 |
text = pipe1(audio_dataset["audio"])["text"]
|
40 |
|
41 |
return text
|