magic_hour 0.9.5__py3-none-any.whl → 0.44.0__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.
- magic_hour/README.md +34 -0
- magic_hour/__init__.py +1 -1
- magic_hour/client.py +8 -17
- magic_hour/environment.py +13 -1
- magic_hour/helpers/__init__.py +4 -0
- magic_hour/helpers/download.py +77 -0
- magic_hour/helpers/logger.py +8 -0
- magic_hour/resources/v1/README.md +32 -0
- magic_hour/resources/v1/ai_clothes_changer/README.md +94 -5
- magic_hour/resources/v1/ai_clothes_changer/client.py +161 -16
- magic_hour/resources/v1/ai_face_editor/README.md +195 -0
- magic_hour/resources/v1/ai_face_editor/__init__.py +4 -0
- magic_hour/resources/v1/ai_face_editor/client.py +324 -0
- magic_hour/resources/v1/ai_gif_generator/README.md +116 -0
- magic_hour/resources/v1/ai_gif_generator/__init__.py +4 -0
- magic_hour/resources/v1/ai_gif_generator/client.py +257 -0
- magic_hour/resources/v1/ai_headshot_generator/README.md +81 -3
- magic_hour/resources/v1/ai_headshot_generator/client.py +167 -18
- magic_hour/resources/v1/ai_image_editor/README.md +125 -0
- magic_hour/resources/v1/ai_image_editor/__init__.py +4 -0
- magic_hour/resources/v1/ai_image_editor/client.py +290 -0
- magic_hour/resources/v1/ai_image_generator/README.md +99 -5
- magic_hour/resources/v1/ai_image_generator/client.py +170 -24
- magic_hour/resources/v1/ai_image_upscaler/README.md +89 -3
- magic_hour/resources/v1/ai_image_upscaler/client.py +173 -20
- magic_hour/resources/v1/ai_meme_generator/README.md +129 -0
- magic_hour/resources/v1/ai_meme_generator/__init__.py +4 -0
- magic_hour/resources/v1/ai_meme_generator/client.py +253 -0
- magic_hour/resources/v1/ai_photo_editor/README.md +119 -4
- magic_hour/resources/v1/ai_photo_editor/client.py +199 -18
- magic_hour/resources/v1/ai_qr_code_generator/README.md +84 -3
- magic_hour/resources/v1/ai_qr_code_generator/client.py +140 -18
- magic_hour/resources/v1/ai_talking_photo/README.md +137 -0
- magic_hour/resources/v1/ai_talking_photo/__init__.py +4 -0
- magic_hour/resources/v1/ai_talking_photo/client.py +326 -0
- magic_hour/resources/v1/ai_voice_cloner/README.md +62 -0
- magic_hour/resources/v1/ai_voice_cloner/__init__.py +4 -0
- magic_hour/resources/v1/ai_voice_cloner/client.py +272 -0
- magic_hour/resources/v1/ai_voice_generator/README.md +112 -0
- magic_hour/resources/v1/ai_voice_generator/__init__.py +4 -0
- magic_hour/resources/v1/ai_voice_generator/client.py +241 -0
- magic_hour/resources/v1/animation/README.md +128 -6
- magic_hour/resources/v1/animation/client.py +247 -22
- magic_hour/resources/v1/audio_projects/README.md +135 -0
- magic_hour/resources/v1/audio_projects/__init__.py +12 -0
- magic_hour/resources/v1/audio_projects/client.py +310 -0
- magic_hour/resources/v1/audio_projects/client_test.py +520 -0
- magic_hour/resources/v1/auto_subtitle_generator/README.md +128 -0
- magic_hour/resources/v1/auto_subtitle_generator/__init__.py +4 -0
- magic_hour/resources/v1/auto_subtitle_generator/client.py +346 -0
- magic_hour/resources/v1/client.py +75 -1
- magic_hour/resources/v1/face_detection/README.md +157 -0
- magic_hour/resources/v1/face_detection/__init__.py +12 -0
- magic_hour/resources/v1/face_detection/client.py +380 -0
- magic_hour/resources/v1/face_swap/README.md +137 -9
- magic_hour/resources/v1/face_swap/client.py +329 -38
- magic_hour/resources/v1/face_swap_photo/README.md +118 -3
- magic_hour/resources/v1/face_swap_photo/client.py +199 -14
- magic_hour/resources/v1/files/README.md +39 -0
- magic_hour/resources/v1/files/client.py +351 -1
- magic_hour/resources/v1/files/client_test.py +414 -0
- magic_hour/resources/v1/files/upload_urls/README.md +38 -17
- magic_hour/resources/v1/files/upload_urls/client.py +38 -34
- magic_hour/resources/v1/image_background_remover/README.md +96 -5
- magic_hour/resources/v1/image_background_remover/client.py +151 -16
- magic_hour/resources/v1/image_projects/README.md +82 -10
- magic_hour/resources/v1/image_projects/__init__.py +10 -2
- magic_hour/resources/v1/image_projects/client.py +154 -16
- magic_hour/resources/v1/image_projects/client_test.py +527 -0
- magic_hour/resources/v1/image_to_video/README.md +96 -11
- magic_hour/resources/v1/image_to_video/client.py +282 -38
- magic_hour/resources/v1/lip_sync/README.md +112 -9
- magic_hour/resources/v1/lip_sync/client.py +288 -34
- magic_hour/resources/v1/photo_colorizer/README.md +107 -0
- magic_hour/resources/v1/photo_colorizer/__init__.py +4 -0
- magic_hour/resources/v1/photo_colorizer/client.py +248 -0
- magic_hour/resources/v1/text_to_video/README.md +96 -7
- magic_hour/resources/v1/text_to_video/client.py +204 -18
- magic_hour/resources/v1/video_projects/README.md +81 -9
- magic_hour/resources/v1/video_projects/__init__.py +10 -2
- magic_hour/resources/v1/video_projects/client.py +151 -14
- magic_hour/resources/v1/video_projects/client_test.py +527 -0
- magic_hour/resources/v1/video_to_video/README.md +119 -15
- magic_hour/resources/v1/video_to_video/client.py +299 -46
- magic_hour/types/models/__init__.py +92 -56
- magic_hour/types/models/v1_ai_clothes_changer_create_response.py +33 -0
- magic_hour/types/models/v1_ai_face_editor_create_response.py +33 -0
- magic_hour/types/models/v1_ai_gif_generator_create_response.py +33 -0
- magic_hour/types/models/v1_ai_headshot_generator_create_response.py +33 -0
- magic_hour/types/models/v1_ai_image_editor_create_response.py +33 -0
- magic_hour/types/models/v1_ai_image_generator_create_response.py +33 -0
- magic_hour/types/models/v1_ai_image_upscaler_create_response.py +33 -0
- magic_hour/types/models/v1_ai_meme_generator_create_response.py +33 -0
- magic_hour/types/models/v1_ai_photo_editor_create_response.py +33 -0
- magic_hour/types/models/v1_ai_qr_code_generator_create_response.py +33 -0
- magic_hour/types/models/v1_ai_talking_photo_create_response.py +35 -0
- magic_hour/types/models/v1_ai_voice_cloner_create_response.py +27 -0
- magic_hour/types/models/v1_ai_voice_generator_create_response.py +27 -0
- magic_hour/types/models/v1_animation_create_response.py +35 -0
- magic_hour/types/models/v1_audio_projects_get_response.py +72 -0
- magic_hour/types/models/v1_audio_projects_get_response_downloads_item.py +19 -0
- magic_hour/types/models/{get_v1_image_projects_id_response_error.py → v1_audio_projects_get_response_error.py} +2 -2
- magic_hour/types/models/v1_auto_subtitle_generator_create_response.py +35 -0
- magic_hour/types/models/v1_face_detection_create_response.py +25 -0
- magic_hour/types/models/v1_face_detection_get_response.py +45 -0
- magic_hour/types/models/v1_face_detection_get_response_faces_item.py +25 -0
- magic_hour/types/models/v1_face_swap_create_response.py +35 -0
- magic_hour/types/models/v1_face_swap_photo_create_response.py +33 -0
- magic_hour/types/models/v1_files_upload_urls_create_response.py +24 -0
- magic_hour/types/models/{post_v1_files_upload_urls_response_items_item.py → v1_files_upload_urls_create_response_items_item.py} +2 -2
- magic_hour/types/models/v1_image_background_remover_create_response.py +33 -0
- magic_hour/types/models/{get_v1_image_projects_id_response.py → v1_image_projects_get_response.py} +20 -18
- magic_hour/types/models/{get_v1_video_projects_id_response_downloads_item.py → v1_image_projects_get_response_downloads_item.py} +1 -1
- magic_hour/types/models/{get_v1_video_projects_id_response_error.py → v1_image_projects_get_response_error.py} +2 -2
- magic_hour/types/models/v1_image_to_video_create_response.py +35 -0
- magic_hour/types/models/v1_lip_sync_create_response.py +35 -0
- magic_hour/types/models/v1_photo_colorizer_create_response.py +33 -0
- magic_hour/types/models/v1_text_to_video_create_response.py +35 -0
- magic_hour/types/models/{get_v1_video_projects_id_response.py → v1_video_projects_get_response.py} +26 -23
- magic_hour/types/models/{get_v1_video_projects_id_response_download.py → v1_video_projects_get_response_download.py} +1 -1
- magic_hour/types/models/{get_v1_image_projects_id_response_downloads_item.py → v1_video_projects_get_response_downloads_item.py} +1 -1
- magic_hour/types/models/v1_video_projects_get_response_error.py +25 -0
- magic_hour/types/models/v1_video_to_video_create_response.py +35 -0
- magic_hour/types/params/__init__.py +422 -176
- magic_hour/types/params/v1_ai_clothes_changer_create_body.py +40 -0
- magic_hour/types/params/v1_ai_clothes_changer_create_body_assets.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_create_body.py +52 -0
- magic_hour/types/params/v1_ai_face_editor_create_body_assets.py +33 -0
- magic_hour/types/params/v1_ai_face_editor_create_body_style.py +137 -0
- magic_hour/types/params/v1_ai_face_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_gif_generator_create_body.py +47 -0
- magic_hour/types/params/{post_v1_ai_image_generator_body_style.py → v1_ai_gif_generator_create_body_style.py} +5 -5
- magic_hour/types/params/v1_ai_headshot_generator_create_body.py +49 -0
- magic_hour/types/params/v1_ai_headshot_generator_create_body_assets.py +33 -0
- magic_hour/types/params/v1_ai_headshot_generator_create_body_style.py +27 -0
- magic_hour/types/params/v1_ai_headshot_generator_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_image_editor_create_body.py +49 -0
- magic_hour/types/params/v1_ai_image_editor_create_body_assets.py +47 -0
- magic_hour/types/params/v1_ai_image_editor_create_body_style.py +41 -0
- magic_hour/types/params/v1_ai_image_editor_generate_body_assets.py +28 -0
- magic_hour/types/params/{post_v1_ai_image_generator_body.py → v1_ai_image_generator_create_body.py} +17 -11
- magic_hour/types/params/v1_ai_image_generator_create_body_style.py +127 -0
- magic_hour/types/params/v1_ai_image_upscaler_create_body.py +59 -0
- magic_hour/types/params/v1_ai_image_upscaler_create_body_assets.py +33 -0
- magic_hour/types/params/{post_v1_ai_image_upscaler_body_style.py → v1_ai_image_upscaler_create_body_style.py} +4 -4
- magic_hour/types/params/v1_ai_image_upscaler_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_meme_generator_create_body.py +37 -0
- magic_hour/types/params/v1_ai_meme_generator_create_body_style.py +73 -0
- magic_hour/types/params/{post_v1_ai_photo_editor_body.py → v1_ai_photo_editor_create_body.py} +15 -15
- magic_hour/types/params/v1_ai_photo_editor_create_body_assets.py +33 -0
- magic_hour/types/params/{post_v1_ai_photo_editor_body_style.py → v1_ai_photo_editor_create_body_style.py} +20 -4
- magic_hour/types/params/v1_ai_photo_editor_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_ai_qr_code_generator_create_body.py +45 -0
- magic_hour/types/params/{post_v1_ai_qr_code_generator_body_style.py → v1_ai_qr_code_generator_create_body_style.py} +4 -4
- magic_hour/types/params/v1_ai_talking_photo_create_body.py +68 -0
- magic_hour/types/params/v1_ai_talking_photo_create_body_assets.py +46 -0
- magic_hour/types/params/v1_ai_talking_photo_create_body_style.py +44 -0
- magic_hour/types/params/v1_ai_talking_photo_generate_body_assets.py +26 -0
- magic_hour/types/params/v1_ai_voice_cloner_create_body.py +49 -0
- magic_hour/types/params/v1_ai_voice_cloner_create_body_assets.py +33 -0
- magic_hour/types/params/v1_ai_voice_cloner_create_body_style.py +28 -0
- magic_hour/types/params/v1_ai_voice_cloner_generate_body_assets.py +28 -0
- magic_hour/types/params/v1_ai_voice_generator_create_body.py +40 -0
- magic_hour/types/params/v1_ai_voice_generator_create_body_style.py +440 -0
- magic_hour/types/params/{post_v1_animation_body.py → v1_animation_create_body.py} +16 -16
- magic_hour/types/params/{post_v1_animation_body_assets.py → v1_animation_create_body_assets.py} +15 -5
- magic_hour/types/params/{post_v1_animation_body_style.py → v1_animation_create_body_style.py} +13 -10
- magic_hour/types/params/v1_animation_generate_body_assets.py +39 -0
- magic_hour/types/params/v1_auto_subtitle_generator_create_body.py +78 -0
- magic_hour/types/params/v1_auto_subtitle_generator_create_body_assets.py +33 -0
- magic_hour/types/params/v1_auto_subtitle_generator_create_body_style.py +56 -0
- magic_hour/types/params/v1_auto_subtitle_generator_create_body_style_custom_config.py +86 -0
- magic_hour/types/params/v1_auto_subtitle_generator_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_face_detection_create_body.py +44 -0
- magic_hour/types/params/v1_face_detection_create_body_assets.py +33 -0
- magic_hour/types/params/v1_face_detection_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_face_swap_create_body.py +92 -0
- magic_hour/types/params/v1_face_swap_create_body_assets.py +91 -0
- magic_hour/types/params/v1_face_swap_create_body_assets_face_mappings_item.py +44 -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_create_body.py +40 -0
- magic_hour/types/params/v1_face_swap_photo_create_body_assets.py +76 -0
- magic_hour/types/params/v1_face_swap_photo_create_body_assets_face_mappings_item.py +44 -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_files_upload_urls_create_body.py +36 -0
- magic_hour/types/params/v1_files_upload_urls_create_body_items_item.py +38 -0
- magic_hour/types/params/v1_image_background_remover_create_body.py +40 -0
- magic_hour/types/params/v1_image_background_remover_create_body_assets.py +49 -0
- magic_hour/types/params/v1_image_background_remover_generate_body_assets.py +27 -0
- magic_hour/types/params/v1_image_to_video_create_body.py +101 -0
- magic_hour/types/params/v1_image_to_video_create_body_assets.py +33 -0
- magic_hour/types/params/v1_image_to_video_create_body_style.py +53 -0
- magic_hour/types/params/v1_image_to_video_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_lip_sync_create_body.py +100 -0
- magic_hour/types/params/{post_v1_lip_sync_body_assets.py → v1_lip_sync_create_body_assets.py} +15 -5
- magic_hour/types/params/v1_lip_sync_create_body_style.py +37 -0
- magic_hour/types/params/v1_lip_sync_generate_body_assets.py +36 -0
- magic_hour/types/params/v1_photo_colorizer_create_body.py +40 -0
- magic_hour/types/params/v1_photo_colorizer_create_body_assets.py +33 -0
- magic_hour/types/params/v1_photo_colorizer_generate_body_assets.py +17 -0
- magic_hour/types/params/v1_text_to_video_create_body.py +78 -0
- magic_hour/types/params/v1_text_to_video_create_body_style.py +43 -0
- magic_hour/types/params/v1_video_to_video_create_body.py +101 -0
- magic_hour/types/params/{post_v1_video_to_video_body_assets.py → v1_video_to_video_create_body_assets.py} +9 -4
- magic_hour/types/params/{post_v1_video_to_video_body_style.py → v1_video_to_video_create_body_style.py} +68 -26
- magic_hour/types/params/v1_video_to_video_generate_body_assets.py +27 -0
- magic_hour-0.44.0.dist-info/METADATA +328 -0
- magic_hour-0.44.0.dist-info/RECORD +231 -0
- magic_hour/core/__init__.py +0 -52
- magic_hour/core/api_error.py +0 -56
- magic_hour/core/auth.py +0 -314
- magic_hour/core/base_client.py +0 -618
- magic_hour/core/binary_response.py +0 -23
- magic_hour/core/query.py +0 -106
- magic_hour/core/request.py +0 -156
- magic_hour/core/response.py +0 -293
- magic_hour/core/type_utils.py +0 -28
- magic_hour/core/utils.py +0 -55
- magic_hour/types/models/post_v1_ai_clothes_changer_response.py +0 -25
- magic_hour/types/models/post_v1_ai_headshot_generator_response.py +0 -25
- magic_hour/types/models/post_v1_ai_image_generator_response.py +0 -25
- magic_hour/types/models/post_v1_ai_image_upscaler_response.py +0 -25
- magic_hour/types/models/post_v1_ai_photo_editor_response.py +0 -25
- magic_hour/types/models/post_v1_ai_qr_code_generator_response.py +0 -25
- magic_hour/types/models/post_v1_animation_response.py +0 -25
- magic_hour/types/models/post_v1_face_swap_photo_response.py +0 -25
- magic_hour/types/models/post_v1_face_swap_response.py +0 -25
- magic_hour/types/models/post_v1_files_upload_urls_response.py +0 -21
- magic_hour/types/models/post_v1_image_background_remover_response.py +0 -25
- magic_hour/types/models/post_v1_image_to_video_response.py +0 -25
- magic_hour/types/models/post_v1_lip_sync_response.py +0 -25
- magic_hour/types/models/post_v1_text_to_video_response.py +0 -25
- magic_hour/types/models/post_v1_video_to_video_response.py +0 -25
- magic_hour/types/params/post_v1_ai_clothes_changer_body.py +0 -40
- magic_hour/types/params/post_v1_ai_clothes_changer_body_assets.py +0 -45
- magic_hour/types/params/post_v1_ai_headshot_generator_body.py +0 -40
- magic_hour/types/params/post_v1_ai_headshot_generator_body_assets.py +0 -28
- magic_hour/types/params/post_v1_ai_image_upscaler_body.py +0 -57
- magic_hour/types/params/post_v1_ai_image_upscaler_body_assets.py +0 -28
- magic_hour/types/params/post_v1_ai_photo_editor_body_assets.py +0 -28
- magic_hour/types/params/post_v1_ai_qr_code_generator_body.py +0 -45
- magic_hour/types/params/post_v1_face_swap_body.py +0 -72
- magic_hour/types/params/post_v1_face_swap_body_assets.py +0 -52
- magic_hour/types/params/post_v1_face_swap_photo_body.py +0 -40
- magic_hour/types/params/post_v1_face_swap_photo_body_assets.py +0 -36
- magic_hour/types/params/post_v1_files_upload_urls_body.py +0 -31
- magic_hour/types/params/post_v1_files_upload_urls_body_items_item.py +0 -38
- magic_hour/types/params/post_v1_image_background_remover_body.py +0 -40
- magic_hour/types/params/post_v1_image_background_remover_body_assets.py +0 -28
- magic_hour/types/params/post_v1_image_to_video_body.py +0 -73
- magic_hour/types/params/post_v1_image_to_video_body_assets.py +0 -28
- magic_hour/types/params/post_v1_image_to_video_body_style.py +0 -37
- magic_hour/types/params/post_v1_lip_sync_body.py +0 -80
- magic_hour/types/params/post_v1_text_to_video_body.py +0 -57
- magic_hour/types/params/post_v1_text_to_video_body_style.py +0 -28
- magic_hour/types/params/post_v1_video_to_video_body.py +0 -93
- magic_hour-0.9.5.dist-info/METADATA +0 -133
- magic_hour-0.9.5.dist-info/RECORD +0 -132
- {magic_hour-0.9.5.dist-info → magic_hour-0.44.0.dist-info}/LICENSE +0 -0
- {magic_hour-0.9.5.dist-info → magic_hour-0.44.0.dist-info}/WHEEL +0 -0
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
import typing_extensions
|
|
3
3
|
|
|
4
|
-
from magic_hour.
|
|
4
|
+
from magic_hour.helpers.logger import get_sdk_logger
|
|
5
|
+
from magic_hour.resources.v1.image_projects.client import (
|
|
6
|
+
AsyncImageProjectsClient,
|
|
7
|
+
ImageProjectsClient,
|
|
8
|
+
)
|
|
9
|
+
from magic_hour.types import models, params
|
|
10
|
+
from make_api_request import (
|
|
5
11
|
AsyncBaseClient,
|
|
6
12
|
RequestOptions,
|
|
7
13
|
SyncBaseClient,
|
|
@@ -9,36 +15,103 @@ from magic_hour.core import (
|
|
|
9
15
|
to_encodable,
|
|
10
16
|
type_utils,
|
|
11
17
|
)
|
|
12
|
-
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
logger = get_sdk_logger(__name__)
|
|
13
21
|
|
|
14
22
|
|
|
15
23
|
class AiImageGeneratorClient:
|
|
16
24
|
def __init__(self, *, base_client: SyncBaseClient):
|
|
17
25
|
self._base_client = base_client
|
|
18
26
|
|
|
27
|
+
def generate(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
image_count: int,
|
|
31
|
+
orientation: typing_extensions.Literal["landscape", "portrait", "square"],
|
|
32
|
+
style: params.V1AiImageGeneratorCreateBodyStyle,
|
|
33
|
+
name: typing.Union[
|
|
34
|
+
typing.Optional[str], type_utils.NotGiven
|
|
35
|
+
] = type_utils.NOT_GIVEN,
|
|
36
|
+
wait_for_completion: bool = True,
|
|
37
|
+
download_outputs: bool = True,
|
|
38
|
+
download_directory: typing.Optional[str] = None,
|
|
39
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
40
|
+
):
|
|
41
|
+
"""
|
|
42
|
+
Generate AI images (alias for create with additional functionality).
|
|
43
|
+
|
|
44
|
+
Create AI images with text prompts. Each image costs 5 credits.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
48
|
+
image_count: Number of images to generate.
|
|
49
|
+
orientation: The orientation of the output image(s).
|
|
50
|
+
style: The art style to use for image generation.
|
|
51
|
+
wait_for_completion: Whether to wait for the image project to complete
|
|
52
|
+
download_outputs: Whether to download the outputs
|
|
53
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
54
|
+
request_options: Additional options to customize the HTTP request
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
V1ImageProjectsGetResponseWithDownloads: The response from the AI Image Generator API with the downloaded paths if `download_outputs` is True.
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
```py
|
|
61
|
+
response = client.v1.ai_image_generator.generate(
|
|
62
|
+
image_count=1,
|
|
63
|
+
orientation="landscape",
|
|
64
|
+
style={"prompt": "Cool image", "tool": "ai-anime-generator"},
|
|
65
|
+
name="Generated Image",
|
|
66
|
+
wait_for_completion=True,
|
|
67
|
+
download_outputs=True,
|
|
68
|
+
download_directory="outputs/",
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
create_response = self.create(
|
|
74
|
+
image_count=image_count,
|
|
75
|
+
orientation=orientation,
|
|
76
|
+
style=style,
|
|
77
|
+
name=name,
|
|
78
|
+
request_options=request_options,
|
|
79
|
+
)
|
|
80
|
+
logger.info(f"AI Image Generator response: {create_response}")
|
|
81
|
+
|
|
82
|
+
image_projects_client = ImageProjectsClient(base_client=self._base_client)
|
|
83
|
+
response = image_projects_client.check_result(
|
|
84
|
+
id=create_response.id,
|
|
85
|
+
wait_for_completion=wait_for_completion,
|
|
86
|
+
download_outputs=download_outputs,
|
|
87
|
+
download_directory=download_directory,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
return response
|
|
91
|
+
|
|
19
92
|
def create(
|
|
20
93
|
self,
|
|
21
94
|
*,
|
|
22
95
|
image_count: int,
|
|
23
96
|
orientation: typing_extensions.Literal["landscape", "portrait", "square"],
|
|
24
|
-
style: params.
|
|
97
|
+
style: params.V1AiImageGeneratorCreateBodyStyle,
|
|
25
98
|
name: typing.Union[
|
|
26
99
|
typing.Optional[str], type_utils.NotGiven
|
|
27
100
|
] = type_utils.NOT_GIVEN,
|
|
28
101
|
request_options: typing.Optional[RequestOptions] = None,
|
|
29
|
-
) -> models.
|
|
102
|
+
) -> models.V1AiImageGeneratorCreateResponse:
|
|
30
103
|
"""
|
|
31
|
-
AI
|
|
104
|
+
AI Image Generator
|
|
32
105
|
|
|
33
|
-
Create an AI image. Each image costs 5
|
|
106
|
+
Create an AI image. Each standard image costs 5 credits. Pro quality images cost 30 credits.
|
|
34
107
|
|
|
35
108
|
POST /v1/ai-image-generator
|
|
36
109
|
|
|
37
110
|
Args:
|
|
38
|
-
name: The name of image
|
|
39
|
-
image_count:
|
|
40
|
-
orientation:
|
|
41
|
-
style:
|
|
111
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
112
|
+
image_count: Number of images to generate.
|
|
113
|
+
orientation: The orientation of the output image(s).
|
|
114
|
+
style: The art style to use for image generation.
|
|
42
115
|
request_options: Additional options to customize the HTTP request
|
|
43
116
|
|
|
44
117
|
Returns:
|
|
@@ -53,7 +126,11 @@ class AiImageGeneratorClient:
|
|
|
53
126
|
client.v1.ai_image_generator.create(
|
|
54
127
|
image_count=1,
|
|
55
128
|
orientation="landscape",
|
|
56
|
-
style={
|
|
129
|
+
style={
|
|
130
|
+
"prompt": "Cool image",
|
|
131
|
+
"quality_mode": "standard",
|
|
132
|
+
"tool": "ai-anime-generator",
|
|
133
|
+
},
|
|
57
134
|
name="Ai Image image",
|
|
58
135
|
)
|
|
59
136
|
```
|
|
@@ -65,14 +142,14 @@ class AiImageGeneratorClient:
|
|
|
65
142
|
"orientation": orientation,
|
|
66
143
|
"style": style,
|
|
67
144
|
},
|
|
68
|
-
dump_with=params.
|
|
145
|
+
dump_with=params._SerializerV1AiImageGeneratorCreateBody,
|
|
69
146
|
)
|
|
70
147
|
return self._base_client.request(
|
|
71
148
|
method="POST",
|
|
72
149
|
path="/v1/ai-image-generator",
|
|
73
150
|
auth_names=["bearerAuth"],
|
|
74
151
|
json=_json,
|
|
75
|
-
cast_to=models.
|
|
152
|
+
cast_to=models.V1AiImageGeneratorCreateResponse,
|
|
76
153
|
request_options=request_options or default_request_options(),
|
|
77
154
|
)
|
|
78
155
|
|
|
@@ -81,29 +158,94 @@ class AsyncAiImageGeneratorClient:
|
|
|
81
158
|
def __init__(self, *, base_client: AsyncBaseClient):
|
|
82
159
|
self._base_client = base_client
|
|
83
160
|
|
|
161
|
+
async def generate(
|
|
162
|
+
self,
|
|
163
|
+
*,
|
|
164
|
+
image_count: int,
|
|
165
|
+
orientation: typing_extensions.Literal["landscape", "portrait", "square"],
|
|
166
|
+
style: params.V1AiImageGeneratorCreateBodyStyle,
|
|
167
|
+
name: typing.Union[
|
|
168
|
+
typing.Optional[str], type_utils.NotGiven
|
|
169
|
+
] = type_utils.NOT_GIVEN,
|
|
170
|
+
wait_for_completion: bool = True,
|
|
171
|
+
download_outputs: bool = True,
|
|
172
|
+
download_directory: typing.Optional[str] = None,
|
|
173
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
174
|
+
):
|
|
175
|
+
"""
|
|
176
|
+
Generate AI images (alias for create with additional functionality).
|
|
177
|
+
|
|
178
|
+
Create AI images with text prompts. Each image costs 5 credits.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
182
|
+
image_count: Number of images to generate.
|
|
183
|
+
orientation: The orientation of the output image(s).
|
|
184
|
+
style: The art style to use for image generation.
|
|
185
|
+
wait_for_completion: Whether to wait for the image project to complete
|
|
186
|
+
download_outputs: Whether to download the outputs
|
|
187
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
188
|
+
request_options: Additional options to customize the HTTP request
|
|
189
|
+
|
|
190
|
+
Returns:
|
|
191
|
+
V1ImageProjectsGetResponseWithDownloads: The response from the AI Image Generator API with the downloaded paths if `download_outputs` is True.
|
|
192
|
+
|
|
193
|
+
Examples:
|
|
194
|
+
```py
|
|
195
|
+
response = await client.v1.ai_image_generator.generate(
|
|
196
|
+
image_count=1,
|
|
197
|
+
orientation="landscape",
|
|
198
|
+
style={"prompt": "Cool image", "tool": "ai-anime-generator"},
|
|
199
|
+
name="Generated Image",
|
|
200
|
+
wait_for_completion=True,
|
|
201
|
+
download_outputs=True,
|
|
202
|
+
download_directory="outputs/",
|
|
203
|
+
)
|
|
204
|
+
```
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
create_response = await self.create(
|
|
208
|
+
image_count=image_count,
|
|
209
|
+
orientation=orientation,
|
|
210
|
+
style=style,
|
|
211
|
+
name=name,
|
|
212
|
+
request_options=request_options,
|
|
213
|
+
)
|
|
214
|
+
logger.info(f"AI Image Generator response: {create_response}")
|
|
215
|
+
|
|
216
|
+
image_projects_client = AsyncImageProjectsClient(base_client=self._base_client)
|
|
217
|
+
response = await image_projects_client.check_result(
|
|
218
|
+
id=create_response.id,
|
|
219
|
+
wait_for_completion=wait_for_completion,
|
|
220
|
+
download_outputs=download_outputs,
|
|
221
|
+
download_directory=download_directory,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
return response
|
|
225
|
+
|
|
84
226
|
async def create(
|
|
85
227
|
self,
|
|
86
228
|
*,
|
|
87
229
|
image_count: int,
|
|
88
230
|
orientation: typing_extensions.Literal["landscape", "portrait", "square"],
|
|
89
|
-
style: params.
|
|
231
|
+
style: params.V1AiImageGeneratorCreateBodyStyle,
|
|
90
232
|
name: typing.Union[
|
|
91
233
|
typing.Optional[str], type_utils.NotGiven
|
|
92
234
|
] = type_utils.NOT_GIVEN,
|
|
93
235
|
request_options: typing.Optional[RequestOptions] = None,
|
|
94
|
-
) -> models.
|
|
236
|
+
) -> models.V1AiImageGeneratorCreateResponse:
|
|
95
237
|
"""
|
|
96
|
-
AI
|
|
238
|
+
AI Image Generator
|
|
97
239
|
|
|
98
|
-
Create an AI image. Each image costs 5
|
|
240
|
+
Create an AI image. Each standard image costs 5 credits. Pro quality images cost 30 credits.
|
|
99
241
|
|
|
100
242
|
POST /v1/ai-image-generator
|
|
101
243
|
|
|
102
244
|
Args:
|
|
103
|
-
name: The name of image
|
|
104
|
-
image_count:
|
|
105
|
-
orientation:
|
|
106
|
-
style:
|
|
245
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
246
|
+
image_count: Number of images to generate.
|
|
247
|
+
orientation: The orientation of the output image(s).
|
|
248
|
+
style: The art style to use for image generation.
|
|
107
249
|
request_options: Additional options to customize the HTTP request
|
|
108
250
|
|
|
109
251
|
Returns:
|
|
@@ -118,7 +260,11 @@ class AsyncAiImageGeneratorClient:
|
|
|
118
260
|
await client.v1.ai_image_generator.create(
|
|
119
261
|
image_count=1,
|
|
120
262
|
orientation="landscape",
|
|
121
|
-
style={
|
|
263
|
+
style={
|
|
264
|
+
"prompt": "Cool image",
|
|
265
|
+
"quality_mode": "standard",
|
|
266
|
+
"tool": "ai-anime-generator",
|
|
267
|
+
},
|
|
122
268
|
name="Ai Image image",
|
|
123
269
|
)
|
|
124
270
|
```
|
|
@@ -130,13 +276,13 @@ class AsyncAiImageGeneratorClient:
|
|
|
130
276
|
"orientation": orientation,
|
|
131
277
|
"style": style,
|
|
132
278
|
},
|
|
133
|
-
dump_with=params.
|
|
279
|
+
dump_with=params._SerializerV1AiImageGeneratorCreateBody,
|
|
134
280
|
)
|
|
135
281
|
return await self._base_client.request(
|
|
136
282
|
method="POST",
|
|
137
283
|
path="/v1/ai-image-generator",
|
|
138
284
|
auth_names=["bearerAuth"],
|
|
139
285
|
json=_json,
|
|
140
|
-
cast_to=models.
|
|
286
|
+
cast_to=models.V1AiImageGeneratorCreateResponse,
|
|
141
287
|
request_options=request_options or default_request_options(),
|
|
142
288
|
)
|
|
@@ -1,11 +1,85 @@
|
|
|
1
|
+
# v1.ai_image_upscaler
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
AI Image Upscaler
|
|
3
|
+
## Module Functions
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<!-- CUSTOM DOCS START -->
|
|
6
|
+
|
|
7
|
+
### Ai Image Upscaler 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.ai_image_upscaler.generate(
|
|
35
|
+
assets={"image_file_path": "/path/to/1234.png"},
|
|
36
|
+
scale_factor=2.0,
|
|
37
|
+
style={"enhancement": "Balanced"},
|
|
38
|
+
name="Image Upscaler image",
|
|
39
|
+
wait_for_completion=True,
|
|
40
|
+
download_outputs=True,
|
|
41
|
+
download_directory="outputs"
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### Asynchronous Client
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from magic_hour import AsyncClient
|
|
49
|
+
from os import getenv
|
|
50
|
+
|
|
51
|
+
client = AsyncClient(token=getenv("API_TOKEN"))
|
|
52
|
+
res = await client.v1.ai_image_upscaler.generate(
|
|
53
|
+
assets={"image_file_path": "/path/to/1234.png"},
|
|
54
|
+
scale_factor=2.0,
|
|
55
|
+
style={"enhancement": "Balanced"},
|
|
56
|
+
name="Image Upscaler image",
|
|
57
|
+
wait_for_completion=True,
|
|
58
|
+
download_outputs=True,
|
|
59
|
+
download_directory="outputs"
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
<!-- CUSTOM DOCS END -->
|
|
64
|
+
|
|
65
|
+
### AI Image Upscaler <a name="create"></a>
|
|
66
|
+
|
|
67
|
+
Upscale your image using AI. Each 2x upscale costs 50 credits, and 4x upscale costs 200 credits.
|
|
6
68
|
|
|
7
69
|
**API Endpoint**: `POST /v1/ai-image-upscaler`
|
|
8
70
|
|
|
71
|
+
#### Parameters
|
|
72
|
+
|
|
73
|
+
| Parameter | Required | Description | Example |
|
|
74
|
+
| -------------------- | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------- |
|
|
75
|
+
| `assets` | ✓ | Provide the assets for upscaling | `{"image_file_path": "api-assets/id/1234.png"}` |
|
|
76
|
+
| `└─ image_file_path` | ✓ | The image to upscale. This value is either - a direct URL to the video file - `file_path` field from the response of the [upload urls API](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls). Please refer to the [Input File documentation](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls#input-file) to learn more. | `"api-assets/id/1234.png"` |
|
|
77
|
+
| `scale_factor` | ✓ | How much to scale the image. Must be either 2 or 4. Note: 4x upscale is only available on Creator, Pro, or Business tier. | `2.0` |
|
|
78
|
+
| `style` | ✓ | | `{"enhancement": "Balanced"}` |
|
|
79
|
+
| `└─ enhancement` | ✓ | | `"Balanced"` |
|
|
80
|
+
| `└─ prompt` | ✗ | A prompt to guide the final image. This value is ignored if `enhancement` is not Creative | `"string"` |
|
|
81
|
+
| `name` | ✗ | The name of image. This value is mainly used for your own identification of the image. | `"Image Upscaler image"` |
|
|
82
|
+
|
|
9
83
|
#### Synchronous Client
|
|
10
84
|
|
|
11
85
|
```python
|
|
@@ -35,3 +109,15 @@ res = await client.v1.ai_image_upscaler.create(
|
|
|
35
109
|
name="Image Upscaler image",
|
|
36
110
|
)
|
|
37
111
|
```
|
|
112
|
+
|
|
113
|
+
#### Response
|
|
114
|
+
|
|
115
|
+
##### Type
|
|
116
|
+
|
|
117
|
+
[V1AiImageUpscalerCreateResponse](/magic_hour/types/models/v1_ai_image_upscaler_create_response.py)
|
|
118
|
+
|
|
119
|
+
##### Example
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
{"credits_charged": 50, "frame_cost": 50, "id": "cuid-example"}
|
|
123
|
+
```
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
|
|
3
|
-
from magic_hour.
|
|
3
|
+
from magic_hour.helpers.logger import get_sdk_logger
|
|
4
|
+
from magic_hour.resources.v1.files.client import AsyncFilesClient, FilesClient
|
|
5
|
+
from magic_hour.resources.v1.image_projects.client import (
|
|
6
|
+
AsyncImageProjectsClient,
|
|
7
|
+
ImageProjectsClient,
|
|
8
|
+
)
|
|
9
|
+
from magic_hour.types import models, params
|
|
10
|
+
from make_api_request import (
|
|
4
11
|
AsyncBaseClient,
|
|
5
12
|
RequestOptions,
|
|
6
13
|
SyncBaseClient,
|
|
@@ -8,36 +15,110 @@ from magic_hour.core import (
|
|
|
8
15
|
to_encodable,
|
|
9
16
|
type_utils,
|
|
10
17
|
)
|
|
11
|
-
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
logger = get_sdk_logger(__name__)
|
|
12
21
|
|
|
13
22
|
|
|
14
23
|
class AiImageUpscalerClient:
|
|
15
24
|
def __init__(self, *, base_client: SyncBaseClient):
|
|
16
25
|
self._base_client = base_client
|
|
17
26
|
|
|
27
|
+
def generate(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
assets: params.V1AiImageUpscalerGenerateBodyAssets,
|
|
31
|
+
scale_factor: float,
|
|
32
|
+
style: params.V1AiImageUpscalerCreateBodyStyle,
|
|
33
|
+
name: typing.Union[
|
|
34
|
+
typing.Optional[str], type_utils.NotGiven
|
|
35
|
+
] = type_utils.NOT_GIVEN,
|
|
36
|
+
wait_for_completion: bool = True,
|
|
37
|
+
download_outputs: bool = True,
|
|
38
|
+
download_directory: typing.Optional[str] = None,
|
|
39
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
40
|
+
):
|
|
41
|
+
"""
|
|
42
|
+
Generate upscaled image (alias for create with additional functionality).
|
|
43
|
+
|
|
44
|
+
Upscale image using AI. Each upscale costs 5 credits.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
48
|
+
assets: Provide the assets for image upscaler
|
|
49
|
+
scale_factor: How much to scale the image. Must be either 2 or 4.
|
|
50
|
+
style: Image upscaling parameters
|
|
51
|
+
wait_for_completion: Whether to wait for the image project to complete
|
|
52
|
+
download_outputs: Whether to download the outputs
|
|
53
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
54
|
+
request_options: Additional options to customize the HTTP request
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
V1ImageProjectsGetResponseWithDownloads: The response from the AI Image Upscaler API with the downloaded paths if `download_outputs` is True.
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
```py
|
|
61
|
+
response = client.v1.ai_image_upscaler.generate(
|
|
62
|
+
assets={"image_file_path": "path/to/image.png"},
|
|
63
|
+
scale_factor=2.0,
|
|
64
|
+
style={"enhancement": "Balanced"},
|
|
65
|
+
name="Upscaled Image",
|
|
66
|
+
wait_for_completion=True,
|
|
67
|
+
download_outputs=True,
|
|
68
|
+
download_directory="outputs/",
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
file_client = FilesClient(base_client=self._base_client)
|
|
74
|
+
|
|
75
|
+
image_file_path = assets["image_file_path"]
|
|
76
|
+
assets["image_file_path"] = file_client.upload_file(file=image_file_path)
|
|
77
|
+
|
|
78
|
+
create_response = self.create(
|
|
79
|
+
assets=assets,
|
|
80
|
+
scale_factor=scale_factor,
|
|
81
|
+
style=style,
|
|
82
|
+
name=name,
|
|
83
|
+
request_options=request_options,
|
|
84
|
+
)
|
|
85
|
+
logger.info(f"AI Image Upscaler response: {create_response}")
|
|
86
|
+
|
|
87
|
+
image_projects_client = ImageProjectsClient(base_client=self._base_client)
|
|
88
|
+
response = image_projects_client.check_result(
|
|
89
|
+
id=create_response.id,
|
|
90
|
+
wait_for_completion=wait_for_completion,
|
|
91
|
+
download_outputs=download_outputs,
|
|
92
|
+
download_directory=download_directory,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
return response
|
|
96
|
+
|
|
18
97
|
def create(
|
|
19
98
|
self,
|
|
20
99
|
*,
|
|
21
|
-
assets: params.
|
|
100
|
+
assets: params.V1AiImageUpscalerCreateBodyAssets,
|
|
22
101
|
scale_factor: float,
|
|
23
|
-
style: params.
|
|
102
|
+
style: params.V1AiImageUpscalerCreateBodyStyle,
|
|
24
103
|
name: typing.Union[
|
|
25
104
|
typing.Optional[str], type_utils.NotGiven
|
|
26
105
|
] = type_utils.NOT_GIVEN,
|
|
27
106
|
request_options: typing.Optional[RequestOptions] = None,
|
|
28
|
-
) -> models.
|
|
107
|
+
) -> models.V1AiImageUpscalerCreateResponse:
|
|
29
108
|
"""
|
|
30
109
|
AI Image Upscaler
|
|
31
110
|
|
|
32
|
-
Upscale your image using AI. Each 2x upscale costs 50
|
|
111
|
+
Upscale your image using AI. Each 2x upscale costs 50 credits, and 4x upscale costs 200 credits.
|
|
33
112
|
|
|
34
113
|
POST /v1/ai-image-upscaler
|
|
35
114
|
|
|
36
115
|
Args:
|
|
37
|
-
name: The name of image
|
|
116
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
38
117
|
assets: Provide the assets for upscaling
|
|
39
|
-
scale_factor: How much to scale the image. Must be either 2 or 4
|
|
40
|
-
|
|
118
|
+
scale_factor: How much to scale the image. Must be either 2 or 4.
|
|
119
|
+
|
|
120
|
+
Note: 4x upscale is only available on Creator, Pro, or Business tier.
|
|
121
|
+
style: V1AiImageUpscalerCreateBodyStyle
|
|
41
122
|
request_options: Additional options to customize the HTTP request
|
|
42
123
|
|
|
43
124
|
Returns:
|
|
@@ -64,14 +145,14 @@ class AiImageUpscalerClient:
|
|
|
64
145
|
"scale_factor": scale_factor,
|
|
65
146
|
"style": style,
|
|
66
147
|
},
|
|
67
|
-
dump_with=params.
|
|
148
|
+
dump_with=params._SerializerV1AiImageUpscalerCreateBody,
|
|
68
149
|
)
|
|
69
150
|
return self._base_client.request(
|
|
70
151
|
method="POST",
|
|
71
152
|
path="/v1/ai-image-upscaler",
|
|
72
153
|
auth_names=["bearerAuth"],
|
|
73
154
|
json=_json,
|
|
74
|
-
cast_to=models.
|
|
155
|
+
cast_to=models.V1AiImageUpscalerCreateResponse,
|
|
75
156
|
request_options=request_options or default_request_options(),
|
|
76
157
|
)
|
|
77
158
|
|
|
@@ -80,29 +161,101 @@ class AsyncAiImageUpscalerClient:
|
|
|
80
161
|
def __init__(self, *, base_client: AsyncBaseClient):
|
|
81
162
|
self._base_client = base_client
|
|
82
163
|
|
|
164
|
+
async def generate(
|
|
165
|
+
self,
|
|
166
|
+
*,
|
|
167
|
+
assets: params.V1AiImageUpscalerGenerateBodyAssets,
|
|
168
|
+
scale_factor: float,
|
|
169
|
+
style: params.V1AiImageUpscalerCreateBodyStyle,
|
|
170
|
+
name: typing.Union[
|
|
171
|
+
typing.Optional[str], type_utils.NotGiven
|
|
172
|
+
] = type_utils.NOT_GIVEN,
|
|
173
|
+
wait_for_completion: bool = True,
|
|
174
|
+
download_outputs: bool = True,
|
|
175
|
+
download_directory: typing.Optional[str] = None,
|
|
176
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
177
|
+
):
|
|
178
|
+
"""
|
|
179
|
+
Generate upscaled image (alias for create with additional functionality).
|
|
180
|
+
|
|
181
|
+
Upscale image using AI. Each upscale costs 5 credits.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
185
|
+
assets: Provide the assets for image upscaler
|
|
186
|
+
scale_factor: How much to scale the image. Must be either 2 or 4.
|
|
187
|
+
style: Image upscaling parameters
|
|
188
|
+
wait_for_completion: Whether to wait for the image project to complete
|
|
189
|
+
download_outputs: Whether to download the outputs
|
|
190
|
+
download_directory: The directory to download the outputs to. If not provided, the outputs will be downloaded to the current working directory
|
|
191
|
+
request_options: Additional options to customize the HTTP request
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
V1ImageProjectsGetResponseWithDownloads: The response from the AI Image Upscaler API with the downloaded paths if `download_outputs` is True.
|
|
195
|
+
|
|
196
|
+
Examples:
|
|
197
|
+
```py
|
|
198
|
+
response = await client.v1.ai_image_upscaler.generate(
|
|
199
|
+
assets={"image_file_path": "path/to/image.png"},
|
|
200
|
+
scale_factor=2.0,
|
|
201
|
+
style={"enhancement": "Balanced"},
|
|
202
|
+
name="Upscaled Image",
|
|
203
|
+
wait_for_completion=True,
|
|
204
|
+
download_outputs=True,
|
|
205
|
+
download_directory="outputs/",
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
file_client = AsyncFilesClient(base_client=self._base_client)
|
|
211
|
+
|
|
212
|
+
image_file_path = assets["image_file_path"]
|
|
213
|
+
assets["image_file_path"] = await file_client.upload_file(file=image_file_path)
|
|
214
|
+
|
|
215
|
+
create_response = await self.create(
|
|
216
|
+
assets=assets,
|
|
217
|
+
scale_factor=scale_factor,
|
|
218
|
+
style=style,
|
|
219
|
+
name=name,
|
|
220
|
+
request_options=request_options,
|
|
221
|
+
)
|
|
222
|
+
logger.info(f"AI Image Upscaler response: {create_response}")
|
|
223
|
+
|
|
224
|
+
image_projects_client = AsyncImageProjectsClient(base_client=self._base_client)
|
|
225
|
+
response = await image_projects_client.check_result(
|
|
226
|
+
id=create_response.id,
|
|
227
|
+
wait_for_completion=wait_for_completion,
|
|
228
|
+
download_outputs=download_outputs,
|
|
229
|
+
download_directory=download_directory,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
return response
|
|
233
|
+
|
|
83
234
|
async def create(
|
|
84
235
|
self,
|
|
85
236
|
*,
|
|
86
|
-
assets: params.
|
|
237
|
+
assets: params.V1AiImageUpscalerCreateBodyAssets,
|
|
87
238
|
scale_factor: float,
|
|
88
|
-
style: params.
|
|
239
|
+
style: params.V1AiImageUpscalerCreateBodyStyle,
|
|
89
240
|
name: typing.Union[
|
|
90
241
|
typing.Optional[str], type_utils.NotGiven
|
|
91
242
|
] = type_utils.NOT_GIVEN,
|
|
92
243
|
request_options: typing.Optional[RequestOptions] = None,
|
|
93
|
-
) -> models.
|
|
244
|
+
) -> models.V1AiImageUpscalerCreateResponse:
|
|
94
245
|
"""
|
|
95
246
|
AI Image Upscaler
|
|
96
247
|
|
|
97
|
-
Upscale your image using AI. Each 2x upscale costs 50
|
|
248
|
+
Upscale your image using AI. Each 2x upscale costs 50 credits, and 4x upscale costs 200 credits.
|
|
98
249
|
|
|
99
250
|
POST /v1/ai-image-upscaler
|
|
100
251
|
|
|
101
252
|
Args:
|
|
102
|
-
name: The name of image
|
|
253
|
+
name: The name of image. This value is mainly used for your own identification of the image.
|
|
103
254
|
assets: Provide the assets for upscaling
|
|
104
|
-
scale_factor: How much to scale the image. Must be either 2 or 4
|
|
105
|
-
|
|
255
|
+
scale_factor: How much to scale the image. Must be either 2 or 4.
|
|
256
|
+
|
|
257
|
+
Note: 4x upscale is only available on Creator, Pro, or Business tier.
|
|
258
|
+
style: V1AiImageUpscalerCreateBodyStyle
|
|
106
259
|
request_options: Additional options to customize the HTTP request
|
|
107
260
|
|
|
108
261
|
Returns:
|
|
@@ -129,13 +282,13 @@ class AsyncAiImageUpscalerClient:
|
|
|
129
282
|
"scale_factor": scale_factor,
|
|
130
283
|
"style": style,
|
|
131
284
|
},
|
|
132
|
-
dump_with=params.
|
|
285
|
+
dump_with=params._SerializerV1AiImageUpscalerCreateBody,
|
|
133
286
|
)
|
|
134
287
|
return await self._base_client.request(
|
|
135
288
|
method="POST",
|
|
136
289
|
path="/v1/ai-image-upscaler",
|
|
137
290
|
auth_names=["bearerAuth"],
|
|
138
291
|
json=_json,
|
|
139
|
-
cast_to=models.
|
|
292
|
+
cast_to=models.V1AiImageUpscalerCreateResponse,
|
|
140
293
|
request_options=request_options or default_request_options(),
|
|
141
294
|
)
|