MarcoM003 commited on
Commit
0959a74
1 Parent(s): e68fa73

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ theme="Nymbo/Nymbo_Theme",
31
+ title="Transcribe multi-lingual audio clips with Whisper",
32
+ description="**How to use**: Select a model, paste in a Youtube link or upload an audio clip, then click submit. If your clip is **100% in English, select models ending in ‘.en’**. If the clip is in other languages, or a mix of languages, select models without ‘.en’",
33
+ article="**Note**: The larger the model size selected or the longer the audio clip, the more time it would take to process the transcript.",
34
+ inputs=[
35
+ gr.Dropdown(
36
+ label="Select Model",
37
+ choices=[
38
+ "tiny.en",
39
+ "base.en",
40
+ "small.en",
41
+ "medium.en",
42
+ "tiny",
43
+ "base",
44
+ "small",
45
+ "medium",
46
+ "large",
47
+ ],
48
+ value="base",
49
+ ),
50
+ gr.Textbox(label="Paste YouTube link here"),
51
+ gr.Audio(label="Upload Audio File", sources=["upload", "microphone"], type="filepath"),
52
+ ],
53
+ outputs=gr.Textbox(label="Whisper Transcript"),
54
+ )
55
+
56
+ gradio_ui.queue().launch()