Whisper-Youtube / app.py
mirari's picture
Update app.py
46612c0
raw
history blame
2.09 kB
import gradio as gr
import whisper
from pytube import YouTube
loaded_model = whisper.load_model("medium")
current_size = 'medium'
def inference(link):
yt = YouTube(link)
path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
options = whisper.DecodingOptions(language= 'Spanish', without_timestamps=True)
results = loaded_model.transcribe(path)
return results['text']
def change_model(size):
if size == current_size:
return
loaded_model = whisper.load_model(size)
current_size = size
def populate_metadata(link):
yt = YouTube(link)
return yt.thumbnail_url, yt.title
title=""
description=""
block = gr.Blocks()
with block:
gr.HTML(
"""
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
<div>
</div>
</div>
"""
)
with gr.Group():
with gr.Box():
sz = gr.Dropdown(label="Model Size", choices=['tiny', 'base','small', 'medium', 'large'], value='medium')
link = gr.Textbox(label="YouTube Link")
with gr.Row():
gr.Textbox(label = "Ejemplo: ", placeholder = "https://www.youtube.com/watch?v=pe79zhH_fVY&t=1s")
with gr.Row().style(mobile_collapse=False, equal_height=True):
title = gr.Label(label="Video Title", placeholder="Title")
img = gr.Image(label="Thumbnail")
text = gr.Textbox(
label="Transcription",
placeholder="Transcription Output",
lines=5)
with gr.Row().style(mobile_collapse=False, equal_height=True):
btn = gr.Button("Transcribe")
# Events
btn.click(inference, inputs=[link], outputs=[text])
link.change(populate_metadata, inputs=[link], outputs=[img, title])
sz.change(change_model, inputs=[sz], outputs=[])
block.launch(debug=True)
demo = gr.Interface(css="footer {visibility: hidden}", examples='https://www.youtube.com/watch?v=pe79zhH_fVY&t=1s')