Spaces:
Running
Running
Daniel Amendoeira
commited on
Update tools.py
Browse files
tools.py
CHANGED
@@ -8,7 +8,7 @@ from urllib.parse import urlparse
|
|
8 |
from openai import OpenAI
|
9 |
from youtube_transcript_api import YouTubeTranscriptApi
|
10 |
from pytube import extract
|
11 |
-
|
12 |
|
13 |
@tool
|
14 |
def add(a: float, b: float) -> float:
|
@@ -95,7 +95,6 @@ def transcribe_audio(audio_file: str, file_extension: str) -> str:
|
|
95 |
Returns:
|
96 |
str: The transcribed text from the audio.
|
97 |
"""
|
98 |
-
|
99 |
try:
|
100 |
response = requests.get(audio_file) # download the audio_file
|
101 |
response.raise_for_status() # check if the http request was successful
|
@@ -137,4 +136,32 @@ def transcribe_youtube(youtube_url: str) -> str:
|
|
137 |
return text
|
138 |
|
139 |
except Exception as e:
|
140 |
-
return f"transcribe_youtube failed: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
from openai import OpenAI
|
9 |
from youtube_transcript_api import YouTubeTranscriptApi
|
10 |
from pytube import extract
|
11 |
+
from openai import OpenAI
|
12 |
|
13 |
@tool
|
14 |
def add(a: float, b: float) -> float:
|
|
|
95 |
Returns:
|
96 |
str: The transcribed text from the audio.
|
97 |
"""
|
|
|
98 |
try:
|
99 |
response = requests.get(audio_file) # download the audio_file
|
100 |
response.raise_for_status() # check if the http request was successful
|
|
|
136 |
return text
|
137 |
|
138 |
except Exception as e:
|
139 |
+
return f"transcribe_youtube failed: {e}"
|
140 |
+
|
141 |
+
|
142 |
+
# TESTING
|
143 |
+
@tool
|
144 |
+
def query_image(query: str, image_url: str) -> str:
|
145 |
+
""" Ask anything about an image using a Vision Language Model
|
146 |
+
Args:
|
147 |
+
query (str): the query about the image, e.g. how many animals are on the image?
|
148 |
+
image_url (str): the image's URL
|
149 |
+
"""
|
150 |
+
try:
|
151 |
+
client = OpenAI()
|
152 |
+
response = client.responses.create(
|
153 |
+
model="gpt-4.1-nano",
|
154 |
+
input=[
|
155 |
+
{
|
156 |
+
"role": "user",
|
157 |
+
"content": [
|
158 |
+
{"type": "input_text", "text": query},
|
159 |
+
{"type": "input_image","image_url": image_url},
|
160 |
+
],
|
161 |
+
}
|
162 |
+
],
|
163 |
+
)
|
164 |
+
return response.output_text
|
165 |
+
|
166 |
+
except Exception as e:
|
167 |
+
return f"query_image failed: {e}"
|