File size: 998 Bytes
4d4b8ad
03410b4
5e74ff4
 
4d4b8ad
4b7eb7e
 
 
5b69f95
4b7eb7e
 
 
 
 
 
 
 
5b69f95
4b7eb7e
 
 
9b856f1
c042fca
d580fae
5b69f95
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
38
39
40
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()