Spaces:
Sleeping
Sleeping
import gradio as gr | |
from utils import VideoProcessor | |
import time | |
def build_ui(): | |
with gr.Blocks(css="style.css", title="YouTube Summarizer Pro") as demo: | |
gr.Markdown("""# π₯ YouTube Video Summarizer Pro | |
Paste any YouTube link to get an AI-generated summary, key points, and transcript preview.""") | |
with gr.Row(): | |
with gr.Column(): | |
youtube_url = gr.Textbox(label="YouTube URL", | |
placeholder="https://www.youtube.com/watch?v=...", | |
max_lines=1) | |
with gr.Row(): | |
submit_btn = gr.Button("Generate Summary", variant="primary") | |
clear_btn = gr.Button("Clear") | |
advanced = gr.Accordion("Advanced Options", open=False) | |
with advanced: | |
chunk_size = gr.Slider(800, 2000, value=1000, | |
label="Processing Chunk Size (characters)") | |
model_choice = gr.Radio(["base", "small", "medium"], | |
value="base", | |
label="Whisper Model Size") | |
use_cookies = gr.Checkbox(False, label="Use YouTube Cookies (for restricted videos)") | |
with gr.Row(): | |
with gr.Column(): | |
summary_output = gr.Textbox(label="β Summary", lines=8) | |
key_points_output = gr.Textbox(label="β¨ Key Points", lines=8) | |
transcript_output = gr.Textbox(label="π Transcript Preview", lines=16) | |
status = gr.Label("Ready", label="Status") | |
processor = VideoProcessor() | |
def process_video(url, chunk_size, model_size, use_cookies): | |
try: | |
yield "Downloading audio...", "", "", "", "" | |
start_time = time.time() | |
result = processor.process( | |
url, | |
chunk_size=int(chunk_size), | |
model_size=model_size, | |
use_cookies=use_cookies | |
) | |
if 'error' in result: | |
raise Exception(result['error']) | |
yield (f"Done in {time.time()-start_time:.1f}s", | |
result['summary'], | |
result['key_points'], | |
result['transcript'], | |
"") | |
except Exception as e: | |
error_msg = f"β Error: {str(e)}" | |
yield "Failed", "", "", "", error_msg | |
submit_btn.click( | |
fn=process_video, | |
inputs=[youtube_url, chunk_size, model_choice, use_cookies], | |
outputs=[status, summary_output, key_points_output, transcript_output, status] | |
) | |
clear_btn.click( | |
fn=lambda: ["", "", "", "", "Ready"], | |
outputs=[youtube_url, summary_output, key_points_output, transcript_output, status] | |
) | |
return demo | |
if __name__ == "__main__": | |
demo = build_ui() | |
demo.launch() |