From 488c485858c1df25646658cc83d5eca58ac5eb35 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Mon, 24 Mar 2025 09:16:42 +0530 Subject: [PATCH 1/9] feat: add genai tools --- videodb/collection.py | 46 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/videodb/collection.py b/videodb/collection.py index 756ab5d..34e8956 100644 --- a/videodb/collection.py +++ b/videodb/collection.py @@ -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, ) @@ -170,6 +164,44 @@ def delete_image(self, image_id: str) -> None: path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id} ) + def youtube_search( + self, query: str, result_threshold: Optional[int] = 10 + ) -> 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) + :return: List of YouTube search results + :rtype: List[dict] + """ + search_data = self._connection.post( + path=f"{ApiPath.collection}/{self.id}/{ApiPath.search}/{ApiPath.web}", + data={ + "query": query, + "result_threshold": result_threshold, + "platform": "youtube", + }, + ) + print(search_data) + return search_data.get("results") + + def generate_image( + self, + prompt: str, + aspect_ratio: Optional[Literal["1:1", "9:16", "16:9", "4:3", "3:4"]] = "1:1", + ) -> Image: + """Generate an image from a prompt. + + :param str prompt: Prompt for the image generation + :return: :class:`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}, + ) + return Image(self._connection, **image_data) + def search( self, query: str, From 6de6eee5c87e439109ad1b3a4836114213b82669 Mon Sep 17 00:00:00 2001 From: Ankit raj <113342181+ankit-v2-3@users.noreply.github.com> Date: Mon, 24 Mar 2025 10:28:18 +0530 Subject: [PATCH 2/9] feat: add audio gen --- videodb/_constants.py | 4 +++ videodb/collection.py | 63 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/videodb/_constants.py b/videodb/_constants.py index 173c825..b155752 100644 --- a/videodb/_constants.py +++ b/videodb/_constants.py @@ -72,6 +72,10 @@ class ApiPath: download = "download" title = "title" generate_url = "generate_url" + generate = "generate" + web = "web" + translate = "translate" + dub = "dub" class Status: diff --git a/videodb/collection.py b/videodb/collection.py index 34e8956..4a8b179 100644 --- a/videodb/collection.py +++ b/videodb/collection.py @@ -182,9 +182,22 @@ def youtube_search( "platform": "youtube", }, ) - print(search_data) return search_data.get("results") + def translate_video(self, video_id: str, language_code: str) -> List[dict]: + """Translate subtitles of a video to a language. + + :param str video_id: ID of the video + :param str language_code: Language code to translate the subtitles to + :return: List of translated subtitles + :rtype: List[dict] + """ + translate_data = self._connection.post( + path=f"{ApiPath.collection}/{self.id}/{ApiPath.video}/{video_id}/{ApiPath.translate}", + data={"language_code": language_code}, + ) + return translate_data.get("translated_text") + def generate_image( self, prompt: str, @@ -202,6 +215,54 @@ def generate_image( ) return Image(self._connection, **image_data) + def generate_music(self, prompt: str, duration: int = 5) -> Audio: + """Generate music from a prompt. + + :param str prompt: Prompt for the music generation + :param int duration: Duration of the music in seconds + :return: :class:`Audio