Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
|
|
3 |
|
4 |
pipe1 = pipeline(model="khalidey/ID2223_Lab2_Whisper_SV") # change to "your-username/the-name-you-picked"
|
5 |
pipe2 = pipeline('text-generation', model='birgermoell/swedish-gpt')
|
@@ -9,6 +11,21 @@ def transcribe(audio):
|
|
9 |
generated_text = pipe2(text, max_length=50, num_return_sequences=2)[0]['generated_text']
|
10 |
return text, generated_text
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
with gr.Blocks() as demo:
|
13 |
gr.Markdown("Whisper Small Swedish + Swedish GPT")
|
14 |
gr.Markdown("Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model & text generation with Swedish GPT.")
|
@@ -26,6 +43,12 @@ with gr.Blocks() as demo:
|
|
26 |
gr.Textbox(label="Recognized speech from recordings"),
|
27 |
gr.Textbox(label="Swedish-gpt generated speech from recordings")
|
28 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
upload_button.click(
|
30 |
fn=transcribe,
|
31 |
inputs=upload_file,
|
@@ -36,5 +59,10 @@ with gr.Blocks() as demo:
|
|
36 |
inputs=record_file,
|
37 |
outputs=record_outputs,
|
38 |
)
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
demo.launch()
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
+
from pytube import YouTube
|
4 |
+
|
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')
|
|
|
11 |
generated_text = pipe2(text, max_length=50, num_return_sequences=2)[0]['generated_text']
|
12 |
return text, generated_text
|
13 |
|
14 |
+
def youtube_link(url):
|
15 |
+
|
16 |
+
# Obtains the audio of the youtube video and returns the path of the mp4 file
|
17 |
+
|
18 |
+
streams = YouTube(url).streams.filter(only_audio=True, file_extension='mp4')
|
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": path}).cast_column("audio", Audio(sampling_rate=16000))
|
27 |
+
text = pipe1(audio_dataset["audio"])["text"]
|
28 |
+
|
29 |
with gr.Blocks() as demo:
|
30 |
gr.Markdown("Whisper Small Swedish + Swedish GPT")
|
31 |
gr.Markdown("Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model & text generation with Swedish GPT.")
|
|
|
43 |
gr.Textbox(label="Recognized speech from recordings"),
|
44 |
gr.Textbox(label="Swedish-gpt generated speech from recordings")
|
45 |
]
|
46 |
+
with gr.TabItem("Transcribe from Youtube URL"):
|
47 |
+
url = gr.Text(max_lines=1, label="Transcribe from YouTube URL")
|
48 |
+
youtube_button = gr.Button("Submit for recognition")
|
49 |
+
youtube_outputs = [
|
50 |
+
gr.Textbox(label="Recognized speech from URL"),
|
51 |
+
]
|
52 |
upload_button.click(
|
53 |
fn=transcribe,
|
54 |
inputs=upload_file,
|
|
|
59 |
inputs=record_file,
|
60 |
outputs=record_outputs,
|
61 |
)
|
62 |
+
youtube_button.click(
|
63 |
+
fn=youtube_transcribe,
|
64 |
+
inputs=url,
|
65 |
+
outputs=youtube_outputs,
|
66 |
+
)
|
67 |
|
68 |
demo.launch()
|