asad231 commited on
Commit
18bb69f
Β·
verified Β·
1 Parent(s): 025daf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -2,47 +2,47 @@ import gradio as gr
2
  from deep_translator import GoogleTranslator
3
  import re
4
 
5
- # Extract video ID from URL
6
  def extract_video_id(url):
7
  regex = r"(?:v=|\/)([0-9A-Za-z_-]{11})"
8
  match = re.search(regex, url)
9
  return match.group(1) if match else url.strip()
10
 
11
- # Simulated transcript agent
12
  def summarize_youtube(video_url):
13
  try:
14
  video_id = extract_video_id(video_url)
15
 
16
- # Predefined summaries for demonstration
17
  saved_transcripts = {
18
  "dQw4w9WgXcQ": "We're no strangers to love. You know the rules and so do I...",
19
- "F9cTlfD7ZGM": "This is a video about AI agents and their collaboration.",
20
- "HMcFwjWVprs": "In this talk, we cover the future of GenAI protocols and their applications."
21
  }
22
 
23
  if video_id not in saved_transcripts:
24
- return "❌ Transcript not available for this video. Please use a supported demo video."
25
 
26
  return saved_transcripts[video_id]
27
  except Exception as e:
28
- return f"❌ Error: {str(e)}"
29
 
30
- # Translator agent
31
  def translate_to_spanish(english_text):
32
  try:
33
  return GoogleTranslator(source='auto', target='es').translate(english_text)
34
  except Exception as e:
35
- return f"❌ Error: {str(e)}"
36
 
37
- # Workflow (master agent)
38
  def agent_workflow(video_url):
39
  summary = summarize_youtube(video_url)
40
  if summary.startswith("❌"):
41
  return summary, ""
42
- translated = translate_to_spanish(summary)
43
- return summary, translated
44
 
45
- # Gradio UI
46
  demo = gr.Interface(
47
  fn=agent_workflow,
48
  inputs=gr.Textbox(label="πŸŽ₯ Enter YouTube Video Link"),
@@ -50,5 +50,8 @@ demo = gr.Interface(
50
  gr.Textbox(label="🧠 English Summary"),
51
  gr.Textbox(label="🌍 Spanish Translation")
52
  ],
53
- title="🧠 AI Agents: YouTube Summary + Spanish Translation",
54
- description="Agent 1: Summarizer (simulated)
 
 
 
 
2
  from deep_translator import GoogleTranslator
3
  import re
4
 
5
+ # βœ… Extract video ID from YouTube URL
6
  def extract_video_id(url):
7
  regex = r"(?:v=|\/)([0-9A-Za-z_-]{11})"
8
  match = re.search(regex, url)
9
  return match.group(1) if match else url.strip()
10
 
11
+ # βœ… Agent 1: Summarizer (simulated)
12
  def summarize_youtube(video_url):
13
  try:
14
  video_id = extract_video_id(video_url)
15
 
16
+ # Simulated transcript summaries for demo
17
  saved_transcripts = {
18
  "dQw4w9WgXcQ": "We're no strangers to love. You know the rules and so do I...",
19
+ "F9cTlfD7ZGM": "This is a video about AI agents and how they collaborate.",
20
+ "HMcFwjWVprs": "This presentation explains the GenAI protocol and its future."
21
  }
22
 
23
  if video_id not in saved_transcripts:
24
+ return "❌ Transcript not available for this video. Try one of the demo videos listed."
25
 
26
  return saved_transcripts[video_id]
27
  except Exception as e:
28
+ return f"❌ Error in Summarizer: {str(e)}"
29
 
30
+ # βœ… Agent 2: Translator
31
  def translate_to_spanish(english_text):
32
  try:
33
  return GoogleTranslator(source='auto', target='es').translate(english_text)
34
  except Exception as e:
35
+ return f"❌ Error in Translator: {str(e)}"
36
 
37
+ # βœ… Master Agent workflow
38
  def agent_workflow(video_url):
39
  summary = summarize_youtube(video_url)
40
  if summary.startswith("❌"):
41
  return summary, ""
42
+ translation = translate_to_spanish(summary)
43
+ return summary, translation
44
 
45
+ # βœ… Gradio UI
46
  demo = gr.Interface(
47
  fn=agent_workflow,
48
  inputs=gr.Textbox(label="πŸŽ₯ Enter YouTube Video Link"),
 
50
  gr.Textbox(label="🧠 English Summary"),
51
  gr.Textbox(label="🌍 Spanish Translation")
52
  ],
53
+ title="🧠 AI Agents Hackathon – Hugging Face App",
54
+ description="Agent 1: Summarizer (simulated) β€’ Agent 2: Translator (real)"
55
+ )
56
+
57
+ demo.launch()