gianTheo commited on
Commit
7e7af56
·
1 Parent(s): 4e08dc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -7
app.py CHANGED
@@ -1,18 +1,60 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
 
 
 
 
 
 
 
3
 
4
- pipe = pipeline(model="farsipal/whisper-small-el") # change to "your-username/the-name-you-picked"
5
 
6
  def transcribe(audio):
7
  text = pipe(audio)["text"]
8
  return text
9
 
10
- iface = gr.Interface(
11
- fn=transcribe,
12
- inputs=gr.Audio(sources="microphone", type="filepath"),
 
 
 
 
 
 
 
 
 
 
13
  outputs="text",
14
- title="Whisper Greek Transcription",
15
- description="Realtime demo for Greek speech recognition using a fine-tuned Whisper model.",
 
16
  )
17
 
18
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ import torch
4
+ import pytube as pt
5
+
6
+ checkpoint = "farsipal/whisper-small-el"
7
+ device = 0 if torch.cuda.is_available() else "cpu"
8
+ print(device)
9
+
10
+ pipe = pipeline(task = "automatic-speech-recognition", model = checkpoint,chunk_length_s=30,device = device)
11
 
 
12
 
13
  def transcribe(audio):
14
  text = pipe(audio)["text"]
15
  return text
16
 
17
+ def transcribe_url(yt_url):
18
+ yt = pt.YouTube(yt_url)
19
+ stream = yt.streams.filter(only_audio=True)[0]
20
+ stream.download(filename = "audio.mp3")
21
+ text = pipe("audio.mp3")["text"]
22
+ return text
23
+
24
+
25
+ demo = gr.Blocks()
26
+
27
+ microphone_interface = gr.Interface(
28
+ fn=transcribe,
29
+ inputs = gr.Audio(sources="microphone", type="filepath"),
30
  outputs="text",
31
+ title="Whisper Small Greek Finetuned raw microphone audio",
32
+ description="Realtime demo for Greek speech recognition using a fine-tuned Whisper small model."
33
+
34
  )
35
 
36
+
37
+ file_interface = gr.Interface(
38
+ fn=transcribe,
39
+ inputs = gr.Audio(sources="upload", type="filepath"),
40
+ outputs="text",
41
+ title="Whisper Small Greek Finetuned for audio file.",
42
+ description="Realtime demo for Greek speech recognition using a fine-tuned Whisper small model."
43
+
44
+ )
45
+
46
+
47
+ url_interface = gr.Interface(
48
+ fn = transcribe_url,
49
+ inputs = gr.Textbox(lines=1, placeholder="Paste the URL to a YouTube video here", label="YouTube URL"),
50
+ outputs = "text",
51
+ title = "Whisper Small Greek Finetuned for URL transcription",
52
+ description = "Realtime demo for Greek speech recognition using a fine-tuned Whisper small model."
53
+
54
+
55
+ )
56
+
57
+ with demo:
58
+ gr.TabbedInterface([microphone_interface,file_interface, url_interface], ["Transcribe Audio", "Transcribe File" , "Transcribe YouTube"])
59
+
60
+ demo.launch(share=True)