Spaces:
Sleeping
Sleeping
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() | |