Spaces:
Sleeping
Sleeping
File size: 2,286 Bytes
cdb10f1 b83d913 cdb10f1 e542c27 b83d913 e542c27 b83d913 e542c27 cdb10f1 b83d913 1374600 18bb69f 1374600 32bef68 1374600 32bef68 cdb10f1 32bef68 e542c27 e911cb9 32bef68 e542c27 32bef68 18bb69f e542c27 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import gradio as gr
from deep_translator import GoogleTranslator
import re
# β
Extract video ID from YouTube 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: Summarizer (Simulated)
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)}", "", ""
# β
Master Agent Workflow with Embedded YouTube Preview
def run_agents(url):
summary, translation, embed = summarize_youtube(url)
if embed:
video_html = f'''
<div style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;">
<iframe src="{embed}" style="position:absolute;top:0;left:0;width:100%;height:100%;"
frameborder="0" allowfullscreen></iframe>
</div>
'''
else:
video_html = ""
return summary, translation, video_html
# β
Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## π₯ AI Agents: YouTube Summary + Spanish Translator")
gr.Markdown("π Enter a YouTube video URL to simulate AI agent collaboration.")
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()
run_btn = gr.Button("π Run Agents")
run_btn.click(fn=run_agents, inputs=input_url, outputs=[summary_output, translation_output, video_output])
demo.launch() |