Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,27 @@ import gradio as gr
|
|
3 |
|
4 |
pipe = pipeline(model="Akseluhr/whisper-small-sv-SE-auhr-v2")
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
if rec is not None:
|
9 |
audio = rec
|
10 |
elif file is not None:
|
11 |
audio = file
|
|
|
|
|
12 |
else:
|
13 |
return "Provide a recording or a file."
|
14 |
|
@@ -21,6 +36,7 @@ iface = gr.Interface(
|
|
21 |
inputs=[
|
22 |
gr.Audio(source="microphone", type="filepath", optional=True),
|
23 |
gr.Audio(source="upload", type="filepath", optional=True),
|
|
|
24 |
],
|
25 |
outputs="text",
|
26 |
title="Whisper Small Swedish",
|
|
|
3 |
|
4 |
pipe = pipeline(model="Akseluhr/whisper-small-sv-SE-auhr-v2")
|
5 |
|
6 |
+
def get_audio(url):
|
7 |
+
yt = YouTube(url)
|
8 |
+
video = yt.streams.filter(only_audio=True).first()
|
9 |
+
out_file=video.download(output_path=".")
|
10 |
+
base, ext = os.path.splitext(out_file)
|
11 |
+
new_file = base+'.mp3'
|
12 |
+
os.rename(out_file, new_file)
|
13 |
+
a = new_file
|
14 |
+
return a
|
15 |
+
|
16 |
+
def get_text(url):
|
17 |
+
result = model.transcribe(get_audio(url))
|
18 |
+
return result['text']
|
19 |
+
|
20 |
+
def transcribe(rec=None, file=None, URL=None):
|
21 |
if rec is not None:
|
22 |
audio = rec
|
23 |
elif file is not None:
|
24 |
audio = file
|
25 |
+
elif url is not None:
|
26 |
+
audio = get_audio(URL)
|
27 |
else:
|
28 |
return "Provide a recording or a file."
|
29 |
|
|
|
36 |
inputs=[
|
37 |
gr.Audio(source="microphone", type="filepath", optional=True),
|
38 |
gr.Audio(source="upload", type="filepath", optional=True),
|
39 |
+
gr.Textbox(placeholder='Enter the Youtube video URL', label='URL', optional=True),
|
40 |
],
|
41 |
outputs="text",
|
42 |
title="Whisper Small Swedish",
|