Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import Whisper, AutoProcessor | |
import youtube_dl | |
# Carrega o modelo Whisper | |
model = Whisper("facebook/whisper-large") | |
# Carrega o processador adequado para o modelo | |
processor = AutoProcessor.from_pretrained("facebook/whisper-large") | |
# Função para transcrever áudio a partir de uma URL do YouTube | |
def transcribe_from_youtube_url(url): | |
ydl_opts = { | |
'format': 'bestaudio/best', | |
'outtmpl': '%(id)s.%(ext)s', | |
'postprocessors': [{ | |
'key': 'FFmpegExtractAudio', | |
'preferredcodec':'mp3', | |
'preferredquality': '192', | |
}], | |
} | |
with youtube_dl.YoutubeDL(ydl_opts) as ydl: | |
info = ydl.extract_info(url, download=True) | |
audio_filename = ydl.prepare_filename(info) | |
ydl.process_item(info, None) | |
return transcribe_audio(audio_filename) | |
def transcribe_audio(audio_file): | |
result = model.transcribe(audio_file) | |
return processor.batch_transcribe(model, audio_file) | |
# Cria interface com Gradio | |
def launch_interface(): | |
url_input = gr.inputs.Textbox(label="Insira a URL do YouTube") | |
output = gr.outputs.Textbox(label="Transcrição") | |
iface = gr.Interface(fn=transcribe_from_youtube_url, inputs=url_input, outputs=output, title="Transcrição de Áudio com Whisper a partir de URL do YouTube") | |
iface.launch(show_alert=True) | |
launch_interface() |