Chrysoula commited on
Commit
1383129
·
1 Parent(s): 667b1f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -14
app.py CHANGED
@@ -1,25 +1,43 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
3
 
4
  pipe = pipeline(model="Hoft/whisper-small-swedish-asr") # change to "your-username/the-name-you-picked"
5
 
6
- def transcribe(audio, file):
7
- print("AUDIO:",audio)
8
- print("FILE:", file)
9
- if audio is not None:
10
- text = pipe(audio)["text"]
11
- return text
12
- if file is not None:
13
- text = pipe(file)["text"]
14
- return text
15
-
16
- iface = gr.Interface(
17
- fn=transcribe,
18
- inputs=[gr.Audio(source="microphone", type="filepath"), gr.File()],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  outputs="text",
20
  title="Whisper Small Swedish",
21
  description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
22
  )
23
 
 
 
24
 
25
- iface.launch()
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ import pytube as pt
4
 
5
  pipe = pipeline(model="Hoft/whisper-small-swedish-asr") # change to "your-username/the-name-you-picked"
6
 
7
+ def microphone_transcribe(audio):
8
+ text = pipe(audio)["text"]
9
+ return text
10
+
11
+ def youtube_transcribe(url):
12
+ yt_url = pt.YouTube(url)
13
+
14
+ stream = yt.streams.filter(only_audio=True)[0]
15
+ stream.download(filename="audio.mp3")
16
+
17
+ text = pipe("audio.mp3")["text"]
18
+
19
+ return text
20
+
21
+
22
+ app = gr.Blocks()
23
+
24
+ microphone_tab = gr.Interface(
25
+ fn=microphone_transcribe,
26
+ inputs=gr.Audio(source="microphone", type="filepath"),
27
+ outputs="text",
28
+ title="Whisper Small Swedish",
29
+ description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
30
+ )
31
+
32
+ youtube_tab = gr.Interface(
33
+ fn=youtube_transcribe,
34
+ inputs=[gr.inputs.Textbox(lines=1, placeholder="Paste the URL to a YouTube video", label="URL")],
35
  outputs="text",
36
  title="Whisper Small Swedish",
37
  description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
38
  )
39
 
40
+ with app:
41
+ gr.TabbedInterface([microphone_tab, youtube_tab], ["Microphone", "YouTube"])
42
 
43
+ app.launch(enable_queue=True)