Create app.py
Browse filestesting to transcribe youtube
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import whisper
|
3 |
+
from pytube import YouTube
|
4 |
+
|
5 |
+
loaded_model = whisper.load_model("ksoky/whisper-small-km")
|
6 |
+
current_size = 'small'
|
7 |
+
def inference(link):
|
8 |
+
yt = YouTube(link)
|
9 |
+
path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
|
10 |
+
options = whisper.DecodingOptions(without_timestamps=True)
|
11 |
+
results = loaded_model.transcribe(path)
|
12 |
+
return results['text']
|
13 |
+
|
14 |
+
def change_model(size):
|
15 |
+
if size == current_size:
|
16 |
+
return
|
17 |
+
loaded_model = whisper.load_model(size)
|
18 |
+
current_size = size
|
19 |
+
|
20 |
+
def populate_metadata(link):
|
21 |
+
yt = YouTube(link)
|
22 |
+
return yt.thumbnail_url, yt.title
|
23 |
+
|
24 |
+
title="Youtube Whisperer"
|
25 |
+
description="Speech to text transcription of Youtube videos using fine-tuned OpenAI's Whisper on Khmer"
|
26 |
+
block = gr.Blocks()
|
27 |
+
|
28 |
+
with block:
|
29 |
+
gr.HTML(
|
30 |
+
"""
|
31 |
+
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
32 |
+
<div>
|
33 |
+
<h1>Youtube Whisperer</h1>
|
34 |
+
</div>
|
35 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
36 |
+
Speech to text transcription of Youtube videos using OpenAI's Whisper
|
37 |
+
</p>
|
38 |
+
</div>
|
39 |
+
"""
|
40 |
+
)
|
41 |
+
with gr.Group():
|
42 |
+
with gr.Box():
|
43 |
+
# sz = gr.Dropdown(label="Model Size", choices=['base','small', 'medium', 'large'], value='base')
|
44 |
+
sz = gr.Dropdown(label="Model Size", choices=['small'], value='small')
|
45 |
+
link = gr.Textbox(label="YouTube Link")
|
46 |
+
|
47 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
48 |
+
title = gr.Label(label="Video Title", placeholder="Title")
|
49 |
+
img = gr.Image(label="Thumbnail")
|
50 |
+
text = gr.Textbox(
|
51 |
+
label="Transcription",
|
52 |
+
placeholder="Transcription Output",
|
53 |
+
lines=5)
|
54 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
55 |
+
btn = gr.Button("Transcribe")
|
56 |
+
|
57 |
+
# Events
|
58 |
+
btn.click(inference, inputs=[link], outputs=[text])
|
59 |
+
link.change(populate_metadata, inputs=[link], outputs=[img, title])
|
60 |
+
sz.change(change_model, inputs=[sz], outputs=[])
|
61 |
+
|
62 |
+
block.launch(debug=True)
|