Spaces:
Sleeping
Sleeping
File size: 4,446 Bytes
b0387ad cdb10f1 b83d913 b0387ad cdb10f1 3871e34 b83d913 c1701a5 b83d913 3871e34 cdb10f1 b83d913 1374600 c1701a5 1374600 32bef68 c1701a5 cdb10f1 c1701a5 0af641e 3871e34 32bef68 c1701a5 3871e34 32bef68 c1701a5 32bef68 c1701a5 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# import gradio as gr
# from deep_translator import GoogleTranslator
# import re
# # β
Extract video ID from YouTube URL
# def extract_video_id(url):
# regex = r"(?:v=|\/)([0-9A-Za-z_-]{11})"
# match = re.search(regex, url)
# return match.group(1) if match else url.strip()
# # β
Agent 1: Summarizer (Simulated)
# def summarize_youtube(video_url):
# try:
# video_id = extract_video_id(video_url)
# saved_transcripts = {
# "dQw4w9WgXcQ": "We're no strangers to love. You know the rules and so do I...",
# "F9cTlfD7ZGM": "This is a video about AI agents and how they collaborate.",
# "HMcFwjWVprs": "This presentation explains the GenAI protocol and its future."
# }
# 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}"
# return summary, translation, video_embed_link
# except Exception as e:
# return f"β Error: {str(e)}", "", ""
# # β
Master Agent Workflow with Embedded YouTube Preview
# def run_agents(url):
# summary, translation, embed = 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
# # β
Gradio UI
# with gr.Blocks() as demo:
# gr.Markdown("## π₯ AI Agents: YouTube Summary + Spanish Translator")
# gr.Markdown("π Enter a YouTube video URL to simulate AI agent collaboration.")
# 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()
# run_btn = gr.Button("π Run Agents")
# run_btn.click(fn=run_agents, inputs=input_url, outputs=[summary_output, translation_output, video_output])
# demo.launch()
import gradio as gr
from deep_translator import GoogleTranslator
import re
from saved_transcripts import saved_transcripts # β
Import 100 video transcripts
# β
Extract video ID from YouTube URL
def extract_video_id(url):
regex = r"(?:v=|\/)([0-9A-Za-z_-]{11})"
match = re.search(regex, url)
return match.group(1) if match else url.strip()
# β
Agent 1: Summarizer (Simulated)
def summarize_youtube(video_url):
try:
video_id = extract_video_id(video_url)
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}"
return summary, translation, video_embed_link
except Exception as e:
return f"β Error: {str(e)}", "", ""
# β
Master Agent Workflow with Embedded YouTube Preview
def run_agents(url):
summary, translation, embed = 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
# β
Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## π₯ AI Agents: YouTube Summary + Spanish Translator")
gr.Markdown("π Enter a YouTube video URL to simulate AI agent collaboration.")
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()
run_btn = gr.Button("π Run Agents")
run_btn.click(fn=run_agents, inputs=input_url, outputs=[summary_output, translation_output, video_output])
demo.launch()
|