File size: 1,646 Bytes
cdb10f1
 
 
b83d913
cdb10f1
b83d913
 
 
 
 
 
 
 
cdb10f1
 
b83d913
cdb10f1
 
 
 
b83d913
cdb10f1
b83d913
cdb10f1
 
 
 
b83d913
cdb10f1
b83d913
cdb10f1
 
b83d913
 
cdb10f1
 
 
b83d913
cdb10f1
 
b83d913
 
 
 
 
 
 
cdb10f1
 
 
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
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi
from deep_translator import GoogleTranslator
import re

# βœ… Extract video ID from YouTube URL
def extract_video_id(url):
    # Supports standard, short, and embed URLs
    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
def summarize_youtube(video_url):
    try:
        video_id = extract_video_id(video_url)
        transcript = YouTubeTranscriptApi.get_transcript(video_id)
        text = " ".join([entry["text"] for entry in transcript[:15]])
        return text[:500]
    except Exception as e:
        return f"❌ Error in Summarizer: {str(e)}"

# βœ… Agent 2: Translator
def translate_to_spanish(english_text):
    try:
        return GoogleTranslator(source='auto', target='es').translate(english_text)
    except Exception as e:
        return f"❌ Error in Translator: {str(e)}"

# βœ… Workflow Function (Master Agent)
def agent_workflow(video_url):
    summary = summarize_youtube(video_url)
    if summary.startswith("❌"):
        return summary, ""
    translated = translate_to_spanish(summary)
    return summary, translated

# βœ… Gradio UI
demo = gr.Interface(
    fn=agent_workflow,
    inputs=gr.Textbox(label="πŸŽ₯ Enter YouTube Video Link"),
    outputs=[
        gr.Textbox(label="🧠 English Summary"),
        gr.Textbox(label="🌍 Spanish Translation")
    ],
    title="Lead with AI Agents Hackathon Project",
    description="🧠 Agent 1: Summarizes YouTube Video · 🌍 Agent 2: Translates Summary to Spanish"
)

demo.launch()