divython's picture
Update app.py
5b69f95 verified
raw
history blame
998 Bytes
import gradio as gr
import yt_dlp
import whisper
import tempfile
import os
import yt_dlp
def download_audio(url, cookies_path=None):
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': 'audio.%(ext)s',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav',
'preferredquality': '192',
}],
'cookiefile': cookies_path if cookies_path else 'cookies.txt'
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
def process_video(url, cookies_path):
audio_file = download_audio(url, cookies_path)
model = whisper.load_model("base")
result = model.transcribe(audio_file)
return result['text']
def main(url):
cookies_path = 'cookies.txt' # Provide path to your exported cookies file
transcript = process_video(url, cookies_path)
return transcript
demo = gr.Interface(fn=main, inputs=gr.Textbox(label="YouTube URL"), outputs="text")
demo.launch()