Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -2,7 +2,6 @@ import tempfile
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
from time import sleep
|
| 6 |
from urllib.parse import urlparse
|
| 7 |
from typing import Optional, List
|
| 8 |
import yt_dlp
|
|
@@ -10,17 +9,17 @@ import imageio
|
|
| 10 |
|
| 11 |
from PIL import Image
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
-
from gaia_benchmark.tools import tool
|
| 14 |
import whisper
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
load_dotenv()
|
| 17 |
|
| 18 |
@tool
|
| 19 |
def use_vision_model(question: str, images: List[Image.Image]) -> str:
|
| 20 |
-
"""
|
| 21 |
-
Use a Vision Model to answer a question about a set of images.
|
| 22 |
-
This stub exists for potential future Gemini or Mistral multimodal integration.
|
| 23 |
-
"""
|
| 24 |
return "Vision model is not available for Mistral. Please integrate a separate endpoint for image analysis."
|
| 25 |
|
| 26 |
@tool
|
|
@@ -39,7 +38,7 @@ def youtube_frames_to_images(url: str, sample_interval_seconds: int = 5) -> List
|
|
| 39 |
'force_ipv4': True,
|
| 40 |
}
|
| 41 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 42 |
-
|
| 43 |
|
| 44 |
video_path = next((os.path.join(tmpdir, f) for f in os.listdir(tmpdir) if f.endswith('.mp4')), None)
|
| 45 |
reader = imageio.get_reader(video_path)
|
|
@@ -114,8 +113,8 @@ def youtube_transcribe(url: str) -> str:
|
|
| 114 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 115 |
ydl.extract_info(url, download=True)
|
| 116 |
audio_path = next((os.path.join(tmpdir, f) for f in os.listdir(tmpdir) if f.endswith('.wav')), None)
|
| 117 |
-
return
|
| 118 |
|
| 119 |
@tool
|
| 120 |
def transcribe_audio(audio_file_path: str) -> str:
|
| 121 |
-
return whisper.load_model("small").transcribe(audio_file_path)['text']
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
from urllib.parse import urlparse
|
| 6 |
from typing import Optional, List
|
| 7 |
import yt_dlp
|
|
|
|
| 9 |
|
| 10 |
from PIL import Image
|
| 11 |
from dotenv import load_dotenv
|
|
|
|
| 12 |
import whisper
|
| 13 |
|
| 14 |
+
# ✅ Define local @tool decorator
|
| 15 |
+
def tool(func):
|
| 16 |
+
func.is_tool = True
|
| 17 |
+
return func
|
| 18 |
+
|
| 19 |
load_dotenv()
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def use_vision_model(question: str, images: List[Image.Image]) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return "Vision model is not available for Mistral. Please integrate a separate endpoint for image analysis."
|
| 24 |
|
| 25 |
@tool
|
|
|
|
| 38 |
'force_ipv4': True,
|
| 39 |
}
|
| 40 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 41 |
+
ydl.extract_info(url, download=True)
|
| 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)
|
|
|
|
| 113 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 114 |
ydl.extract_info(url, download=True)
|
| 115 |
audio_path = next((os.path.join(tmpdir, f) for f in os.listdir(tmpdir) if f.endswith('.wav')), None)
|
| 116 |
+
return model.transcribe(audio_path)['text']
|
| 117 |
|
| 118 |
@tool
|
| 119 |
def transcribe_audio(audio_file_path: str) -> str:
|
| 120 |
+
return whisper.load_model("small").transcribe(audio_file_path)['text']
|