Spaces:
Sleeping
Sleeping
File size: 1,108 Bytes
4d4b8ad 03410b4 5e74ff4 4d4b8ad 5e74ff4 9b856f1 5e74ff4 03410b4 5e74ff4 9b856f1 5e74ff4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
import yt_dlp
import whisper
import tempfile
def download_audio(url, cookies_path):
with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as tmpfile:
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': tmpfile.name,
'quiet': True,
'cookiefile': cookies_path,
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
return tmpfile.name
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()
|