Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,17 @@ import gradio as gr
|
|
2 |
from deep_translator import GoogleTranslator
|
3 |
import re
|
4 |
|
5 |
-
# β
Extract video ID from
|
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 |
-
# β
Agent 1: Summarizer
|
12 |
def summarize_youtube(video_url):
|
13 |
try:
|
14 |
video_id = extract_video_id(video_url)
|
15 |
|
16 |
-
# Simulated transcript summaries for demo
|
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 how they collaborate.",
|
@@ -21,37 +20,34 @@ def summarize_youtube(video_url):
|
|
21 |
}
|
22 |
|
23 |
if video_id not in saved_transcripts:
|
24 |
-
return "β Transcript not available for this video.
|
25 |
|
26 |
-
|
|
|
|
|
|
|
27 |
except Exception as e:
|
28 |
-
return f"β Error
|
29 |
-
|
30 |
-
# β
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
outputs=[
|
50 |
-
gr.Textbox(label="π§ English Summary"),
|
51 |
-
gr.Textbox(label="π Spanish Translation")
|
52 |
-
],
|
53 |
-
title="π§ AI Agents Hackathon β Hugging Face App",
|
54 |
-
description="Agent 1: Summarizer (simulated) β’ Agent 2: Translator (real)"
|
55 |
-
)
|
56 |
|
57 |
demo.launch()
|
|
|
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 |
+
# β
Agent 1: Simulated Summarizer
|
12 |
def summarize_youtube(video_url):
|
13 |
try:
|
14 |
video_id = extract_video_id(video_url)
|
15 |
|
|
|
16 |
saved_transcripts = {
|
17 |
"dQw4w9WgXcQ": "We're no strangers to love. You know the rules and so do I...",
|
18 |
"F9cTlfD7ZGM": "This is a video about AI agents and how they collaborate.",
|
|
|
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 |
+
return summary, translation, video_embed_link
|
29 |
except Exception as e:
|
30 |
+
return f"β Error: {str(e)}", "", ""
|
31 |
+
|
32 |
+
# β
Gradio App
|
33 |
+
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("## π₯ AI Agents: YouTube Summary + Spanish Translator")
|
35 |
+
gr.Markdown("Enter a YouTube video URL to simulate agent behavior.")
|
36 |
+
|
37 |
+
input_url = gr.Textbox(label="Paste YouTube Link")
|
38 |
+
summary_output = gr.Textbox(label="π§ English Summary")
|
39 |
+
translation_output = gr.Textbox(label="π Spanish Translation")
|
40 |
+
video_output = gr.HTML()
|
41 |
+
|
42 |
+
def run_agents(url):
|
43 |
+
summary, translation, embed = summarize_youtube(url)
|
44 |
+
if embed:
|
45 |
+
video_html = f'<iframe width="100%" height="315" src="{embed}" frameborder="0" allowfullscreen></iframe>'
|
46 |
+
else:
|
47 |
+
video_html = ""
|
48 |
+
return summary, translation, video_html
|
49 |
+
|
50 |
+
run_btn = gr.Button("π Run Agents")
|
51 |
+
run_btn.click(fn=run_agents, inputs=input_url, outputs=[summary_output, translation_output, video_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
demo.launch()
|