BenjaminKaindu0506 commited on
Commit
2f79205
·
verified ·
1 Parent(s): be7ba79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -36,7 +36,31 @@ class BasicAgent:
36
  with open(path, "wb") as f:
37
  f.write(resp.content)
38
  return path
 
 
 
 
 
 
 
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  @tool
41
  def read_spreadsheet(file_path: str) -> str:
42
  """
@@ -81,6 +105,7 @@ class BasicAgent:
81
  VisitWebpageTool(),
82
  fetch_task_file,
83
  read_spreadsheet,
 
84
  #os.environ["HF_TOKEN"] = "hf_token",
85
  #image_analysis_tool,
86
  ],
 
36
  with open(path, "wb") as f:
37
  f.write(resp.content)
38
  return path
39
+ @tool
40
+ def get_youtube_transcript(url: str) -> str:
41
+ """
42
+ Fetches the transcript/captions of a YouTube video.
43
+
44
+ Args:
45
+ url: The full YouTube video URL.
46
 
47
+ Returns:
48
+ The transcript text, or an error message if unavailable.
49
+ """
50
+ from youtube_transcript_api import YouTubeTranscriptApi
51
+ import re
52
+
53
+ match = re.search(r"(?:v=|youtu\.be/)([\w-]{11})", url)
54
+ if not match:
55
+ return "Could not extract video ID from URL."
56
+ video_id = match.group(1)
57
+
58
+ try:
59
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
60
+ return " ".join(entry["text"] for entry in transcript)
61
+ except Exception as e:
62
+ return f"Transcript unavailable: {e}"
63
+
64
  @tool
65
  def read_spreadsheet(file_path: str) -> str:
66
  """
 
105
  VisitWebpageTool(),
106
  fetch_task_file,
107
  read_spreadsheet,
108
+ get_youtube_transcript,
109
  #os.environ["HF_TOKEN"] = "hf_token",
110
  #image_analysis_tool,
111
  ],