Spaces:
Sleeping
Sleeping
File size: 1,179 Bytes
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 |
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi
from deep_translator import GoogleTranslator
# Agent 1: Summarizer
def summarize_youtube(video_url):
try:
video_id = video_url.split("v=")[-1]
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: {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: {e}"
# Workflow function
def agent_workflow(video_url):
summary = summarize_youtube(video_url)
translated = translate_to_spanish(summary)
return summary, translated
# Gradio UI
demo = gr.Interface(
fn=agent_workflow,
inputs=gr.Textbox(label="YouTube Video Link"),
outputs=[gr.Textbox(label="English Summary"), gr.Textbox(label="Spanish Translation")],
title="Lead with AI Agents",
description="๐น Agent 1: Summarizes YouTube video ๐น Agent 2: Translates to Spanish"
)
demo.launch()
|