Spaces:
Runtime error
Runtime error
ver1.0
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pytube import YouTube
|
3 |
+
import whisper
|
4 |
+
|
5 |
+
#define transcription function
|
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 |
+
options = whisper.DecodingOptions(without_timestamps=True)
|
15 |
+
|
16 |
+
loaded_model = whisper.load_model(model_size)
|
17 |
+
transcript = loaded_model.transcribe(source)
|
18 |
+
|
19 |
+
return transcript["text"]
|
20 |
+
|
21 |
+
#DEFINE GRADIO INTERFACE
|
22 |
+
gradio_ui = gr.Interface(
|
23 |
+
fn=whisper_transcript,
|
24 |
+
title="Transcribe multi-lingual audio clips with Whisper",
|
25 |
+
description= "**How to use**: Select a model, paste in a Youtube link or upload an audio clip, then click submit.",
|
26 |
+
article="**Note**: The larger the model size selected or the longer the audio clip, the more time it would take to process the transcript.",
|
27 |
+
inputs=[
|
28 |
+
gr.Dropdown(
|
29 |
+
label="Select Model",
|
30 |
+
choices=["base", "small", "medium", "large"],
|
31 |
+
value="base",
|
32 |
+
),
|
33 |
+
gr.Textbox(label="Paste YouTube link here"),
|
34 |
+
gr.Audio(label="Upload Audio File", source="upload", type="filepath"),
|
35 |
+
],
|
36 |
+
outputs=gr.outputs.Textbox(label="Whisper Transcript"),
|
37 |
+
)
|
38 |
+
|
39 |
+
gradio_ui.queue().launch()
|