adjoint-bass commited on
Commit
e559252
1 Parent(s): 556e022

update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -27
app.py CHANGED
@@ -1,38 +1,48 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
  from pytube import YouTube
 
4
 
5
- pipe = pipeline(model = 'CsanadT/whisper-small-se')
6
 
7
- def live_performance(audio):
8
- text = pipe(audio)['text']
9
  return text
10
 
11
- def url_performance(link):
12
- yt = YouTube(str(link))
13
- audio= yt.streams.filter(only_audio=True).first()
14
- text = pipe(audio)['text']
15
  return text
16
 
17
-
18
-
19
- with gr.Blocks() as demo:
20
- with gr.Tab('Live audio'):
21
- iface = gr.Interface(
22
- fn=live_performance,
23
- inputs=gr.Audio(source="microphone", type="filepath"),
24
- outputs="text",
25
- title="Whisper Small Swedish",
26
- description="Real-time demo for swedish speech recognition using a fine-tuned Whisper small model."
27
- )
28
-
29
- with gr.Tab('Transcription from URL'):
30
- iface = gr.Interface(
31
- fn=url_performance,
32
- inputs=gr.Textbox(label='Paste the UL here'),
33
- outputs="text",
34
- title="Whisper Small Swedish",
35
- description="Real-time demo for swedish speech recognition using a fine-tuned Whisper small model."
36
- )
 
 
 
 
 
 
 
 
 
37
 
38
  demo.launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
  from pytube import YouTube
4
+ import os
5
 
6
+ pipe = pipeline(model="CsanadT/whisper_small_sv")
7
 
8
+ def transcribe_live(audio):
9
+ text = pipe(audio)["text"]
10
  return text
11
 
12
+ def transcribe_url(url):
13
+ youtube = YouTube(str(url))
14
+ audio = youtube.streams.filter(only_audio=True).first().download('yt_video')
15
+ text = pipe(audio)["text"]
16
  return text
17
 
18
+ def transcribe_file(audio):
19
+ rate, y = audio
20
+ text = pipe(y)["text"]
21
+ return text
22
+
23
+ url_demo = gr.Interface(
24
+ fn = transcribe_url,
25
+ inputs = "text",
26
+ outputs = "text",
27
+ title = "Swedish Whisper",
28
+ description = "Fine-tuned Whisper model for swedish audio transcription",
29
+ )
30
+
31
+ voice_demo = gr.Interface(
32
+ fn=transcribe_live,
33
+ inputs=gr.Audio(source="microphone", type="filepath"),
34
+ outputs="text",
35
+ title="Whisper Swedish",
36
+ description="Fine-tuned Whisper model for swedish audio transcription",
37
+ )
38
+
39
+ file_demo = gr.Interface(
40
+ fn = transcribe_file,
41
+ inputs=gr.Audio(file_count="single"),
42
+ outputs="text",
43
+ title="Swedish Whisper",
44
+ description="Fine-tuned Whisper model for swedish audio transcription",
45
+ )
46
+ demo = gr.TabbedInterface([url_demo, voice_demo, file_demo], ["YouTube Video to Text", "Audio to Text"])
47
 
48
  demo.launch()