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()