Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
-
from youtube_transcript_api import YouTubeTranscriptApi
|
3 |
from deep_translator import GoogleTranslator
|
4 |
import re
|
5 |
|
6 |
-
#
|
7 |
def extract_video_id(url):
|
8 |
-
# Supports standard, short, and embed URLs
|
9 |
regex = r"(?:v=|\/)([0-9A-Za-z_-]{11})"
|
10 |
match = re.search(regex, url)
|
11 |
return match.group(1) if match else url.strip()
|
12 |
|
13 |
-
#
|
14 |
def summarize_youtube(video_url):
|
15 |
try:
|
16 |
video_id = extract_video_id(video_url)
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
except Exception as e:
|
21 |
-
return f"β Error
|
22 |
|
23 |
-
#
|
24 |
def translate_to_spanish(english_text):
|
25 |
try:
|
26 |
return GoogleTranslator(source='auto', target='es').translate(english_text)
|
27 |
except Exception as e:
|
28 |
-
return f"β Error
|
29 |
|
30 |
-
#
|
31 |
def agent_workflow(video_url):
|
32 |
summary = summarize_youtube(video_url)
|
33 |
if summary.startswith("β"):
|
@@ -35,7 +42,7 @@ def agent_workflow(video_url):
|
|
35 |
translated = translate_to_spanish(summary)
|
36 |
return summary, translated
|
37 |
|
38 |
-
#
|
39 |
demo = gr.Interface(
|
40 |
fn=agent_workflow,
|
41 |
inputs=gr.Textbox(label="π₯ Enter YouTube Video Link"),
|
@@ -43,8 +50,5 @@ demo = gr.Interface(
|
|
43 |
gr.Textbox(label="π§ English Summary"),
|
44 |
gr.Textbox(label="π Spanish Translation")
|
45 |
],
|
46 |
-
title="
|
47 |
-
description="
|
48 |
-
)
|
49 |
-
|
50 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from deep_translator import GoogleTranslator
|
3 |
import re
|
4 |
|
5 |
+
# Extract video ID from URL
|
6 |
def extract_video_id(url):
|
|
|
7 |
regex = r"(?:v=|\/)([0-9A-Za-z_-]{11})"
|
8 |
match = re.search(regex, url)
|
9 |
return match.group(1) if match else url.strip()
|
10 |
|
11 |
+
# Simulated transcript agent
|
12 |
def summarize_youtube(video_url):
|
13 |
try:
|
14 |
video_id = extract_video_id(video_url)
|
15 |
+
|
16 |
+
# Predefined summaries for demonstration
|
17 |
+
saved_transcripts = {
|
18 |
+
"dQw4w9WgXcQ": "We're no strangers to love. You know the rules and so do I...",
|
19 |
+
"F9cTlfD7ZGM": "This is a video about AI agents and their collaboration.",
|
20 |
+
"HMcFwjWVprs": "In this talk, we cover the future of GenAI protocols and their applications."
|
21 |
+
}
|
22 |
+
|
23 |
+
if video_id not in saved_transcripts:
|
24 |
+
return "β Transcript not available for this video. Please use a supported demo video."
|
25 |
+
|
26 |
+
return saved_transcripts[video_id]
|
27 |
except Exception as e:
|
28 |
+
return f"β Error: {str(e)}"
|
29 |
|
30 |
+
# Translator agent
|
31 |
def translate_to_spanish(english_text):
|
32 |
try:
|
33 |
return GoogleTranslator(source='auto', target='es').translate(english_text)
|
34 |
except Exception as e:
|
35 |
+
return f"β Error: {str(e)}"
|
36 |
|
37 |
+
# Workflow (master agent)
|
38 |
def agent_workflow(video_url):
|
39 |
summary = summarize_youtube(video_url)
|
40 |
if summary.startswith("β"):
|
|
|
42 |
translated = translate_to_spanish(summary)
|
43 |
return summary, translated
|
44 |
|
45 |
+
# Gradio UI
|
46 |
demo = gr.Interface(
|
47 |
fn=agent_workflow,
|
48 |
inputs=gr.Textbox(label="π₯ Enter YouTube Video Link"),
|
|
|
50 |
gr.Textbox(label="π§ English Summary"),
|
51 |
gr.Textbox(label="π Spanish Translation")
|
52 |
],
|
53 |
+
title="π§ AI Agents: YouTube Summary + Spanish Translation",
|
54 |
+
description="Agent 1: Summarizer (simulated)
|
|
|
|
|
|