File size: 968 Bytes
22b53d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3818196
22b53d1
 
 
 
 
3818196
 
22b53d1
 
 
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
import gradio as gr
import whisper
import yt_dlp
from moviepy.editor import VideoFileClip
import os
import uuid

model = whisper.load_model("base")

def download_video(url):
    ydl_opts = {
        'format': 'best',
        'outtmpl': 'downloaded_video.%(ext)s',
    }
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        info = ydl.extract_info(url, download=True)
        return ydl.prepare_filename(info)

def process_video(url):
    video_path = download_video(url)
    result = model.transcribe(video_path)
    transcript = result['text']

    clip = VideoFileClip(video_path).subclip(0, 30)
    output_path = f"clip_{uuid.uuid4().hex}.mp4"
    clip.write_videofile(output_path, codec="libx264", audio_codec="aac")

    return output_path, transcript

demo = gr.Interface(fn=process_video,
                    inputs=gr.Textbox(label="YouTube URL"),
                    outputs=[gr.Video(label="Clip generado"), gr.Textbox(label="Transcripción")])

demo.launch()