import gradio as gr from deep_translator import GoogleTranslator import re # ✅ Extract video ID from URL def extract_video_id(url): regex = r"(?:v=|\/)([0-9A-Za-z_-]{11})" match = re.search(regex, url) return match.group(1) if match else url.strip() # ✅ Agent 1: Simulated Summarizer def summarize_youtube(video_url): try: video_id = extract_video_id(video_url) saved_transcripts = { "dQw4w9WgXcQ": "We're no strangers to love. You know the rules and so do I...", "F9cTlfD7ZGM": "This is a video about AI agents and how they collaborate.", "HMcFwjWVprs": "This presentation explains the GenAI protocol and its future." } if video_id not in saved_transcripts: return "❌ Transcript not available for this video.", "", "" summary = saved_transcripts[video_id] translation = GoogleTranslator(source='auto', target='es').translate(summary) video_embed_link = f"https://www.youtube.com/embed/{video_id}" return summary, translation, video_embed_link except Exception as e: return f"❌ Error: {str(e)}", "", "" # ✅ Gradio App with gr.Blocks() as demo: gr.Markdown("## 🎥 AI Agents: YouTube Summary + Spanish Translator") gr.Markdown("Enter a YouTube video URL to simulate agent behavior.") input_url = gr.Textbox(label="Paste YouTube Link") summary_output = gr.Textbox(label="🧠 English Summary") translation_output = gr.Textbox(label="🌍 Spanish Translation") video_output = gr.HTML() def run_agents(url): summary, translation, embed = summarize_youtube(url) if embed: video_html = f'' else: video_html = "" return summary, translation, video_html run_btn = gr.Button("🔍 Run Agents") run_btn.click(fn=run_agents, inputs=input_url, outputs=[summary_output, translation_output, video_output]) demo.launch()