asad231 commited on
Commit
cdb10f1
·
verified ·
1 Parent(s): f625ede

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from youtube_transcript_api import YouTubeTranscriptApi
3
+ from deep_translator import GoogleTranslator
4
+
5
+ # Agent 1: Summarizer
6
+ def summarize_youtube(video_url):
7
+ try:
8
+ video_id = video_url.split("v=")[-1]
9
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
10
+ text = " ".join([entry["text"] for entry in transcript[:15]])
11
+ return text[:500]
12
+ except Exception as e:
13
+ return f"Error: {e}"
14
+
15
+ # Agent 2: Translator
16
+ def translate_to_spanish(english_text):
17
+ try:
18
+ return GoogleTranslator(source='auto', target='es').translate(english_text)
19
+ except Exception as e:
20
+ return f"Error: {e}"
21
+
22
+ # Workflow function
23
+ def agent_workflow(video_url):
24
+ summary = summarize_youtube(video_url)
25
+ translated = translate_to_spanish(summary)
26
+ return summary, translated
27
+
28
+ # Gradio UI
29
+ demo = gr.Interface(
30
+ fn=agent_workflow,
31
+ inputs=gr.Textbox(label="YouTube Video Link"),
32
+ outputs=[gr.Textbox(label="English Summary"), gr.Textbox(label="Spanish Translation")],
33
+ title="Lead with AI Agents",
34
+ description="🔹 Agent 1: Summarizes YouTube video 🔹 Agent 2: Translates to Spanish"
35
+ )
36
+
37
+ demo.launch()