chinhon commited on
Commit
8832bce
1 Parent(s): 1c85f51
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pytube import YouTube
3
+ import whisper
4
+
5
+ # define function for transcription
6
+ def whisper_transcript(model_size, url, audio_file):
7
+ if url:
8
+ link = YouTube(url)
9
+ source = link.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
10
+
11
+ else:
12
+ source = audio_file
13
+
14
+ if model_size.endswith(".en"):
15
+ language = "english"
16
+
17
+ else:
18
+ language = None
19
+
20
+ options = whisper.DecodingOptions(without_timestamps=True)
21
+
22
+ loaded_model = whisper.load_model(model_size)
23
+ transcript = loaded_model.transcribe(source, language=language)
24
+
25
+ return transcript["text"]
26
+
27
+ # define Gradio app interface
28
+ gradio_ui = gr.Interface(
29
+ fn=whisper_transcript,
30
+ title="Transcribe multi-lingual audio clips with Whisper",
31
+ description="**How to use**: Select a model, paste in a Youtube link or upload an audio clip, then click submit. Select models ending in '.en' if your clip is in English. For clips in other languages, select models without '.en'",
32
+ article="**Note**: The larger the model size selected or the longer the audio clip, the more time it would take to process the transcript.",
33
+ inputs=[
34
+ gr.Dropdown(
35
+ label="Select Model",
36
+ choices=[
37
+ "tiny.en",
38
+ "base.en",
39
+ "small.en",
40
+ "medium.en",
41
+ "tiny",
42
+ "base",
43
+ "small",
44
+ "medium",
45
+ "large",
46
+ ],
47
+ value="base",
48
+ ),
49
+ gr.Textbox(label="Paste YouTube link here"),
50
+ gr.Audio(label="Upload Audio File", source="upload", type="filepath"),
51
+ ],
52
+ outputs=gr.outputs.Textbox(label="Whisper Transcript"),
53
+ )
54
+
55
+ gradio_ui.queue().launch()