linneafr commited on
Commit
456d766
β€’
1 Parent(s): 7dc49ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+ from pytube import YouTube
4
+
5
+ pipe = pipeline(model="TeoJM/whisper-small-se") # change to "your-username/the-name-you-picked"
6
+
7
+
8
+
9
+
10
+ def transcribe(audio):
11
+ text = pipe(audio)["text"]
12
+ return text
13
+
14
+
15
+ def get_audio_from_youtube(url):
16
+ streams = YouTube(url).streams.filter(only_audio=True, file_extension='mp4')
17
+ path = streams.first().download()
18
+
19
+ text = transcribe(path)
20
+ return text
21
+
22
+
23
+
24
+
25
+ with gr.Blocks() as iface:
26
+ with gr.TabItem("Record from microphone"):
27
+ filefrom_mic = gr.Audio(source="microphone", type="filepath")
28
+ button_mic = gr.Button("Submit audio")
29
+ outputs_mic = [
30
+ gr.Textbox(label="Outputs"),
31
+ ]
32
+ with gr.TabItem("Transcribe from a Youtube video"):
33
+ url = gr.Text(max_lines=1, label="Insert YouTube URL", value="https://www.youtube.com/watch?v=db2cCDUJBNk&t=1s")
34
+ button_yt = gr.Button("Submit video")
35
+ outputs_yt = [
36
+ gr.Textbox(label="Outputs")
37
+ ]
38
+ button_mic.click(
39
+ fn=transcribe,
40
+ inputs=filefrom_mic,
41
+ outputs=outputs_mic,
42
+ )
43
+ button_yt.click(
44
+ fn=get_audio_from_youtube,
45
+ inputs=url,
46
+ outputs=outputs_yt,
47
+ )
48
+
49
+
50
+
51
+ iface.launch()