Spaces:
Sleeping
Sleeping
File size: 2,075 Bytes
cdb10f1 b83d913 b0387ad cdb10f1 3871e34 b83d913 c1701a5 b83d913 3871e34 cdb10f1 b83d913 1374600 c1701a5 1374600 32bef68 c1701a5 cdb10f1 c1701a5 0af641e 3871e34 32bef68 27cdad0 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 |
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 + Youtube Video")
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()
|