Spaces:
Sleeping
Sleeping
File size: 1,646 Bytes
cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 b83d913 cdb10f1 |
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 |
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi
from deep_translator import GoogleTranslator
import re
# β
Extract video ID from YouTube URL
def extract_video_id(url):
# Supports standard, short, and embed URLs
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
def summarize_youtube(video_url):
try:
video_id = extract_video_id(video_url)
transcript = YouTubeTranscriptApi.get_transcript(video_id)
text = " ".join([entry["text"] for entry in transcript[:15]])
return text[:500]
except Exception as e:
return f"β Error in Summarizer: {str(e)}"
# β
Agent 2: Translator
def translate_to_spanish(english_text):
try:
return GoogleTranslator(source='auto', target='es').translate(english_text)
except Exception as e:
return f"β Error in Translator: {str(e)}"
# β
Workflow Function (Master Agent)
def agent_workflow(video_url):
summary = summarize_youtube(video_url)
if summary.startswith("β"):
return summary, ""
translated = translate_to_spanish(summary)
return summary, translated
# β
Gradio UI
demo = gr.Interface(
fn=agent_workflow,
inputs=gr.Textbox(label="π₯ Enter YouTube Video Link"),
outputs=[
gr.Textbox(label="π§ English Summary"),
gr.Textbox(label="π Spanish Translation")
],
title="Lead with AI Agents Hackathon Project",
description="π§ Agent 1: Summarizes YouTube Video Β· π Agent 2: Translates Summary to Spanish"
)
demo.launch()
|