Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
pipe = pipeline(model="ZinebSN/whisper-small-swedish-Test-3000") # change to "your-username/the-name-you-picked"
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return text
|
| 9 |
|
| 10 |
iface = gr.Interface(
|
| 11 |
fn=transcribe,
|
| 12 |
-
inputs=
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
outputs="text",
|
| 17 |
-
|
| 18 |
title="Whisper Small Swedish",
|
| 19 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
| 20 |
)
|
|
|
|
| 1 |
+
from pytube import YouTube
|
| 2 |
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
pipe = pipeline(model="ZinebSN/whisper-small-swedish-Test-3000") # change to "your-username/the-name-you-picked"
|
| 7 |
|
| 8 |
+
def get_audio(url):
|
| 9 |
+
yt = YouTube(url)
|
| 10 |
+
stream = yt.streams.filter(only_audio=True).first()
|
| 11 |
+
out_file=stream.download(output_path=".")
|
| 12 |
+
base, ext = os.path.splitext(out_file)
|
| 13 |
+
new_file = base+'.mp3'
|
| 14 |
+
os.rename(out_file, new_file)
|
| 15 |
+
audio = new_file
|
| 16 |
+
return audio
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def transcribe(audio=None, file=None, youtube=None):
|
| 20 |
+
if (audio is None) and (file is None) and (youtube is None):
|
| 21 |
+
return "No audio provided!"
|
| 22 |
+
elif audio is not None:
|
| 23 |
+
input=audio
|
| 24 |
+
elif file is not None:
|
| 25 |
+
input=file
|
| 26 |
+
elif youtube is not None:
|
| 27 |
+
input=get_audio(youtube)
|
| 28 |
+
text = pipe(input)["text"]
|
| 29 |
return text
|
| 30 |
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=transcribe,
|
| 33 |
+
inputs=[
|
| 34 |
+
gr.Audio(source="microphone", type="filepath", interactive=True),
|
| 35 |
+
gr.Audio(source="upload", type="filepath", interactive=True),
|
| 36 |
+
gr.Text(label="URL (YouTube, etc.)")],
|
| 37 |
+
outputs="text",
|
|
|
|
| 38 |
title="Whisper Small Swedish",
|
| 39 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
| 40 |
)
|