Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
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):
|
|
@@ -13,12 +75,6 @@ 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.",
|
| 19 |
-
"HMcFwjWVprs": "This presentation explains the GenAI protocol and its future."
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
if video_id not in saved_transcripts:
|
| 23 |
return "β Transcript not available for this video.", "", ""
|
| 24 |
|
|
|
|
| 1 |
+
# 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 |
+
# 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 (Simulated)
|
| 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.",
|
| 19 |
+
# "HMcFwjWVprs": "This presentation explains the GenAI protocol and its future."
|
| 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 |
+
# # β
Master Agent Workflow with Embedded YouTube Preview
|
| 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;">
|
| 38 |
+
# <iframe src="{embed}" style="position:absolute;top:0;left:0;width:100%;height:100%;"
|
| 39 |
+
# frameborder="0" allowfullscreen></iframe>
|
| 40 |
+
# </div>
|
| 41 |
+
# '''
|
| 42 |
+
# else:
|
| 43 |
+
# video_html = ""
|
| 44 |
+
# return summary, translation, video_html
|
| 45 |
+
|
| 46 |
+
# # β
Gradio UI
|
| 47 |
+
# with gr.Blocks() as demo:
|
| 48 |
+
# gr.Markdown("## π₯ AI Agents: YouTube Summary + Spanish Translator")
|
| 49 |
+
# gr.Markdown("π Enter a YouTube video URL to simulate AI agent collaboration.")
|
| 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("π Run Agents")
|
| 57 |
+
# run_btn.click(fn=run_agents, inputs=input_url, outputs=[summary_output, translation_output, video_output])
|
| 58 |
+
|
| 59 |
+
# demo.launch()
|
| 60 |
+
|
| 61 |
+
|
| 62 |
import gradio as gr
|
| 63 |
from deep_translator import GoogleTranslator
|
| 64 |
import re
|
| 65 |
+
from saved_transcripts import saved_transcripts # β
Import 100 video transcripts
|
| 66 |
|
| 67 |
# β
Extract video ID from YouTube URL
|
| 68 |
def extract_video_id(url):
|
|
|
|
| 75 |
try:
|
| 76 |
video_id = extract_video_id(video_url)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if video_id not in saved_transcripts:
|
| 79 |
return "β Transcript not available for this video.", "", ""
|
| 80 |
|