magic_hour 0.35.0__py3-none-any.whl → 0.36.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of magic_hour might be problematic. Click here for more details.
- magic_hour/README.md +35 -0
- magic_hour/core/base_client.py +6 -5
- magic_hour/core/query.py +12 -6
- magic_hour/core/request.py +3 -3
- magic_hour/core/response.py +18 -14
- magic_hour/core/utils.py +3 -3
- magic_hour/environment.py +1 -1
- magic_hour/helpers/__init__.py +3 -0
- magic_hour/helpers/download.py +75 -0
- magic_hour/resources/v1/README.md +33 -0
- magic_hour/resources/v1/ai_clothes_changer/README.md +73 -0
- magic_hour/resources/v1/ai_clothes_changer/client.py +146 -0
- magic_hour/resources/v1/ai_face_editor/README.md +110 -0
- magic_hour/resources/v1/ai_face_editor/client.py +168 -0
- magic_hour/resources/v1/ai_gif_generator/README.md +59 -0
- magic_hour/resources/v1/ai_gif_generator/client.py +119 -0
- magic_hour/resources/v1/ai_headshot_generator/README.md +60 -0
- magic_hour/resources/v1/ai_headshot_generator/client.py +140 -0
- magic_hour/resources/v1/ai_image_editor/README.md +64 -0
- magic_hour/resources/v1/ai_image_editor/client.py +136 -0
- magic_hour/resources/v1/ai_image_generator/README.md +66 -0
- magic_hour/resources/v1/ai_image_generator/client.py +139 -0
- magic_hour/resources/v1/ai_image_upscaler/README.md +67 -0
- magic_hour/resources/v1/ai_image_upscaler/client.py +150 -0
- magic_hour/resources/v1/ai_meme_generator/README.md +71 -0
- magic_hour/resources/v1/ai_meme_generator/client.py +127 -0
- magic_hour/resources/v1/ai_photo_editor/README.md +98 -7
- magic_hour/resources/v1/ai_photo_editor/client.py +174 -0
- magic_hour/resources/v1/ai_qr_code_generator/README.md +63 -0
- magic_hour/resources/v1/ai_qr_code_generator/client.py +123 -0
- magic_hour/resources/v1/ai_talking_photo/README.md +74 -0
- magic_hour/resources/v1/ai_talking_photo/client.py +170 -0
- magic_hour/resources/v1/animation/README.md +100 -0
- magic_hour/resources/v1/animation/client.py +218 -0
- magic_hour/resources/v1/auto_subtitle_generator/README.md +69 -0
- magic_hour/resources/v1/auto_subtitle_generator/client.py +178 -0
- magic_hour/resources/v1/face_detection/README.md +59 -0
- magic_hour/resources/v1/face_detection/__init__.py +10 -2
- magic_hour/resources/v1/face_detection/client.py +179 -0
- magic_hour/resources/v1/face_swap/README.md +105 -8
- magic_hour/resources/v1/face_swap/client.py +242 -0
- magic_hour/resources/v1/face_swap_photo/README.md +84 -0
- magic_hour/resources/v1/face_swap_photo/client.py +172 -0
- magic_hour/resources/v1/files/README.md +40 -0
- magic_hour/resources/v1/files/client.py +350 -0
- magic_hour/resources/v1/files/client_test.py +414 -0
- magic_hour/resources/v1/files/upload_urls/README.md +8 -0
- magic_hour/resources/v1/image_background_remover/README.md +68 -0
- magic_hour/resources/v1/image_background_remover/client.py +130 -0
- magic_hour/resources/v1/image_projects/README.md +52 -0
- magic_hour/resources/v1/image_projects/__init__.py +10 -2
- magic_hour/resources/v1/image_projects/client.py +138 -0
- magic_hour/resources/v1/image_projects/client_test.py +527 -0
- magic_hour/resources/v1/image_to_video/README.md +77 -9
- magic_hour/resources/v1/image_to_video/client.py +186 -0
- magic_hour/resources/v1/lip_sync/README.md +87 -9
- magic_hour/resources/v1/lip_sync/client.py +210 -0
- magic_hour/resources/v1/photo_colorizer/README.md +59 -0
- magic_hour/resources/v1/photo_colorizer/client.py +130 -0
- magic_hour/resources/v1/text_to_video/README.md +68 -0
- magic_hour/resources/v1/text_to_video/client.py +151 -0
- magic_hour/resources/v1/video_projects/README.md +52 -0
- magic_hour/resources/v1/video_projects/__init__.py +10 -2
- magic_hour/resources/v1/video_projects/client.py +137 -0
- magic_hour/resources/v1/video_projects/client_test.py +527 -0
- magic_hour/resources/v1/video_to_video/README.md +98 -10
- magic_hour/resources/v1/video_to_video/client.py +222 -0
- magic_hour/types/params/__init__.py +58 -0
- magic_hour/types/params/v1_ai_clothes_changer_generate_body_assets.py +33 -0
- magic_hour/types/params/v1_ai_face_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_headshot_generator_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_image_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_image_upscaler_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_photo_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_talking_photo_generate_body_assets.py +26 -0
- magic_hour/types/params/v1_animation_generate_body_assets.py +39 -0
- magic_hour/types/params/v1_auto_subtitle_generator_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_face_detection_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_face_swap_create_body.py +12 -0
- magic_hour/types/params/v1_face_swap_create_body_style.py +33 -0
- magic_hour/types/params/v1_face_swap_generate_body_assets.py +56 -0
- magic_hour/types/params/v1_face_swap_generate_body_assets_face_mappings_item.py +25 -0
- magic_hour/types/params/v1_face_swap_photo_generate_body_assets.py +47 -0
- magic_hour/types/params/v1_face_swap_photo_generate_body_assets_face_mappings_item.py +25 -0
- magic_hour/types/params/v1_image_background_remover_generate_body_assets.py +27 -0
- magic_hour/types/params/v1_image_to_video_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_lip_sync_generate_body_assets.py +36 -0
- magic_hour/types/params/v1_photo_colorizer_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_video_to_video_generate_body_assets.py +27 -0
- magic_hour-0.36.1.dist-info/METADATA +306 -0
- {magic_hour-0.35.0.dist-info → magic_hour-0.36.1.dist-info}/RECORD +93 -65
- magic_hour-0.35.0.dist-info/METADATA +0 -166
- {magic_hour-0.35.0.dist-info → magic_hour-0.36.1.dist-info}/LICENSE +0 -0
- {magic_hour-0.35.0.dist-info → magic_hour-0.36.1.dist-info}/WHEEL +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import typing
|
|
2
3
|
|
|
3
4
|
from magic_hour.core import (
|
|
@@ -8,13 +9,82 @@ from magic_hour.core import (
|
|
|
8
9
|
to_encodable,
|
|
9
10
|
type_utils,
|
|
10
11
|
)
|
|
12
|
+
from magic_hour.resources.v1.files.client import AsyncFilesClient, FilesClient
|
|
13
|
+
from magic_hour.resources.v1.image_projects.client import (
|
|
14
|
+
AsyncImageProjectsClient,
|
|
15
|
+
ImageProjectsClient,
|
|
16
|
+
)
|
|
11
17
|
from magic_hour.types import models, params
|
|
12
18
|
|
|
13
19
|
|
|
20
|
+
logging.basicConfig(level=logging.INFO)
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
14
24
|
class PhotoColorizerClient:
|
|
15
25
|
def __init__(self, *, base_client: SyncBaseClient):
|
|
16
26
|
self._base_client = base_client
|
|
17
27
|
|
|
28
|
+
def generate(
|
|
29
|
+
self,
|
|
30
|
+
*,
|
|
31
|
+
assets: params.V1PhotoColorizerGenerateBodyAssets,
|
|
32
|
+
name: typing.Union[
|
|
33
|
+
typing.Optional[str], type_utils.NotGiven
|
|
34
|
+
] = type_utils.NOT_GIVEN,
|
|
35
|
+
wait_for_completion: bool = True,
|
|
36
|
+
download_outputs: bool = True,
|
|
37
|
+
download_directory: typing.Optional[str] = None,
|
|
38
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
39
|
+
):
|
|
40
|
+
"""
|
|
41
|
+
Generate colorized photo (alias for create with additional functionality).
|
|
42
|
+
|
|
43
|
+
Colorize image. Each image costs 5 credits.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
47
|
+
assets: Provide the assets for photo colorization
|
|
48
|
+
wait_for_completion: Whether to wait for the image project to complete
|
|
49
|
+
download_outputs: Whether to download the outputs
|
|
50
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
51
|
+
request_options: Additional options to customize the HTTP request
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
V1ImageProjectsGetResponseWithDownloads: The response from the Photo Colorizer API with the downloaded paths if `download_outputs` is True.
|
|
55
|
+
|
|
56
|
+
Examples:
|
|
57
|
+
```py
|
|
58
|
+
response = client.v1.photo_colorizer.generate(
|
|
59
|
+
assets={"image_file_path": "path/to/black_white_photo.jpg"},
|
|
60
|
+
name="Colorized Photo",
|
|
61
|
+
wait_for_completion=True,
|
|
62
|
+
download_outputs=True,
|
|
63
|
+
download_directory="outputs/",
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
file_client = FilesClient(base_client=self._base_client)
|
|
69
|
+
|
|
70
|
+
image_file_path = assets["image_file_path"]
|
|
71
|
+
assets["image_file_path"] = file_client.upload_file(file=image_file_path)
|
|
72
|
+
|
|
73
|
+
create_response = self.create(
|
|
74
|
+
assets=assets, name=name, request_options=request_options
|
|
75
|
+
)
|
|
76
|
+
logger.info(f"Photo Colorizer response: {create_response}")
|
|
77
|
+
|
|
78
|
+
image_projects_client = ImageProjectsClient(base_client=self._base_client)
|
|
79
|
+
response = image_projects_client.check_result(
|
|
80
|
+
id=create_response.id,
|
|
81
|
+
wait_for_completion=wait_for_completion,
|
|
82
|
+
download_outputs=download_outputs,
|
|
83
|
+
download_directory=download_directory,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
return response
|
|
87
|
+
|
|
18
88
|
def create(
|
|
19
89
|
self,
|
|
20
90
|
*,
|
|
@@ -69,6 +139,66 @@ class AsyncPhotoColorizerClient:
|
|
|
69
139
|
def __init__(self, *, base_client: AsyncBaseClient):
|
|
70
140
|
self._base_client = base_client
|
|
71
141
|
|
|
142
|
+
async def generate(
|
|
143
|
+
self,
|
|
144
|
+
*,
|
|
145
|
+
assets: params.V1PhotoColorizerGenerateBodyAssets,
|
|
146
|
+
name: typing.Union[
|
|
147
|
+
typing.Optional[str], type_utils.NotGiven
|
|
148
|
+
] = type_utils.NOT_GIVEN,
|
|
149
|
+
wait_for_completion: bool = True,
|
|
150
|
+
download_outputs: bool = True,
|
|
151
|
+
download_directory: typing.Optional[str] = None,
|
|
152
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
153
|
+
):
|
|
154
|
+
"""
|
|
155
|
+
Generate colorized photo (alias for create with additional functionality).
|
|
156
|
+
|
|
157
|
+
Colorize image. Each image costs 5 credits.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
161
|
+
assets: Provide the assets for photo colorization
|
|
162
|
+
wait_for_completion: Whether to wait for the image project to complete
|
|
163
|
+
download_outputs: Whether to download the outputs
|
|
164
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
165
|
+
request_options: Additional options to customize the HTTP request
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
V1ImageProjectsGetResponseWithDownloads: The response from the Photo Colorizer API with the downloaded paths if `download_outputs` is True.
|
|
169
|
+
|
|
170
|
+
Examples:
|
|
171
|
+
```py
|
|
172
|
+
response = await client.v1.photo_colorizer.generate(
|
|
173
|
+
assets={"image_file_path": "path/to/black_white_photo.jpg"},
|
|
174
|
+
name="Colorized Photo",
|
|
175
|
+
wait_for_completion=True,
|
|
176
|
+
download_outputs=True,
|
|
177
|
+
download_directory="outputs/",
|
|
178
|
+
)
|
|
179
|
+
```
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
file_client = AsyncFilesClient(base_client=self._base_client)
|
|
183
|
+
|
|
184
|
+
image_file_path = assets["image_file_path"]
|
|
185
|
+
assets["image_file_path"] = await file_client.upload_file(file=image_file_path)
|
|
186
|
+
|
|
187
|
+
create_response = await self.create(
|
|
188
|
+
assets=assets, name=name, request_options=request_options
|
|
189
|
+
)
|
|
190
|
+
logger.info(f"Photo Colorizer response: {create_response}")
|
|
191
|
+
|
|
192
|
+
image_projects_client = AsyncImageProjectsClient(base_client=self._base_client)
|
|
193
|
+
response = await image_projects_client.check_result(
|
|
194
|
+
id=create_response.id,
|
|
195
|
+
wait_for_completion=wait_for_completion,
|
|
196
|
+
download_outputs=download_outputs,
|
|
197
|
+
download_directory=download_directory,
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
return response
|
|
201
|
+
|
|
72
202
|
async def create(
|
|
73
203
|
self,
|
|
74
204
|
*,
|
|
@@ -1,3 +1,68 @@
|
|
|
1
|
+
# v1_text_to_video
|
|
2
|
+
|
|
3
|
+
## Module Functions
|
|
4
|
+
|
|
5
|
+
<!-- CUSTOM DOCS START -->
|
|
6
|
+
|
|
7
|
+
### Text To Video Generate Workflow <a name="generate"></a>
|
|
8
|
+
|
|
9
|
+
The workflow performs the following action
|
|
10
|
+
|
|
11
|
+
1. upload local assets to Magic Hour storage. So you can pass in a local path instead of having to upload files yourself
|
|
12
|
+
2. trigger a generation
|
|
13
|
+
3. poll for a completion status. This is configurable
|
|
14
|
+
4. if success, download the output to local directory
|
|
15
|
+
|
|
16
|
+
> [!TIP]
|
|
17
|
+
> This is the recommended way to use the SDK unless you have specific needs where it is necessary to split up the actions.
|
|
18
|
+
|
|
19
|
+
#### Parameters
|
|
20
|
+
|
|
21
|
+
In Additional to the parameters listed in the `.create` section below, `.generate` introduces 3 new parameters:
|
|
22
|
+
|
|
23
|
+
- `wait_for_completion` (bool, default True): Whether to wait for the project to complete.
|
|
24
|
+
- `download_outputs` (bool, default True): Whether to download the generated files
|
|
25
|
+
- `download_directory` (str, optional): Directory to save downloaded files (defaults to current directory)
|
|
26
|
+
|
|
27
|
+
#### Synchronous Client
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from magic_hour import Client
|
|
31
|
+
from os import getenv
|
|
32
|
+
|
|
33
|
+
client = Client(token=getenv("API_TOKEN"))
|
|
34
|
+
res = client.v1.text_to_video.generate(
|
|
35
|
+
end_seconds=5.0,
|
|
36
|
+
orientation="landscape",
|
|
37
|
+
style={"prompt": "a dog running"},
|
|
38
|
+
name="Text To Video video",
|
|
39
|
+
resolution="720p",
|
|
40
|
+
wait_for_completion=True,
|
|
41
|
+
download_outputs=True,
|
|
42
|
+
download_directory="outputs"
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Asynchronous Client
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from magic_hour import AsyncClient
|
|
50
|
+
from os import getenv
|
|
51
|
+
|
|
52
|
+
client = AsyncClient(token=getenv("API_TOKEN"))
|
|
53
|
+
res = await client.v1.text_to_video.generate(
|
|
54
|
+
end_seconds=5.0,
|
|
55
|
+
orientation="landscape",
|
|
56
|
+
style={"prompt": "a dog running"},
|
|
57
|
+
name="Text To Video video",
|
|
58
|
+
resolution="720p",
|
|
59
|
+
wait_for_completion=True,
|
|
60
|
+
download_outputs=True,
|
|
61
|
+
download_directory="outputs"
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
<!-- CUSTOM DOCS END -->
|
|
1
66
|
|
|
2
67
|
### Text-to-Video <a name="create"></a>
|
|
3
68
|
|
|
@@ -15,6 +80,8 @@ Get more information about this mode at our [product page](https://magichour.ai/
|
|
|
15
80
|
| `end_seconds` | ✓ | The total duration of the output video in seconds. The value must be greater than or equal to 5 seconds and less than or equal to 60 seconds. Note: For 480p resolution, the value must be either 5 or 10. | `5.0` |
|
|
16
81
|
| `orientation` | ✓ | Determines the orientation of the output video | `"landscape"` |
|
|
17
82
|
| `style` | ✓ | | `{"prompt": "a dog running"}` |
|
|
83
|
+
| `└─ prompt` | ✓ | The prompt used for the video. | `"a dog running"` |
|
|
84
|
+
| `└─ quality_mode` | ✗ | DEPRECATED: Please use `resolution` field instead. For backward compatibility: * `quick` maps to 720p resolution * `studio` maps to 1080p resolution This field will be removed in a future version. Use the `resolution` field to directly to specify the resolution. | `"quick"` |
|
|
18
85
|
| `name` | ✗ | The name of video. This value is mainly used for your own identification of the video. | `"Text To Video video"` |
|
|
19
86
|
| `resolution` | ✗ | Controls the output video resolution. Defaults to `720p` if not specified. 480p and 720p are available on Creator, Pro, or Business tiers. However, 1080p require Pro or Business tier. **Options:** - `480p` - Supports only 5 or 10 second videos. Output: 24fps. Cost: 120 credits per 5 seconds. - `720p` - Supports videos between 5-60 seconds. Output: 30fps. Cost: 300 credits per 5 seconds. - `1080p` - Supports videos between 5-60 seconds. Output: 30fps. Cost: 600 credits per 5 seconds. | `"720p"` |
|
|
20
87
|
|
|
@@ -59,3 +126,4 @@ res = await client.v1.text_to_video.create(
|
|
|
59
126
|
|
|
60
127
|
##### Example
|
|
61
128
|
`{"credits_charged": 450, "estimated_frame_cost": 450, "id": "cuid-example"}`
|
|
129
|
+
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import typing
|
|
2
3
|
import typing_extensions
|
|
3
4
|
|
|
@@ -9,13 +10,92 @@ from magic_hour.core import (
|
|
|
9
10
|
to_encodable,
|
|
10
11
|
type_utils,
|
|
11
12
|
)
|
|
13
|
+
from magic_hour.resources.v1.video_projects.client import (
|
|
14
|
+
AsyncVideoProjectsClient,
|
|
15
|
+
VideoProjectsClient,
|
|
16
|
+
)
|
|
12
17
|
from magic_hour.types import models, params
|
|
13
18
|
|
|
14
19
|
|
|
20
|
+
logging.basicConfig(level=logging.INFO)
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
15
24
|
class TextToVideoClient:
|
|
16
25
|
def __init__(self, *, base_client: SyncBaseClient):
|
|
17
26
|
self._base_client = base_client
|
|
18
27
|
|
|
28
|
+
def generate(
|
|
29
|
+
self,
|
|
30
|
+
*,
|
|
31
|
+
end_seconds: float,
|
|
32
|
+
orientation: typing_extensions.Literal["landscape", "portrait", "square"],
|
|
33
|
+
style: params.V1TextToVideoCreateBodyStyle,
|
|
34
|
+
name: typing.Union[
|
|
35
|
+
typing.Optional[str], type_utils.NotGiven
|
|
36
|
+
] = type_utils.NOT_GIVEN,
|
|
37
|
+
resolution: typing.Union[
|
|
38
|
+
typing.Optional[typing_extensions.Literal["1080p", "480p", "720p"]],
|
|
39
|
+
type_utils.NotGiven,
|
|
40
|
+
] = type_utils.NOT_GIVEN,
|
|
41
|
+
wait_for_completion: bool = True,
|
|
42
|
+
download_outputs: bool = True,
|
|
43
|
+
download_directory: typing.Optional[str] = None,
|
|
44
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
45
|
+
):
|
|
46
|
+
"""
|
|
47
|
+
Generate text-to-video (alias for create with additional functionality).
|
|
48
|
+
|
|
49
|
+
Create a Text To Video video. The estimated frame cost is calculated using 30 FPS. This amount is deducted from your account balance when a video is queued. Once the video is complete, the cost will be updated based on the actual number of frames rendered.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
name: The name of video. This value is mainly used for your own identification of the video.
|
|
53
|
+
resolution: Controls the output video resolution. Defaults to `720p` if not specified.
|
|
54
|
+
end_seconds: The total duration of the output video in seconds.
|
|
55
|
+
orientation: Determines the orientation of the output video
|
|
56
|
+
style: V1TextToVideoCreateBodyStyle
|
|
57
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
58
|
+
download_outputs: Whether to download the outputs
|
|
59
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
60
|
+
request_options: Additional options to customize the HTTP request
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
V1VideoProjectsGetResponseWithDownloads: The response from the Text-to-Video API with the downloaded paths if `download_outputs` is True.
|
|
64
|
+
|
|
65
|
+
Examples:
|
|
66
|
+
```py
|
|
67
|
+
response = client.v1.text_to_video.generate(
|
|
68
|
+
end_seconds=5.0,
|
|
69
|
+
orientation="landscape",
|
|
70
|
+
style={"prompt": "a dog running through a meadow"},
|
|
71
|
+
resolution="720p",
|
|
72
|
+
wait_for_completion=True,
|
|
73
|
+
download_outputs=True,
|
|
74
|
+
download_directory="outputs/",
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
create_response = self.create(
|
|
80
|
+
end_seconds=end_seconds,
|
|
81
|
+
orientation=orientation,
|
|
82
|
+
style=style,
|
|
83
|
+
name=name,
|
|
84
|
+
resolution=resolution,
|
|
85
|
+
request_options=request_options,
|
|
86
|
+
)
|
|
87
|
+
logger.info(f"Text-to-Video response: {create_response}")
|
|
88
|
+
|
|
89
|
+
video_projects_client = VideoProjectsClient(base_client=self._base_client)
|
|
90
|
+
response = video_projects_client.check_result(
|
|
91
|
+
id=create_response.id,
|
|
92
|
+
wait_for_completion=wait_for_completion,
|
|
93
|
+
download_outputs=download_outputs,
|
|
94
|
+
download_directory=download_directory,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
return response
|
|
98
|
+
|
|
19
99
|
def create(
|
|
20
100
|
self,
|
|
21
101
|
*,
|
|
@@ -102,6 +182,77 @@ class AsyncTextToVideoClient:
|
|
|
102
182
|
def __init__(self, *, base_client: AsyncBaseClient):
|
|
103
183
|
self._base_client = base_client
|
|
104
184
|
|
|
185
|
+
async def generate(
|
|
186
|
+
self,
|
|
187
|
+
*,
|
|
188
|
+
end_seconds: float,
|
|
189
|
+
orientation: typing_extensions.Literal["landscape", "portrait", "square"],
|
|
190
|
+
style: params.V1TextToVideoCreateBodyStyle,
|
|
191
|
+
name: typing.Union[
|
|
192
|
+
typing.Optional[str], type_utils.NotGiven
|
|
193
|
+
] = type_utils.NOT_GIVEN,
|
|
194
|
+
resolution: typing.Union[
|
|
195
|
+
typing.Optional[typing_extensions.Literal["1080p", "480p", "720p"]],
|
|
196
|
+
type_utils.NotGiven,
|
|
197
|
+
] = type_utils.NOT_GIVEN,
|
|
198
|
+
wait_for_completion: bool = True,
|
|
199
|
+
download_outputs: bool = True,
|
|
200
|
+
download_directory: typing.Optional[str] = None,
|
|
201
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
202
|
+
):
|
|
203
|
+
"""
|
|
204
|
+
Generate text-to-video (alias for create with additional functionality).
|
|
205
|
+
|
|
206
|
+
Create a Text To Video video. The estimated frame cost is calculated using 30 FPS. This amount is deducted from your account balance when a video is queued. Once the video is complete, the cost will be updated based on the actual number of frames rendered.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
name: The name of video. This value is mainly used for your own identification of the video.
|
|
210
|
+
resolution: Controls the output video resolution. Defaults to `720p` if not specified.
|
|
211
|
+
end_seconds: The total duration of the output video in seconds.
|
|
212
|
+
orientation: Determines the orientation of the output video
|
|
213
|
+
style: V1TextToVideoCreateBodyStyle
|
|
214
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
215
|
+
download_outputs: Whether to download the outputs
|
|
216
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
217
|
+
request_options: Additional options to customize the HTTP request
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
V1VideoProjectsGetResponseWithDownloads: The response from the Text-to-Video API with the downloaded paths if `download_outputs` is True.
|
|
221
|
+
|
|
222
|
+
Examples:
|
|
223
|
+
```py
|
|
224
|
+
response = await client.v1.text_to_video.generate(
|
|
225
|
+
end_seconds=5.0,
|
|
226
|
+
orientation="landscape",
|
|
227
|
+
style={"prompt": "a dog running through a meadow"},
|
|
228
|
+
resolution="720p",
|
|
229
|
+
wait_for_completion=True,
|
|
230
|
+
download_outputs=True,
|
|
231
|
+
download_directory="outputs/",
|
|
232
|
+
)
|
|
233
|
+
```
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
create_response = await self.create(
|
|
237
|
+
end_seconds=end_seconds,
|
|
238
|
+
orientation=orientation,
|
|
239
|
+
style=style,
|
|
240
|
+
name=name,
|
|
241
|
+
resolution=resolution,
|
|
242
|
+
request_options=request_options,
|
|
243
|
+
)
|
|
244
|
+
logger.info(f"Text-to-Video response: {create_response}")
|
|
245
|
+
|
|
246
|
+
video_projects_client = AsyncVideoProjectsClient(base_client=self._base_client)
|
|
247
|
+
response = await video_projects_client.check_result(
|
|
248
|
+
id=create_response.id,
|
|
249
|
+
wait_for_completion=wait_for_completion,
|
|
250
|
+
download_outputs=download_outputs,
|
|
251
|
+
download_directory=download_directory,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
return response
|
|
255
|
+
|
|
105
256
|
async def create(
|
|
106
257
|
self,
|
|
107
258
|
*,
|
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
# v1_video_projects
|
|
2
|
+
|
|
3
|
+
## Module Functions
|
|
4
|
+
|
|
5
|
+
<!-- CUSTOM DOCS START -->
|
|
6
|
+
|
|
7
|
+
### Check results <a name="check-result"></a>
|
|
8
|
+
|
|
9
|
+
Poll the details API to check on the status of the rendering. Optionally can also download the output
|
|
10
|
+
|
|
11
|
+
#### Parameters
|
|
12
|
+
|
|
13
|
+
| Parameter | Required | Description | Example |
|
|
14
|
+
| --------------------- | :------: | ---------------------------------------------------------------------------------------------------- | ---------------- |
|
|
15
|
+
| `id` | ✓ | Unique ID of the video project. This value is returned by all of the POST APIs that create an video. | `"cuid-example"` |
|
|
16
|
+
| `wait_for_completion` | ✗ | Whether to wait for the project to complete. | `True` |
|
|
17
|
+
| `download_outputs` | ✗ | Whether to download the generated files | `True` |
|
|
18
|
+
| `download_directory` | ✗ | Directory to save downloaded files (defaults to current directory) | `"./outputs"` |
|
|
19
|
+
|
|
20
|
+
#### Synchronous Client
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from magic_hour import Client
|
|
24
|
+
from os import getenv
|
|
25
|
+
|
|
26
|
+
client = Client(token=getenv("API_TOKEN"))
|
|
27
|
+
res = client.v1.video_projects.check_result(
|
|
28
|
+
id="cuid-example",
|
|
29
|
+
wait_for_completion=True,
|
|
30
|
+
download_outputs=True,
|
|
31
|
+
download_directory="outputs",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Asynchronous Client
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from magic_hour import AsyncClient
|
|
40
|
+
from os import getenv
|
|
41
|
+
|
|
42
|
+
client = AsyncClient(token=getenv("API_TOKEN"))
|
|
43
|
+
res = await client.v1.video_projects.check_result(
|
|
44
|
+
id="cuid-example",
|
|
45
|
+
wait_for_completion=True,
|
|
46
|
+
download_outputs=True,
|
|
47
|
+
download_directory="outputs",
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
<!-- CUSTOM DOCS END -->
|
|
1
52
|
|
|
2
53
|
### Delete video <a name="delete"></a>
|
|
3
54
|
|
|
@@ -83,3 +134,4 @@ res = await client.v1.video_projects.get(id="cuid-example")
|
|
|
83
134
|
|
|
84
135
|
##### Example
|
|
85
136
|
`{"created_at": "1970-01-01T00:00:00", "credits_charged": 450, "download": {"expires_at": "2024-10-19T05:16:19.027Z", "url": "https://videos.magichour.ai/id/output.mp4"}, "downloads": [{"expires_at": "2024-10-19T05:16:19.027Z", "url": "https://videos.magichour.ai/id/output.mp4"}], "enabled": True, "end_seconds": 15.0, "error": {"code": "no_source_face", "message": "Please use an image with a detectable face"}, "fps": 30.0, "height": 960, "id": "cuid-example", "name": "Example Name", "start_seconds": 0.0, "status": "complete", "total_frame_cost": 450, "type_": "FACE_SWAP", "width": 512}`
|
|
137
|
+
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
from .client import
|
|
1
|
+
from .client import (
|
|
2
|
+
AsyncVideoProjectsClient,
|
|
3
|
+
V1VideoProjectsGetResponseWithDownloads,
|
|
4
|
+
VideoProjectsClient,
|
|
5
|
+
)
|
|
2
6
|
|
|
3
7
|
|
|
4
|
-
__all__ = [
|
|
8
|
+
__all__ = [
|
|
9
|
+
"AsyncVideoProjectsClient",
|
|
10
|
+
"V1VideoProjectsGetResponseWithDownloads",
|
|
11
|
+
"VideoProjectsClient",
|
|
12
|
+
]
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import pydantic
|
|
4
|
+
import time
|
|
1
5
|
import typing
|
|
2
6
|
|
|
3
7
|
from magic_hour.core import (
|
|
@@ -6,13 +10,87 @@ from magic_hour.core import (
|
|
|
6
10
|
SyncBaseClient,
|
|
7
11
|
default_request_options,
|
|
8
12
|
)
|
|
13
|
+
from magic_hour.helpers.download import download_files_async, download_files_sync
|
|
9
14
|
from magic_hour.types import models
|
|
10
15
|
|
|
11
16
|
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class V1VideoProjectsGetResponseWithDownloads(models.V1VideoProjectsGetResponse):
|
|
21
|
+
downloaded_paths: typing.Optional[typing.List[str]] = pydantic.Field(
|
|
22
|
+
default=None, alias="downloaded_paths"
|
|
23
|
+
)
|
|
24
|
+
"""
|
|
25
|
+
The paths to the downloaded files.
|
|
26
|
+
|
|
27
|
+
This field is only populated if `download_outputs` is True and the video project is complete.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
12
31
|
class VideoProjectsClient:
|
|
13
32
|
def __init__(self, *, base_client: SyncBaseClient):
|
|
14
33
|
self._base_client = base_client
|
|
15
34
|
|
|
35
|
+
def check_result(
|
|
36
|
+
self,
|
|
37
|
+
id: str,
|
|
38
|
+
wait_for_completion: bool,
|
|
39
|
+
download_outputs: bool,
|
|
40
|
+
download_directory: typing.Optional[str] = None,
|
|
41
|
+
) -> V1VideoProjectsGetResponseWithDownloads:
|
|
42
|
+
"""
|
|
43
|
+
Check the result of a video project with optional waiting and downloading.
|
|
44
|
+
|
|
45
|
+
This method retrieves the status of a video project and optionally waits for completion
|
|
46
|
+
and downloads the output files.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
id: Unique ID of the video project
|
|
50
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
51
|
+
download_outputs: Whether to download the outputs
|
|
52
|
+
download_directory: The directory to download the outputs to. If not provided,
|
|
53
|
+
the outputs will be downloaded to the current working directory
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
V1VideoProjectsGetResponseWithDownloads: The video project response with optional
|
|
57
|
+
downloaded file paths included
|
|
58
|
+
"""
|
|
59
|
+
api_response = self.get(id=id)
|
|
60
|
+
if not wait_for_completion:
|
|
61
|
+
response = V1VideoProjectsGetResponseWithDownloads(
|
|
62
|
+
**api_response.model_dump()
|
|
63
|
+
)
|
|
64
|
+
return response
|
|
65
|
+
|
|
66
|
+
poll_interval = float(os.getenv("MAGIC_HOUR_POLL_INTERVAL", "0.5"))
|
|
67
|
+
|
|
68
|
+
status = api_response.status
|
|
69
|
+
|
|
70
|
+
while status not in ["complete", "error", "canceled"]:
|
|
71
|
+
api_response = self.get(id=id)
|
|
72
|
+
status = api_response.status
|
|
73
|
+
time.sleep(poll_interval)
|
|
74
|
+
|
|
75
|
+
if api_response.status != "complete":
|
|
76
|
+
log = logger.error if api_response.status == "error" else logger.info
|
|
77
|
+
log(
|
|
78
|
+
f"Video project {id} has status {api_response.status}: {api_response.error}"
|
|
79
|
+
)
|
|
80
|
+
return V1VideoProjectsGetResponseWithDownloads(**api_response.model_dump())
|
|
81
|
+
|
|
82
|
+
if not download_outputs:
|
|
83
|
+
return V1VideoProjectsGetResponseWithDownloads(**api_response.model_dump())
|
|
84
|
+
|
|
85
|
+
downloaded_paths = download_files_sync(
|
|
86
|
+
downloads=api_response.downloads,
|
|
87
|
+
download_directory=download_directory,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return V1VideoProjectsGetResponseWithDownloads(
|
|
91
|
+
**api_response.model_dump(), downloaded_paths=downloaded_paths
|
|
92
|
+
)
|
|
93
|
+
|
|
16
94
|
def delete(
|
|
17
95
|
self, *, id: str, request_options: typing.Optional[RequestOptions] = None
|
|
18
96
|
) -> None:
|
|
@@ -95,6 +173,65 @@ class AsyncVideoProjectsClient:
|
|
|
95
173
|
def __init__(self, *, base_client: AsyncBaseClient):
|
|
96
174
|
self._base_client = base_client
|
|
97
175
|
|
|
176
|
+
async def check_result(
|
|
177
|
+
self,
|
|
178
|
+
id: str,
|
|
179
|
+
wait_for_completion: bool,
|
|
180
|
+
download_outputs: bool,
|
|
181
|
+
download_directory: typing.Optional[str] = None,
|
|
182
|
+
) -> V1VideoProjectsGetResponseWithDownloads:
|
|
183
|
+
"""
|
|
184
|
+
Check the result of a video project with optional waiting and downloading.
|
|
185
|
+
|
|
186
|
+
This method retrieves the status of a video project and optionally waits for completion
|
|
187
|
+
and downloads the output files.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
id: Unique ID of the video project
|
|
191
|
+
wait_for_completion: Whether to wait for the video project to complete
|
|
192
|
+
download_outputs: Whether to download the outputs
|
|
193
|
+
download_directory: The directory to download the outputs to. If not provided,
|
|
194
|
+
the outputs will be downloaded to the current working directory
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
V1VideoProjectsGetResponseWithDownloads: The video project response with optional
|
|
198
|
+
downloaded file paths included
|
|
199
|
+
"""
|
|
200
|
+
api_response = await self.get(id=id)
|
|
201
|
+
if not wait_for_completion:
|
|
202
|
+
response = V1VideoProjectsGetResponseWithDownloads(
|
|
203
|
+
**api_response.model_dump()
|
|
204
|
+
)
|
|
205
|
+
return response
|
|
206
|
+
|
|
207
|
+
poll_interval = float(os.getenv("MAGIC_HOUR_POLL_INTERVAL", "0.5"))
|
|
208
|
+
|
|
209
|
+
status = api_response.status
|
|
210
|
+
|
|
211
|
+
while status not in ["complete", "error", "canceled"]:
|
|
212
|
+
api_response = await self.get(id=id)
|
|
213
|
+
status = api_response.status
|
|
214
|
+
time.sleep(poll_interval)
|
|
215
|
+
|
|
216
|
+
if api_response.status != "complete":
|
|
217
|
+
log = logger.error if api_response.status == "error" else logger.info
|
|
218
|
+
log(
|
|
219
|
+
f"Video project {id} has status {api_response.status}: {api_response.error}"
|
|
220
|
+
)
|
|
221
|
+
return V1VideoProjectsGetResponseWithDownloads(**api_response.model_dump())
|
|
222
|
+
|
|
223
|
+
if not download_outputs:
|
|
224
|
+
return V1VideoProjectsGetResponseWithDownloads(**api_response.model_dump())
|
|
225
|
+
|
|
226
|
+
downloaded_paths = await download_files_async(
|
|
227
|
+
downloads=api_response.downloads,
|
|
228
|
+
download_directory=download_directory,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
return V1VideoProjectsGetResponseWithDownloads(
|
|
232
|
+
**api_response.model_dump(), downloaded_paths=downloaded_paths
|
|
233
|
+
)
|
|
234
|
+
|
|
98
235
|
async def delete(
|
|
99
236
|
self, *, id: str, request_options: typing.Optional[RequestOptions] = None
|
|
100
237
|
) -> None:
|