File size: 2,958 Bytes
cdb10f1
 
b83d913
cdb10f1
0af641e
b83d913
0af641e
b83d913
 
0af641e
cdb10f1
 
b83d913
1374600
 
e7a056d
 
 
 
 
 
 
 
1374600
 
0af641e
1374600
32bef68
 
 
0af641e
 
 
cdb10f1
0af641e
 
 
 
 
 
32bef68
0af641e
 
 
 
 
 
 
e911cb9
0af641e
 
e911cb9
 
 
 
 
 
 
 
 
 
0af641e
 
 
32bef68
0af641e
 
32bef68
0af641e
32bef68
 
 
0af641e
32bef68
0af641e
 
 
18bb69f
0af641e
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import gradio as gr
from deep_translator import GoogleTranslator
import re

# βœ… Extract video ID from any YouTube URL format
def extract_video_id(url):
    match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11})", url)
    return match.group(1) if match else url.strip()

# βœ… Agent 1: Simulated YouTube Summary
def summarize_youtube(video_url):
    try:
        video_id = extract_video_id(video_url)

        saved_transcripts = {
    "dQw4w9WgXcQ": "This video explains advanced AI concepts using example 1.",
    "F9cTlfD7ZGM": "This video explains advanced AI concepts using example 2.",
    "HMcFwjWVprs": "This video explains advanced AI concepts using example 3.",
    "xvFZjo5PgG0": "This video explains advanced AI concepts using example 4.",
    "tVZxRHrhgW8": "This video explains advanced AI concepts using example 5.",
    ...
    # Total 100 entries!
}

        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}"
        steps = simulate_video_steps(summary)

        return summary, translation, video_embed_link, steps
    except Exception as e:
        return f"❌ Error: {str(e)}", "", "", ""

# βœ… Agent 2: Simulated Key Moments / Scene Steps
def simulate_video_steps(summary):
    if not summary or summary.startswith("❌"):
        return "No steps available."

    return "\n".join([
        "πŸ“Œ Step 1: Introduction of topic",
        "πŸ” Step 2: Main discussion about agents",
        "βœ… Step 3: Final conclusion & translation"
    ])

# βœ… Master Agent Workflow
def run_agents(url):
    summary, translation, embed, steps_text = 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, steps_text

# βœ… Gradio App
with gr.Blocks() as demo:
    gr.Markdown("## πŸ€– Lead With AI Agents: YouTube Video Analyzer")
    gr.Markdown("Paste any **YouTube video link** to get AI-powered insights.")

    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()
    steps_output = gr.Textbox(label="🎬 AI Scene Steps / Key Moments")

    run_btn = gr.Button("▢️ Run Agents")
    run_btn.click(fn=run_agents, inputs=input_url,
                  outputs=[summary_output, translation_output, video_output, steps_output])

demo.launch()