Spaces:
Sleeping
Sleeping
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() | |