|
1 | 1 | import logging
|
2 | 2 |
|
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 |
10 | 4 | from videodb._upload import (
|
11 | 5 | upload,
|
12 | 6 | )
|
@@ -170,6 +164,134 @@ def delete_image(self, image_id: str) -> None:
|
170 | 164 | path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
|
171 | 165 | )
|
172 | 166 |
|
| 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 | + |
173 | 295 | def search(
|
174 | 296 | self,
|
175 | 297 | query: str,
|
|
0 commit comments