FD900 commited on
Commit
9b4ce5f
·
verified ·
1 Parent(s): 51a00c3

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +13 -26
tools.py CHANGED
@@ -1,16 +1,20 @@
1
  import tempfile
2
  import requests
3
  import os
4
-
5
  from urllib.parse import urlparse
6
  from typing import Optional, List
7
  import yt_dlp
8
  import imageio
9
-
10
  from PIL import Image
11
- from dotenv import load_dotenv
12
- from gaia_benchmark.tools import tool
13
  import whisper
 
 
 
 
 
 
 
 
14
 
15
  load_dotenv()
16
 
@@ -34,11 +38,11 @@ def youtube_frames_to_images(url: str, sample_interval_seconds: int = 5) -> List
34
  'force_ipv4': True,
35
  }
36
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
37
- info = ydl.extract_info(url, download=True)
38
 
39
  video_path = next((os.path.join(tmpdir, f) for f in os.listdir(tmpdir) if f.endswith('.mp4')), None)
40
  reader = imageio.get_reader(video_path)
41
- fps = reader.get_meta_data().get('fps')
42
  frame_interval = int(fps * sample_interval_seconds)
43
  images = [Image.fromarray(frame) for idx, frame in enumerate(reader) if idx % frame_interval == 0]
44
  reader.close()
@@ -107,28 +111,11 @@ def youtube_transcribe(url: str) -> str:
107
  'force_ipv4': True,
108
  }
109
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
110
- ydl.extract_info(url, download=True)
 
111
  audio_path = next((os.path.join(tmpdir, f) for f in os.listdir(tmpdir) if f.endswith('.wav')), None)
112
  return model.transcribe(audio_path)['text']
113
 
114
  @tool
115
  def transcribe_audio(audio_file_path: str) -> str:
116
- return whisper.load_model("small").transcribe(audio_file_path)['text']
117
-
118
- # 🔧 Stub Tools for Mistral Compatibility
119
-
120
- @tool
121
- def web_search(query: str) -> str:
122
- return f"(Stub) Web search results for: {query}"
123
-
124
- @tool
125
- def wikipedia_search(topic: str) -> str:
126
- return f"(Stub) Wikipedia summary for: {topic}"
127
-
128
- @tool
129
- def visit_webpage(url: str) -> str:
130
- return f"(Stub) Visited webpage at: {url}"
131
-
132
- @tool
133
- def final_answer(response: str) -> str:
134
- return f"(Stub) Final answer: {response}"
 
1
  import tempfile
2
  import requests
3
  import os
 
4
  from urllib.parse import urlparse
5
  from typing import Optional, List
6
  import yt_dlp
7
  import imageio
 
8
  from PIL import Image
 
 
9
  import whisper
10
+ from dotenv import load_dotenv
11
+
12
+ # Fallback tool decorator if gaia_benchmark.tools is not available
13
+ try:
14
+ from gaia_benchmark.tools import tool
15
+ except ImportError:
16
+ def tool(func):
17
+ return func
18
 
19
  load_dotenv()
20
 
 
38
  'force_ipv4': True,
39
  }
40
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
41
+ ydl.download([url])
42
 
43
  video_path = next((os.path.join(tmpdir, f) for f in os.listdir(tmpdir) if f.endswith('.mp4')), None)
44
  reader = imageio.get_reader(video_path)
45
+ fps = reader.get_meta_data().get('fps', 25)
46
  frame_interval = int(fps * sample_interval_seconds)
47
  images = [Image.fromarray(frame) for idx, frame in enumerate(reader) if idx % frame_interval == 0]
48
  reader.close()
 
111
  'force_ipv4': True,
112
  }
113
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
114
+ ydl.download([url])
115
+
116
  audio_path = next((os.path.join(tmpdir, f) for f in os.listdir(tmpdir) if f.endswith('.wav')), None)
117
  return model.transcribe(audio_path)['text']
118
 
119
  @tool
120
  def transcribe_audio(audio_file_path: str) -> str:
121
+ return whisper.load_model("small").transcribe(audio_file_path)['text']