Skip to content

Commit 840246c

Browse files
authored
Merge pull request #40 from video-db/ankit/add-genai-tools
Ankit/add genai tools
2 parents 1de8fbb + 6ee30af commit 840246c

File tree

5 files changed

+185
-9
lines changed

5 files changed

+185
-9
lines changed

Diff for: videodb/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" About information for videodb sdk"""
22

33

4-
__version__ = "0.2.11"
4+
__version__ = "0.2.12"
55
__title__ = "videodb"
66
__author__ = "videodb"
77
__email__ = "[email protected]"

Diff for: videodb/_constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class ApiPath:
7272
download = "download"
7373
title = "title"
7474
generate_url = "generate_url"
75+
generate = "generate"
76+
web = "web"
77+
translate = "translate"
78+
dub = "dub"
7579

7680

7781
class Status:

Diff for: videodb/client.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def update_collection(self, id: str, name: str, description: str) -> Collection:
110110
"""Update an existing collection.
111111
112112
:param str id: ID of the collection
113-
:param str name: Name of the collection
113+
:param str name: Name of the collection
114114
:param str description: Description of the collection
115115
:return: :class:`Collection <Collection>` object
116116
:rtype: :class:`videodb.collection.Collection`
@@ -163,6 +163,31 @@ def download(self, stream_link: str, name: str) -> dict:
163163
},
164164
)
165165

166+
def youtube_search(
167+
self,
168+
query: str,
169+
result_threshold: Optional[int] = 10,
170+
duration: str = "medium",
171+
) -> List[dict]:
172+
"""Search for a query on YouTube.
173+
174+
:param str query: Query to search for
175+
:param int result_threshold: Number of results to return (optional)
176+
:param str duration: Duration of the video (optional)
177+
:return: List of YouTube search results
178+
:rtype: List[dict]
179+
"""
180+
search_data = self.post(
181+
path=f"{ApiPath.collection}/{self.collection_id}/{ApiPath.search}/{ApiPath.web}",
182+
data={
183+
"query": query,
184+
"result_threshold": result_threshold,
185+
"platform": "youtube",
186+
"duration": duration,
187+
},
188+
)
189+
return search_data.get("results")
190+
166191
def upload(
167192
self,
168193
file_path: str = None,

Diff for: videodb/collection.py

+129-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import logging
22

3-
from typing import (
4-
Optional,
5-
Union,
6-
List,
7-
Dict,
8-
Any,
9-
)
3+
from typing import Optional, Union, List, Dict, Any, Literal
104
from videodb._upload import (
115
upload,
126
)
@@ -170,6 +164,134 @@ def delete_image(self, image_id: str) -> None:
170164
path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
171165
)
172166

167+
def generate_image(
168+
self,
169+
prompt: str,
170+
aspect_ratio: Optional[Literal["1:1", "9:16", "16:9", "4:3", "3:4"]] = "1:1",
171+
callback_url: Optional[str] = None,
172+
) -> Image:
173+
"""Generate an image from a prompt.
174+
175+
:param str prompt: Prompt for the image generation
176+
:param str aspect_ratio: Aspect ratio of the image (optional)
177+
:param str callback_url: URL to receive the callback (optional)
178+
:return: :class:`Image <Image>` object
179+
:rtype: :class:`videodb.image.Image`
180+
"""
181+
image_data = self._connection.post(
182+
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.image}",
183+
data={
184+
"prompt": prompt,
185+
"aspect_ratio": aspect_ratio,
186+
"callback_url": callback_url,
187+
},
188+
)
189+
if image_data:
190+
return Image(self._connection, **image_data)
191+
192+
def generate_music(
193+
self, prompt: str, duration: int = 5, callback_url: Optional[str] = None
194+
) -> Audio:
195+
"""Generate music from a prompt.
196+
197+
:param str prompt: Prompt for the music generation
198+
:param int duration: Duration of the music in seconds
199+
:param str callback_url: URL to receive the callback (optional)
200+
:return: :class:`Audio <Audio>` object
201+
:rtype: :class:`videodb.audio.Audio`
202+
"""
203+
audio_data = self._connection.post(
204+
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.audio}",
205+
data={
206+
"prompt": prompt,
207+
"duration": duration,
208+
"audio_type": "music",
209+
"callback_url": callback_url,
210+
},
211+
)
212+
if audio_data:
213+
return Audio(self._connection, **audio_data)
214+
215+
def generate_sound_effect(
216+
self,
217+
prompt: str,
218+
duration: int = 2,
219+
config: dict = {},
220+
callback_url: Optional[str] = None,
221+
) -> Audio:
222+
"""Generate sound effect from a prompt.
223+
224+
:param str prompt: Prompt for the sound effect generation
225+
:param int duration: Duration of the sound effect in seconds
226+
:param dict config: Configuration for the sound effect generation
227+
:param str callback_url: URL to receive the callback (optional)
228+
:return: :class:`Audio <Audio>` object
229+
:rtype: :class:`videodb.audio.Audio`
230+
"""
231+
audio_data = self._connection.post(
232+
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.audio}",
233+
data={
234+
"prompt": prompt,
235+
"duration": duration,
236+
"audio_type": "sound_effect",
237+
"config": config,
238+
"callback_url": callback_url,
239+
},
240+
)
241+
if audio_data:
242+
return Audio(self._connection, **audio_data)
243+
244+
def generate_voice(
245+
self,
246+
text: str,
247+
voice_name: str = "Default",
248+
config: dict = {},
249+
callback_url: Optional[str] = None,
250+
) -> Audio:
251+
"""Generate voice from text.
252+
253+
:param str text: Text to convert to voice
254+
:param str voice_name: Name of the voice to use
255+
:param dict config: Configuration for the voice generation
256+
:param str callback_url: URL to receive the callback (optional)
257+
:return: :class:`Audio <Audio>` object
258+
:rtype: :class:`videodb.audio.Audio`
259+
"""
260+
audio_data = self._connection.post(
261+
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.audio}",
262+
data={
263+
"text": text,
264+
"audio_type": "voice",
265+
"voice_name": voice_name,
266+
"config": config,
267+
"callback_url": callback_url,
268+
},
269+
)
270+
if audio_data:
271+
return Audio(self._connection, **audio_data)
272+
273+
def dub_video(
274+
self, video_id: str, language_code: str, callback_url: Optional[str] = None
275+
) -> Video:
276+
"""Dub a video.
277+
278+
:param str video_id: ID of the video to dub
279+
:param str language_code: Language code to dub the video to
280+
:param str callback_url: URL to receive the callback (optional)
281+
:return: :class:`Video <Video>` object
282+
:rtype: :class:`videodb.video.Video`
283+
"""
284+
dub_data = self._connection.post(
285+
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.video}/{ApiPath.dub}",
286+
data={
287+
"video_id": video_id,
288+
"language_code": language_code,
289+
"callback_url": callback_url,
290+
},
291+
)
292+
if dub_data:
293+
return Video(self._connection, **dub_data)
294+
173295
def search(
174296
self,
175297
query: str,

Diff for: videodb/video.py

+25
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,31 @@ def get_transcript_text(
249249
)
250250
return self.transcript_text
251251

252+
def translate_transcript(
253+
self,
254+
language: str,
255+
additional_notes: str = "",
256+
callback_url: Optional[str] = None,
257+
) -> List[dict]:
258+
"""Translate transcript of a video to a given language.
259+
260+
:param str language: Language to translate the transcript
261+
:param str additional_notes: Additional notes for the style of language
262+
:param str callback_url: URL to receive the callback (optional)
263+
:return: List of translated transcript
264+
:rtype: List[dict]
265+
"""
266+
translate_data = self._connection.post(
267+
path=f"{ApiPath.collection}/{self.collection_id}/{ApiPath.video}/{self.id}/{ApiPath.translate}",
268+
data={
269+
"language": language,
270+
"additional_notes": additional_notes,
271+
"callback_url": callback_url,
272+
},
273+
)
274+
if translate_data:
275+
return translate_data.get("translated_transcript")
276+
252277
def index_spoken_words(
253278
self,
254279
language_code: Optional[str] = None,

0 commit comments

Comments
 (0)