Skip to content

Ankit/add genai tools #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion videodb/__about__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" About information for videodb sdk"""


__version__ = "0.2.11"
__version__ = "0.2.12"
__title__ = "videodb"
__author__ = "videodb"
__email__ = "[email protected]"
Expand Down
4 changes: 4 additions & 0 deletions videodb/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class ApiPath:
download = "download"
title = "title"
generate_url = "generate_url"
generate = "generate"
web = "web"
translate = "translate"
dub = "dub"


class Status:
Expand Down
27 changes: 26 additions & 1 deletion videodb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def update_collection(self, id: str, name: str, description: str) -> Collection:
"""Update an existing collection.

:param str id: ID of the collection
:param str name: Name of the collection
:param str name: Name of the collection
:param str description: Description of the collection
:return: :class:`Collection <Collection>` object
:rtype: :class:`videodb.collection.Collection`
Expand Down Expand Up @@ -163,6 +163,31 @@ def download(self, stream_link: str, name: str) -> dict:
},
)

def youtube_search(
self,
query: str,
result_threshold: Optional[int] = 10,
duration: str = "medium",
) -> List[dict]:
"""Search for a query on YouTube.

:param str query: Query to search for
:param int result_threshold: Number of results to return (optional)
:param str duration: Duration of the video (optional)
:return: List of YouTube search results
:rtype: List[dict]
"""
search_data = self.post(
path=f"{ApiPath.collection}/{self.collection_id}/{ApiPath.search}/{ApiPath.web}",
data={
"query": query,
"result_threshold": result_threshold,
"platform": "youtube",
"duration": duration,
},
)
return search_data.get("results")

def upload(
self,
file_path: str = None,
Expand Down
136 changes: 129 additions & 7 deletions videodb/collection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import logging

from typing import (
Optional,
Union,
List,
Dict,
Any,
)
from typing import Optional, Union, List, Dict, Any, Literal
from videodb._upload import (
upload,
)
Expand Down Expand Up @@ -170,6 +164,134 @@ def delete_image(self, image_id: str) -> None:
path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
)

def generate_image(
self,
prompt: str,
aspect_ratio: Optional[Literal["1:1", "9:16", "16:9", "4:3", "3:4"]] = "1:1",
callback_url: Optional[str] = None,
) -> Image:
"""Generate an image from a prompt.

:param str prompt: Prompt for the image generation
:param str aspect_ratio: Aspect ratio of the image (optional)
:param str callback_url: URL to receive the callback (optional)
:return: :class:`Image <Image>` object
:rtype: :class:`videodb.image.Image`
"""
image_data = self._connection.post(
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.image}",
data={
"prompt": prompt,
"aspect_ratio": aspect_ratio,
"callback_url": callback_url,
},
)
if image_data:
return Image(self._connection, **image_data)

def generate_music(
self, prompt: str, duration: int = 5, callback_url: Optional[str] = None
) -> Audio:
"""Generate music from a prompt.

:param str prompt: Prompt for the music generation
:param int duration: Duration of the music in seconds
:param str callback_url: URL to receive the callback (optional)
:return: :class:`Audio <Audio>` object
:rtype: :class:`videodb.audio.Audio`
"""
audio_data = self._connection.post(
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.audio}",
data={
"prompt": prompt,
"duration": duration,
"audio_type": "music",
"callback_url": callback_url,
},
)
if audio_data:
return Audio(self._connection, **audio_data)

def generate_sound_effect(
self,
prompt: str,
duration: int = 2,
config: dict = {},
callback_url: Optional[str] = None,
) -> Audio:
"""Generate sound effect from a prompt.

:param str prompt: Prompt for the sound effect generation
:param int duration: Duration of the sound effect in seconds
:param dict config: Configuration for the sound effect generation
:param str callback_url: URL to receive the callback (optional)
:return: :class:`Audio <Audio>` object
:rtype: :class:`videodb.audio.Audio`
"""
audio_data = self._connection.post(
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.audio}",
data={
"prompt": prompt,
"duration": duration,
"audio_type": "sound_effect",
"config": config,
"callback_url": callback_url,
},
)
if audio_data:
return Audio(self._connection, **audio_data)

def generate_voice(
self,
text: str,
voice_name: str = "Default",
config: dict = {},
callback_url: Optional[str] = None,
) -> Audio:
"""Generate voice from text.

:param str text: Text to convert to voice
:param str voice_name: Name of the voice to use
:param dict config: Configuration for the voice generation
:param str callback_url: URL to receive the callback (optional)
:return: :class:`Audio <Audio>` object
:rtype: :class:`videodb.audio.Audio`
"""
audio_data = self._connection.post(
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.audio}",
data={
"text": text,
"audio_type": "voice",
"voice_name": voice_name,
"config": config,
"callback_url": callback_url,
},
)
if audio_data:
return Audio(self._connection, **audio_data)

def dub_video(
self, video_id: str, language_code: str, callback_url: Optional[str] = None
) -> Video:
"""Dub a video.

:param str video_id: ID of the video to dub
:param str language_code: Language code to dub the video to
:param str callback_url: URL to receive the callback (optional)
:return: :class:`Video <Video>` object
:rtype: :class:`videodb.video.Video`
"""
dub_data = self._connection.post(
path=f"{ApiPath.collection}/{self.id}/{ApiPath.generate}/{ApiPath.video}/{ApiPath.dub}",
data={
"video_id": video_id,
"language_code": language_code,
"callback_url": callback_url,
},
)
if dub_data:
return Video(self._connection, **dub_data)

def search(
self,
query: str,
Expand Down
25 changes: 25 additions & 0 deletions videodb/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,31 @@ def get_transcript_text(
)
return self.transcript_text

def translate_transcript(
self,
language: str,
additional_notes: str = "",
callback_url: Optional[str] = None,
) -> List[dict]:
"""Translate transcript of a video to a given language.

:param str language: Language to translate the transcript
:param str additional_notes: Additional notes for the style of language
:param str callback_url: URL to receive the callback (optional)
:return: List of translated transcript
:rtype: List[dict]
"""
translate_data = self._connection.post(
path=f"{ApiPath.collection}/{self.collection_id}/{ApiPath.video}/{self.id}/{ApiPath.translate}",
data={
"language": language,
"additional_notes": additional_notes,
"callback_url": callback_url,
},
)
if translate_data:
return translate_data.get("translated_transcript")

def index_spoken_words(
self,
language_code: Optional[str] = None,
Expand Down