Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,12 @@ import gradio as gr
|
|
2 |
from deep_translator import GoogleTranslator
|
3 |
import re
|
4 |
|
5 |
-
# β
Extract video ID from YouTube URL
|
6 |
def extract_video_id(url):
|
7 |
-
|
8 |
-
match = re.search(regex, url)
|
9 |
return match.group(1) if match else url.strip()
|
10 |
|
11 |
-
# β
Agent 1:
|
12 |
def summarize_youtube(video_url):
|
13 |
try:
|
14 |
video_id = extract_video_id(video_url)
|
@@ -20,18 +19,32 @@ def summarize_youtube(video_url):
|
|
20 |
}
|
21 |
|
22 |
if video_id not in saved_transcripts:
|
23 |
-
return "β Transcript not available for this video.", "", ""
|
24 |
|
25 |
summary = saved_transcripts[video_id]
|
26 |
translation = GoogleTranslator(source='auto', target='es').translate(summary)
|
27 |
video_embed_link = f"https://www.youtube.com/embed/{video_id}"
|
28 |
-
|
|
|
|
|
29 |
except Exception as e:
|
30 |
-
return f"β Error: {str(e)}", "", ""
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def run_agents(url):
|
34 |
-
summary, translation, embed = summarize_youtube(url)
|
|
|
35 |
if embed:
|
36 |
video_html = f'''
|
37 |
<div style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;">
|
@@ -41,19 +54,22 @@ def run_agents(url):
|
|
41 |
'''
|
42 |
else:
|
43 |
video_html = ""
|
44 |
-
return summary, translation, video_html
|
45 |
|
46 |
-
|
|
|
|
|
47 |
with gr.Blocks() as demo:
|
48 |
-
gr.Markdown("##
|
49 |
-
gr.Markdown("
|
50 |
|
51 |
-
input_url = gr.Textbox(label="Paste YouTube Link")
|
52 |
summary_output = gr.Textbox(label="π§ English Summary")
|
53 |
translation_output = gr.Textbox(label="π Spanish Translation")
|
54 |
video_output = gr.HTML()
|
|
|
55 |
|
56 |
-
run_btn = gr.Button("
|
57 |
-
run_btn.click(fn=run_agents, inputs=input_url,
|
|
|
58 |
|
59 |
-
demo.launch()
|
|
|
2 |
from deep_translator import GoogleTranslator
|
3 |
import re
|
4 |
|
5 |
+
# β
Extract video ID from any YouTube URL format
|
6 |
def extract_video_id(url):
|
7 |
+
match = re.search(r"(?:v=|\/)([0-9A-Za-z_-]{11})", url)
|
|
|
8 |
return match.group(1) if match else url.strip()
|
9 |
|
10 |
+
# β
Agent 1: Simulated YouTube Summary
|
11 |
def summarize_youtube(video_url):
|
12 |
try:
|
13 |
video_id = extract_video_id(video_url)
|
|
|
19 |
}
|
20 |
|
21 |
if video_id not in saved_transcripts:
|
22 |
+
return "β Transcript not available for this video.", "", "", ""
|
23 |
|
24 |
summary = saved_transcripts[video_id]
|
25 |
translation = GoogleTranslator(source='auto', target='es').translate(summary)
|
26 |
video_embed_link = f"https://www.youtube.com/embed/{video_id}"
|
27 |
+
steps = simulate_video_steps(summary)
|
28 |
+
|
29 |
+
return summary, translation, video_embed_link, steps
|
30 |
except Exception as e:
|
31 |
+
return f"β Error: {str(e)}", "", "", ""
|
32 |
+
|
33 |
+
# β
Agent 2: Simulated Key Moments / Scene Steps
|
34 |
+
def simulate_video_steps(summary):
|
35 |
+
if not summary or summary.startswith("β"):
|
36 |
+
return "No steps available."
|
37 |
|
38 |
+
return "\n".join([
|
39 |
+
"π Step 1: Introduction of topic",
|
40 |
+
"π Step 2: Main discussion about agents",
|
41 |
+
"β
Step 3: Final conclusion & translation"
|
42 |
+
])
|
43 |
+
|
44 |
+
# β
Master Agent Workflow
|
45 |
def run_agents(url):
|
46 |
+
summary, translation, embed, steps_text = summarize_youtube(url)
|
47 |
+
|
48 |
if embed:
|
49 |
video_html = f'''
|
50 |
<div style="position:relative;padding-bottom:56.25%;height:0;overflow:hidden;">
|
|
|
54 |
'''
|
55 |
else:
|
56 |
video_html = ""
|
|
|
57 |
|
58 |
+
return summary, translation, video_html, steps_text
|
59 |
+
|
60 |
+
# β
Gradio App
|
61 |
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown("## π€ Lead With AI Agents: YouTube Video Analyzer")
|
63 |
+
gr.Markdown("Paste any **YouTube video link** to get AI-powered insights.")
|
64 |
|
65 |
+
input_url = gr.Textbox(label="π Paste YouTube Link")
|
66 |
summary_output = gr.Textbox(label="π§ English Summary")
|
67 |
translation_output = gr.Textbox(label="π Spanish Translation")
|
68 |
video_output = gr.HTML()
|
69 |
+
steps_output = gr.Textbox(label="π¬ AI Scene Steps / Key Moments")
|
70 |
|
71 |
+
run_btn = gr.Button("βΆοΈ Run Agents")
|
72 |
+
run_btn.click(fn=run_agents, inputs=input_url,
|
73 |
+
outputs=[summary_output, translation_output, video_output, steps_output])
|
74 |
|
75 |
+
demo.launch()
|