ekkasilina commited on
Commit
ed2154b
·
verified ·
1 Parent(s): b21adef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -5,6 +5,7 @@ import inspect
5
  import pandas as pd
6
  from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, tool
7
  from smolagents import OpenAIServerModel
 
8
 
9
 
10
  # (Keep Constants as is)
@@ -51,7 +52,23 @@ def analyze_image(question: str, image_url: str) -> str:
51
 
52
  return response
53
 
54
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  def run_and_submit_all( profile: gr.OAuthProfile | None):
57
  """
@@ -83,7 +100,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
83
  search_tool = DuckDuckGoSearchTool()
84
  my_small_agent = CodeAgent(
85
  model=openai_41mini_model,
86
- tools=[search_tool, analyze_image],
87
  name="web_agent",
88
  description="Use search engine to find webpages related to a subject and get the page content",
89
  #additional_authorized_imports=["pandas", "numpy","bs4"],
 
5
  import pandas as pd
6
  from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, tool
7
  from smolagents import OpenAIServerModel
8
+ from youtube_transcript_api import YouTubeTranscriptApi
9
 
10
 
11
  # (Keep Constants as is)
 
52
 
53
  return response
54
 
55
+ @tool
56
+ # a function to get youtube transcript from video id
57
+ def get_youtube_transcript(video_id: str) -> str:
58
+ """
59
+ Fetches the transcript of a YouTube video given its video ID.
60
+ Args:
61
+ video_id (str): The ID of the YouTube video. Pass in the video ID, NOT the video URL. For a video with the URL https://www.youtube.com/watch?v=12345 the ID is 12345.
62
+ Returns:
63
+ str: The transcript of the YouTube video. as a single string with each line separated by a newline character.
64
+ """
65
+ # Initialize the YouTubeTranscriptApi
66
+ ytt_api = YouTubeTranscriptApi()
67
+ fetched_transcript = ytt_api.fetch(video_id)
68
+ raw_data = fetched_transcript.to_raw_data()
69
+ # raw data is in the form of [{ 'text': 'Hey there', 'start': 0.0, 'duration': 1.54 }, { 'text': 'how are you',, 'start': 1.54, 'duration': 4.16 }, ... ] we will return ony the text element as lines
70
+ transcript = "\n".join([item['text'] for item in raw_data])
71
+ return transcript
72
 
73
  def run_and_submit_all( profile: gr.OAuthProfile | None):
74
  """
 
100
  search_tool = DuckDuckGoSearchTool()
101
  my_small_agent = CodeAgent(
102
  model=openai_41mini_model,
103
+ tools=[search_tool, analyze_image, get_youtube_transcript],
104
  name="web_agent",
105
  description="Use search engine to find webpages related to a subject and get the page content",
106
  #additional_authorized_imports=["pandas", "numpy","bs4"],