diff --git a/README.md b/README.md index bcc6b40..ca92f45 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ The SDK needs to be configured with an API key which is available [here](https:/ ```python from imagine import Imagine -from imagine.styles import GenerationsStyle -from imagine.models import Status +from imagine.enums import Styles +from imagine.enums import Status # Initialize the Imagine client with your API token client = Imagine(token="your-api-token") @@ -42,7 +42,7 @@ response = client.generations( A vibrant and whimsical fantasy forest with magical creatures, glowing plants, and a flowing river, in a digital painting style inspired by video games like Ori and the Blind Forest. ''', - style=GenerationsStyle.IMAGINE_V5, + style=Styles.Generations.IMAGINE_V5, ) # Check if the request was successful @@ -61,11 +61,11 @@ else: The Imagine class acts as a facade, providing an interface to interact with all of our endpoints. It currently provides the following features: -- **Text-To-Image**: `generations() -> Response[Image]` -- **Image-Remix**: `image_remix() -> Response[Image]` -- **Super-Resolution**: `super_resolution() -> Response[Image]` -- **Variations**: `variations() -> Response[Image]` (_Currently Not Supported_) -- **In-Painting**: `in_painting() -> Response[Image]` (_Currently Not Supported_) +- **Generations**: `generations() -> Response[Image]` +- **Background**: `background() -> Response[Image]` +- **Edits**: `edits() -> Response[Image]` +- **Enhance**: `enhance() -> Response[Image]` +- **Face**: `face() -> Response[Image]` For the full list of parameters and other details, check out the [documentation](https://vyroai.notion.site/API-Documentation-e643af82991f4265841cff2951eac803). @@ -108,71 +108,6 @@ The module is loaded dynamically and is not included in the default package, you The module is loaded dynamically and is not included in the default package, you can choose to forgo this dependency. [See this](#integration-with-other-libraries) for more information. -### Some More Usage Examples - -#### Variations - -> Currently Not Supported - -```python -from imagine import Imagine -from imagine.styles import GenerationsStyle -from imagine.models import Status - -# Initialize the Imagine client with your API token -client = Imagine(token="your-api-token") - -# Generate an image using the variations feature -response = client.variate( - image_path="anime_girl.png", - prompt="a cute anime girl in a forest", - style=GenerationStyle.ANIME, -) - -# Check if the request was successful -if response.status == Status.OK: - image = response.data - image.as_file("result.png") -else: - print(f"Status Code: {response.status.value}") -``` - -**Result**: - -![Variate](https://vyroai.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7a2a54f2-c762-45ea-a1bd-c655ed421caa%2Fbanner_2.png?table=block&id=d60f4549-e35c-4044-afaa-7cd9d17803a2&spaceId=60572bb8-cbeb-42ba-b882-c88845384d44&width=2000&userId=&cache=v2) - -#### In-Painting - -> Currently Not Supported - -```python -from imagine import Imagine -from imagine.styles import InPaintingStyle -from imagine.models import Status - -# Initialize the Imagine client with your API token -client = Imagine(token="your-api-token") - -# Generate an image using the in_painting feature -response = client.in_painting( - image_path="couple.png", - mask_path="mask.png", - prompt="woman sitting next to a teddy bear", - style=InPaintingStyle.BASIC, -) - -# Check if the request was successful -if response.status == Status.OK: - image = response.data - image.as_file("result.png") -else: - print(f"Status Code: {response.status.value}") - -``` - -**Result**: -![InPainting](https://vyroai.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7017cedd-aeda-4a3e-ad09-54eb8b93399d%2Finpainting.jpg?table=block&id=1bc58f0f-1d7f-465f-b414-200ceb2464b1&spaceId=60572bb8-cbeb-42ba-b882-c88845384d44&width=2000&userId=&cache=v2) - ## Integration With Other Libraries The Imagine SDK has two levels of dependencies. By default, only the requests library is shipped as a dependency. If you want to use Pillow and Numpy as well, execute the following command: diff --git a/docs/imagine.constants.rst b/docs/imagine.constants.rst new file mode 100644 index 0000000..7197111 --- /dev/null +++ b/docs/imagine.constants.rst @@ -0,0 +1,21 @@ +imagine.constants package +========================= + +Submodules +---------- + +imagine.constants.filters module +-------------------------------- + +.. automodule:: imagine.constants.filters + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.constants + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.enums.rst b/docs/imagine.enums.rst new file mode 100644 index 0000000..2e1bd5d --- /dev/null +++ b/docs/imagine.enums.rst @@ -0,0 +1,53 @@ +imagine.enums package +===================== + +Submodules +---------- + +imagine.enums.aspect\_ratio module +---------------------------------- + +.. automodule:: imagine.enums.aspect_ratio + :members: + :undoc-members: + :show-inheritance: + +imagine.enums.controls module +----------------------------- + +.. automodule:: imagine.enums.controls + :members: + :undoc-members: + :show-inheritance: + +imagine.enums.filters module +---------------------------- + +.. automodule:: imagine.enums.filters + :members: + :undoc-members: + :show-inheritance: + +imagine.enums.status module +--------------------------- + +.. automodule:: imagine.enums.status + :members: + :undoc-members: + :show-inheritance: + +imagine.enums.styles module +--------------------------- + +.. automodule:: imagine.enums.styles + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.enums + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.background.remover.rst b/docs/imagine.features.background.remover.rst new file mode 100644 index 0000000..7b3aa87 --- /dev/null +++ b/docs/imagine.features.background.remover.rst @@ -0,0 +1,21 @@ +imagine.features.background.remover package +=========================================== + +Submodules +---------- + +imagine.features.background.remover.handler module +-------------------------------------------------- + +.. automodule:: imagine.features.background.remover.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.background.remover + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.background.rst b/docs/imagine.features.background.rst new file mode 100644 index 0000000..af61432 --- /dev/null +++ b/docs/imagine.features.background.rst @@ -0,0 +1,29 @@ +imagine.features.background package +=================================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.features.background.remover + +Submodules +---------- + +imagine.features.background.handler module +------------------------------------------ + +.. automodule:: imagine.features.background.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.background + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.edits.filters.rst b/docs/imagine.features.edits.filters.rst new file mode 100644 index 0000000..f7f543f --- /dev/null +++ b/docs/imagine.features.edits.filters.rst @@ -0,0 +1,21 @@ +imagine.features.edits.filters package +====================================== + +Submodules +---------- + +imagine.features.edits.filters.handler module +--------------------------------------------- + +.. automodule:: imagine.features.edits.filters.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.edits.filters + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.edits.inpaint.rst b/docs/imagine.features.edits.inpaint.rst new file mode 100644 index 0000000..1e2e8e6 --- /dev/null +++ b/docs/imagine.features.edits.inpaint.rst @@ -0,0 +1,21 @@ +imagine.features.edits.inpaint package +====================================== + +Submodules +---------- + +imagine.features.edits.inpaint.handler module +--------------------------------------------- + +.. automodule:: imagine.features.edits.inpaint.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.edits.inpaint + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.edits.remix.remix.rst b/docs/imagine.features.edits.remix.remix.rst new file mode 100644 index 0000000..fb6fe04 --- /dev/null +++ b/docs/imagine.features.edits.remix.remix.rst @@ -0,0 +1,21 @@ +imagine.features.edits.remix.remix package +========================================== + +Submodules +---------- + +imagine.features.edits.remix.remix.handler module +------------------------------------------------- + +.. automodule:: imagine.features.edits.remix.remix.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.edits.remix.remix + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.edits.remix.rst b/docs/imagine.features.edits.remix.rst new file mode 100644 index 0000000..18c1adb --- /dev/null +++ b/docs/imagine.features.edits.remix.rst @@ -0,0 +1,29 @@ +imagine.features.edits.remix package +==================================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.features.edits.remix.remix + +Submodules +---------- + +imagine.features.edits.remix.handler module +------------------------------------------- + +.. automodule:: imagine.features.edits.remix.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.edits.remix + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.edits.rst b/docs/imagine.features.edits.rst new file mode 100644 index 0000000..10a54e4 --- /dev/null +++ b/docs/imagine.features.edits.rst @@ -0,0 +1,31 @@ +imagine.features.edits package +============================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.features.edits.filters + imagine.features.edits.inpaint + imagine.features.edits.remix + +Submodules +---------- + +imagine.features.edits.handler module +------------------------------------- + +.. automodule:: imagine.features.edits.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.edits + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.enhance.rst b/docs/imagine.features.enhance.rst new file mode 100644 index 0000000..a6a0caf --- /dev/null +++ b/docs/imagine.features.enhance.rst @@ -0,0 +1,29 @@ +imagine.features.enhance package +================================ + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.features.enhance.upsacle + +Submodules +---------- + +imagine.features.enhance.handler module +--------------------------------------- + +.. automodule:: imagine.features.enhance.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.enhance + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.enhance.upsacle.rst b/docs/imagine.features.enhance.upsacle.rst new file mode 100644 index 0000000..62102d8 --- /dev/null +++ b/docs/imagine.features.enhance.upsacle.rst @@ -0,0 +1,21 @@ +imagine.features.enhance.upsacle package +======================================== + +Submodules +---------- + +imagine.features.enhance.upsacle.handler module +----------------------------------------------- + +.. automodule:: imagine.features.enhance.upsacle.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.enhance.upsacle + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.face.headshot.rst b/docs/imagine.features.face.headshot.rst new file mode 100644 index 0000000..cbb7fc1 --- /dev/null +++ b/docs/imagine.features.face.headshot.rst @@ -0,0 +1,21 @@ +imagine.features.face.headshot package +====================================== + +Submodules +---------- + +imagine.features.face.headshot.handler module +--------------------------------------------- + +.. automodule:: imagine.features.face.headshot.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.face.headshot + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.face.rst b/docs/imagine.features.face.rst new file mode 100644 index 0000000..9bfb7ea --- /dev/null +++ b/docs/imagine.features.face.rst @@ -0,0 +1,29 @@ +imagine.features.face package +============================= + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.features.face.headshot + +Submodules +---------- + +imagine.features.face.handler module +------------------------------------ + +.. automodule:: imagine.features.face.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.face + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.generations.background.rst b/docs/imagine.features.generations.background.rst new file mode 100644 index 0000000..c6ef466 --- /dev/null +++ b/docs/imagine.features.generations.background.rst @@ -0,0 +1,21 @@ +imagine.features.generations.background package +=============================================== + +Submodules +---------- + +imagine.features.generations.background.handler module +------------------------------------------------------ + +.. automodule:: imagine.features.generations.background.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.generations.background + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.generations.generations.rst b/docs/imagine.features.generations.generations.rst new file mode 100644 index 0000000..55101ca --- /dev/null +++ b/docs/imagine.features.generations.generations.rst @@ -0,0 +1,21 @@ +imagine.features.generations.generations package +================================================ + +Submodules +---------- + +imagine.features.generations.generations.handler module +------------------------------------------------------- + +.. automodule:: imagine.features.generations.generations.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.generations.generations + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.generations.rst b/docs/imagine.features.generations.rst index 38775bc..a08cc3d 100644 --- a/docs/imagine.features.generations.rst +++ b/docs/imagine.features.generations.rst @@ -1,31 +1,31 @@ -imagine.features.generations package -==================================== - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - imagine.features.generations.variations - -imagine.features.generations.handler module -------------------------------------------- - -.. automodule:: imagine.features.generations.handler - :members: - :undoc-members: - :show-inheritance: - -imagine.features.generations.style\_ids module ----------------------------------------------- - -.. automodule:: imagine.features.generations.style_ids - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.features.generations - :members: - :undoc-members: - :show-inheritance: +imagine.features.generations package +==================================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.features.generations.background + imagine.features.generations.generations + imagine.features.generations.variations + +Submodules +---------- + +imagine.features.generations.handler module +------------------------------------------- + +.. automodule:: imagine.features.generations.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.generations + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.generations.variations.rst b/docs/imagine.features.generations.variations.rst index aaf1c5d..e24d718 100644 --- a/docs/imagine.features.generations.variations.rst +++ b/docs/imagine.features.generations.variations.rst @@ -1,15 +1,21 @@ -imagine.features.generations.variations package -=============================================== - -imagine.features.generations.variations.handler module ------------------------------------------------------- - -.. automodule:: imagine.features.generations.variations.handler - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.features.generations.variations - :members: - :undoc-members: - :show-inheritance: +imagine.features.generations.variations package +=============================================== + +Submodules +---------- + +imagine.features.generations.variations.handler module +------------------------------------------------------ + +.. automodule:: imagine.features.generations.variations.handler + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.features.generations.variations + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.image_remix.rst b/docs/imagine.features.image_remix.rst deleted file mode 100644 index db23f11..0000000 --- a/docs/imagine.features.image_remix.rst +++ /dev/null @@ -1,31 +0,0 @@ -imagine.features.image\_remix package -===================================== - -imagine.features.image\_remix.controls module ---------------------------------------------- - -.. automodule:: imagine.features.image_remix.controls - :members: - :undoc-members: - :show-inheritance: - -imagine.features.image\_remix.handler module --------------------------------------------- - -.. automodule:: imagine.features.image_remix.handler - :members: - :undoc-members: - :show-inheritance: - -imagine.features.image\_remix.style\_ids module ------------------------------------------------ - -.. automodule:: imagine.features.image_remix.style_ids - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.features.image_remix - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/imagine.features.in_painting.rst b/docs/imagine.features.in_painting.rst deleted file mode 100644 index 3a735a7..0000000 --- a/docs/imagine.features.in_painting.rst +++ /dev/null @@ -1,23 +0,0 @@ -imagine.features.in\_painting package -===================================== - -imagine.features.in\_painting.handler module --------------------------------------------- - -.. automodule:: imagine.features.in_painting.handler - :members: - :undoc-members: - :show-inheritance: - -imagine.features.in\_painting.style\_ids module ------------------------------------------------ - -.. automodule:: imagine.features.in_painting.style_ids - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.features.in_painting - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/imagine.features.rst b/docs/imagine.features.rst index 70105c7..46c779b 100644 --- a/docs/imagine.features.rst +++ b/docs/imagine.features.rst @@ -1,18 +1,22 @@ -imagine.features package -======================== - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - imagine.features.generations - imagine.features.image_remix - imagine.features.in_painting - imagine.features.super_resolution - -.. automodule:: imagine.features - :members: - :undoc-members: - :show-inheritance: +imagine.features package +======================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.features.background + imagine.features.edits + imagine.features.enhance + imagine.features.face + imagine.features.generations + +Module contents +--------------- + +.. automodule:: imagine.features + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.features.super_resolution.rst b/docs/imagine.features.super_resolution.rst deleted file mode 100644 index 342ac79..0000000 --- a/docs/imagine.features.super_resolution.rst +++ /dev/null @@ -1,23 +0,0 @@ -imagine.features.super\_resolution package -========================================== - -imagine.features.super\_resolution.handler module -------------------------------------------------- - -.. automodule:: imagine.features.super_resolution.handler - :members: - :undoc-members: - :show-inheritance: - -imagine.features.super\_resolution.style\_ids module ----------------------------------------------------- - -.. automodule:: imagine.features.super_resolution.style_ids - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.features.super_resolution - :members: - :undoc-members: - :show-inheritance: diff --git a/docs/imagine.models.rst b/docs/imagine.models.rst index b8dd7a9..fb29e13 100644 --- a/docs/imagine.models.rst +++ b/docs/imagine.models.rst @@ -1,32 +1,29 @@ -imagine.models package -====================== - - -imagine.models.image module ---------------------------- - -.. automodule:: imagine.models.image - :members: - :undoc-members: - :show-inheritance: - -imagine.models.response module ------------------------------- - -.. automodule:: imagine.models.response - :members: - :undoc-members: - :show-inheritance: - -imagine.models.status module ----------------------------- - -.. automodule:: imagine.models.status - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.models - :members: - :undoc-members: - :show-inheritance: +imagine.models package +====================== + +Submodules +---------- + +imagine.models.image module +--------------------------- + +.. automodule:: imagine.models.image + :members: + :undoc-members: + :show-inheritance: + +imagine.models.response module +------------------------------ + +.. automodule:: imagine.models.response + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.models + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.remote.rest.rst b/docs/imagine.remote.rest.rst index e2b1176..47244d3 100644 --- a/docs/imagine.remote.rest.rst +++ b/docs/imagine.remote.rest.rst @@ -1,15 +1,21 @@ -imagine.remote.rest package -=========================== - -imagine.remote.rest.http\_client module ---------------------------------------- - -.. automodule:: imagine.remote.rest.http_client - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.remote.rest - :members: - :undoc-members: - :show-inheritance: +imagine.remote.rest package +=========================== + +Submodules +---------- + +imagine.remote.rest.http\_client module +--------------------------------------- + +.. automodule:: imagine.remote.rest.http_client + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.remote.rest + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.remote.rst b/docs/imagine.remote.rst index b6302b6..67c5f65 100644 --- a/docs/imagine.remote.rst +++ b/docs/imagine.remote.rst @@ -1,24 +1,29 @@ -imagine.remote package -====================== - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - imagine.remote.rest - - -imagine.remote.http\_client module ----------------------------------- - -.. automodule:: imagine.remote.http_client - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.remote - :members: - :undoc-members: - :show-inheritance: +imagine.remote package +====================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.remote.rest + +Submodules +---------- + +imagine.remote.http\_client module +---------------------------------- + +.. automodule:: imagine.remote.http_client + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.remote + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.rst b/docs/imagine.rst index b428121..9d62b42 100644 --- a/docs/imagine.rst +++ b/docs/imagine.rst @@ -1,27 +1,35 @@ -imagine package -=============== - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - imagine.features - imagine.models - imagine.remote - imagine.type - imagine.utils - -imagine.client module ---------------------- - -.. automodule:: imagine.client - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine - :members: - :undoc-members: - :show-inheritance: +imagine package +=============== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.constants + imagine.enums + imagine.features + imagine.models + imagine.remote + imagine.type + imagine.utils + +Submodules +---------- + +imagine.client module +--------------------- + +.. automodule:: imagine.client + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.type.rst b/docs/imagine.type.rst index 66dca8a..6a46538 100644 --- a/docs/imagine.type.rst +++ b/docs/imagine.type.rst @@ -1,15 +1,21 @@ -imagine.type package -==================== - -imagine.type.multipart module ------------------------------ - -.. automodule:: imagine.type.multipart - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.type - :members: - :undoc-members: - :show-inheritance: +imagine.type package +==================== + +Submodules +---------- + +imagine.type.multipart module +----------------------------- + +.. automodule:: imagine.type.multipart + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.type + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.utils.error.rst b/docs/imagine.utils.error.rst index 189343f..6e712ed 100644 --- a/docs/imagine.utils.error.rst +++ b/docs/imagine.utils.error.rst @@ -1,16 +1,21 @@ -imagine.utils.error package -=========================== - - -imagine.utils.error.checker module ----------------------------------- - -.. automodule:: imagine.utils.error.checker - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.utils.error - :members: - :undoc-members: - :show-inheritance: +imagine.utils.error package +=========================== + +Submodules +---------- + +imagine.utils.error.checker module +---------------------------------- + +.. automodule:: imagine.utils.error.checker + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.utils.error + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.utils.file.rst b/docs/imagine.utils.file.rst index fab0df9..8e83045 100644 --- a/docs/imagine.utils.file.rst +++ b/docs/imagine.utils.file.rst @@ -1,15 +1,21 @@ -imagine.utils.file package -========================== - -imagine.utils.file.read module ------------------------------- - -.. automodule:: imagine.utils.file.read - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.utils.file - :members: - :undoc-members: - :show-inheritance: +imagine.utils.file package +========================== + +Submodules +---------- + +imagine.utils.file.read module +------------------------------ + +.. automodule:: imagine.utils.file.read + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.utils.file + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.utils.imports.rst b/docs/imagine.utils.imports.rst index b9f3359..189975b 100644 --- a/docs/imagine.utils.imports.rst +++ b/docs/imagine.utils.imports.rst @@ -1,15 +1,21 @@ -imagine.utils.imports package -============================= - -imagine.utils.imports.dynamic module ------------------------------------- - -.. automodule:: imagine.utils.imports.dynamic - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.utils.imports - :members: - :undoc-members: - :show-inheritance: +imagine.utils.imports package +============================= + +Submodules +---------- + +imagine.utils.imports.dynamic module +------------------------------------ + +.. automodule:: imagine.utils.imports.dynamic + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.utils.imports + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.utils.parameter.rst b/docs/imagine.utils.parameter.rst index 19f86c0..0321705 100644 --- a/docs/imagine.utils.parameter.rst +++ b/docs/imagine.utils.parameter.rst @@ -1,23 +1,29 @@ -imagine.utils.parameter package -=============================== - -imagine.utils.parameter.checker module --------------------------------------- - -.. automodule:: imagine.utils.parameter.checker - :members: - :undoc-members: - :show-inheritance: - -imagine.utils.parameter.multipart module ----------------------------------------- - -.. automodule:: imagine.utils.parameter.multipart - :members: - :undoc-members: - :show-inheritance: - -.. automodule:: imagine.utils.parameter - :members: - :undoc-members: - :show-inheritance: +imagine.utils.parameter package +=============================== + +Submodules +---------- + +imagine.utils.parameter.checker module +-------------------------------------- + +.. automodule:: imagine.utils.parameter.checker + :members: + :undoc-members: + :show-inheritance: + +imagine.utils.parameter.multipart module +---------------------------------------- + +.. automodule:: imagine.utils.parameter.multipart + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: imagine.utils.parameter + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/imagine.utils.rst b/docs/imagine.utils.rst index 8d37c2f..c09e95a 100644 --- a/docs/imagine.utils.rst +++ b/docs/imagine.utils.rst @@ -1,18 +1,21 @@ -imagine.utils package -===================== - -Subpackages ------------ - -.. toctree:: - :maxdepth: 4 - - imagine.utils.error - imagine.utils.file - imagine.utils.imports - imagine.utils.parameter - -.. automodule:: imagine.utils - :members: - :undoc-members: - :show-inheritance: +imagine.utils package +===================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + imagine.utils.error + imagine.utils.file + imagine.utils.imports + imagine.utils.parameter + +Module contents +--------------- + +.. automodule:: imagine.utils + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/modules.rst b/docs/modules.rst new file mode 100644 index 0000000..1df3443 --- /dev/null +++ b/docs/modules.rst @@ -0,0 +1,7 @@ +imagine +======= + +.. toctree:: + :maxdepth: 4 + + imagine diff --git a/docs/usage.rst b/docs/usage.rst index 6dd1b99..de3d6c4 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -6,8 +6,7 @@ The SDK needs to be configured with an API key which is available `here `_ acts as a facade, providing an interface to interact with all of our endpoints. It currently provides the following features: -- **Text-To-Image**: ``generations() -> Response[Image]`` -- **Image-Remix**: ``image_remix() -> Response[Image]`` -- **Super-Resolution**: ``super_resolution() -> Response[Image]`` -- **Variations**: ``variations() -> Response[Image]`` `(Currently Not Supported)` -- **In-Painting**: ``in_painting() -> Response[Image]`` `(Currently Not Supported)` +- **Generations**: ``generations() -> Response[Image]`` +- **Background**: ``background() -> Response[Image]`` +- **Edits**: ``edits() -> Response[Image]`` +- **Enhance**: ``enhance() -> Response[Image]`` +- **Face**: ``face() -> Response[Image]`` For the full list of parameters and other details, check out the `documentation `_. @@ -91,74 +90,3 @@ For more details on this function, check out the `documentation `_ for more information. For more details on this function, check out the `documentation `_. - -Some More Usage Examples -~~~~~~~~~~~~~~~~~~~~~~~~ - -**Variations** - -.. note:: - - Currently Not Supported - -.. code-block:: python - - from imagine.client import Imagine - from imagine.features.generations.style_ids import GenerationsStyle - from imagine.models.status import Status - - # Initialize the Imagine client with your API token - client = Imagine(token="your-api-token") - - # Generate an image using the variations feature - response = client.variate( - image_path="anime_girl.png", - prompt="a cute anime girl in a forest", - style=GenerationStyle.ANIME, - ) - - # Check if the request was successful - if response.status == Status.OK: - image = response.data - image.as_file("result.png") - else: - print(f"Status Code: {response.status.value}") - -**Result**: - -.. image:: https://vyroai.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7a2a54f2-c762-45ea-a1bd-c655ed421caa%2Fbanner_2.png?table=block&id=d60f4549-e35c-4044-afaa-7cd9d17803a2&spaceId=60572bb8-cbeb-42ba-b882-c88845384d44&width=2000&userId=&cache=v2 - :alt: Variate - -**In-Painting** - -.. note:: - - Currently Not Supported - -.. code-block:: python - - from imagine.client import Imagine - from imagine.features.in_painting.style_ids import InPaintingStyle - from imagine.models.status import Status - - # Initialize the Imagine client with your API token - client = Imagine(token="your-api-token") - - # Generate an image using the in_painting feature - response = client.in_painting( - image_path="couple.png", - mask_path="mask.png", - prompt="woman sitting next to a teddy bear", - style=InPaintingStyle.BASIC, - ) - - # Checking the request status - if response.status == Status.OK: - image = response.data - image.as_file("result.png") - else: - print(f"Status Code: {response.status.value}") - -**Result**: - -.. image:: https://vyroai.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7017cedd-aeda-4a3e-ad09-54eb8b93399d%2Finpainting.jpg?table=block&id=1bc58f0f-1d7f-465f-b414-200ceb2464b1&spaceId=60572bb8-cbeb-42ba-b882-c88845384d44&width=2000&userId=&cache=v2 diff --git a/src/imagine/aspect_ratios/__init__.py b/src/imagine/aspect_ratios/__init__.py deleted file mode 100644 index e8d656f..0000000 --- a/src/imagine/aspect_ratios/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from ..features.aspect_ratio import AspectRatio - -__all__ = [ - "AspectRatio" -] diff --git a/src/imagine/client.py b/src/imagine/client.py index fc26c71..5af8ebf 100644 --- a/src/imagine/client.py +++ b/src/imagine/client.py @@ -1,18 +1,11 @@ from typing import Optional -from .features.aspect_ratio import AspectRatio -from .features.generations.handler import GenerationsHandler -from .features.image_remix.handler import ImageRemixHandler -from .features.in_painting.handler import InPaintHandler -from .features.super_resolution.handler import SuperResolutionHandler -from .features.generations.variations.handler import VariationsHandler -from .features.generations.style_ids import GenerationsStyle -from .features.image_remix.controls import RemixControls -from .features.image_remix.style_ids import ImageRemixStyle -from .features.in_painting.style_ids import InPaintingStyle -from .features.super_resolution.style_ids import SuperResolutionStyle -from .models.image import Image -from .models.response import Response +from .features.generations.handler import Generations +from .features.background.handler import Background +from .features.edits.handler import Edits +from .features.enhance.handler import Enhance +from .features.face.handler import Face + from .remote.http_client import HttpClient from .remote.rest.http_client import RestClient @@ -27,11 +20,11 @@ class Imagine: __client: HttpClient - __generations_handler: GenerationsHandler - __image_remix_handler: ImageRemixHandler - __super_resolution_handler: SuperResolutionHandler - __variations_handler: VariationsHandler - __in_paint_handler: InPaintHandler + __generations_handler: Generations + __background_handler: Background + __edits_handler: Edits + __enhance_handler: Enhance + __face_handler: Face def __init__(self, token: str, *, client: Optional[HttpClient] = None) -> None: """ @@ -44,210 +37,73 @@ def __init__(self, token: str, *, client: Optional[HttpClient] = None) -> None: """ self.__client = RestClient(token, client) - self.__generations_handler = GenerationsHandler(self.__client) - self.__image_remix_handler = ImageRemixHandler(self.__client) - self.__super_resolution_handler = SuperResolutionHandler(self.__client) - self.__variations_handler = VariationsHandler(self.__client) - self.__in_paint_handler = InPaintHandler(self.__client) - - def generations( - self, - prompt: str, - *, - style: GenerationsStyle = GenerationsStyle.IMAGINE_V1, - aspect_ratio: AspectRatio = AspectRatio.ONE_RATIO_ONE, - neg_prompt: Optional[str] = None, - cfg: Optional[float] = None, - seed: Optional[int] = None, - steps: Optional[int] = None, - high_res_results: bool = False, - ) -> Response[Image]: + self.__generations_handler = Generations(self.__client) + self.__background_handler = Background(self.__client) + self.__edits_handler = Edits(self.__client) + self.__enhance_handler = Enhance(self.__client) + self.__face_handler = Face(self.__client) + + @property + def generations(self) -> Generations: """ - Generate an image based on specified parameters using the - GenerationsHandler. - - :param prompt: The prompt for generating the image. - :type prompt: str - :param style: The style for the image generation (default: - GenerationsStyle.STYLE_IMAGINE_V1). - :type style: :class:`GenerationsStyle` - :param aspect_ratio: The aspect ratio of the image (default: None). - :type aspect_ratio: Optional[str] - :param neg_prompt: The negative prompt for contrasting images (default: None). - :type neg_prompt: Optional[str] - :param cfg: The cfg parameter for image generation (default: None). - :type cfg: Optional[float] - :param seed: The random seed for reproducible generation (default: None). - :type seed: Optional[int] - :param steps: The number of steps for generating the image (default: None). - :type steps: Optional[int] - :param high_res_results: The level of high-resolution results (default: False). - :type high_res_results: bool - :return: A response containing the generated error or an :class:`Image` - object. - :rtype: :class:`Response`[:class:`Image`] + Instances of all the methods that do generations + + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + + :return: An instance of the Generations handler. + :rtype: class:Generations """ - return self.__generations_handler( - prompt=prompt, - style_id=style.value, - aspect_ratio=aspect_ratio.value, - cfg=cfg, - seed=seed, - neg_prompt=neg_prompt, - high_res_results=int(high_res_results), - steps=steps, - ) - - def image_remix( - self, - image_path: str, - prompt: str, - *, - style: ImageRemixStyle = ImageRemixStyle.IMAGINE_V1, - control: RemixControls = RemixControls.OPENPOSE, - seed: Optional[int] = None, - strength: Optional[int] = None, - steps: Optional[int] = None, - cfg: Optional[float] = None, - neg_prompt: Optional[str] = None, - ) -> Response[Image]: + return self.__generations_handler + + @property + def background(self) -> Background: """ - Remix an image based on specified parameters using the - ImageRemixHandler. - - :param image_path: The path to the source image. - :type image_path: str - :param prompt: The prompt for remixing the image. - :type prompt: str - :param style: The style for the image remixing (default: - ImageRemixStyle.STYLE_IMAGINE_V1). - :type style: :class:`ImageRemixStyle` - :param control: The control settings for remixing (default: - RemixControls.OPENPOSE). - :type control: :class:`RemixControls` - :param seed: The random seed for reproducible remixing (default: None). - :type seed: Optional[int] - :param strength: The strength of the remixing effect (default: None). - :type strength: Optional[int] - :param steps: The number of steps for remixing the image (default: None). - :type steps: Optional[int] - :param cfg: The cfg parameter for remixing (default: None). - :type cfg: Optional[float] - :param neg_prompt: The negative prompt for remixing (default: None). - :type neg_prompt: Optional[str] - :return: A response containing the generated error or an :class:`Image` - object. - :rtype: :class:`Response`[:class:`Image`] + Instances of all the methods to interact with the background of an image + + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + + :return: An instance of the Background handler. + :rtype: class:Background """ - return self.__image_remix_handler( - prompt=prompt, - image_path=image_path, - style_id=style.value, - control=control.value, - seed=seed, - strength=strength, - steps=steps, - cfg=cfg, - neg_prompt=neg_prompt, - ) - - def super_resolution( - self, - image_path: str, - *, - style: SuperResolutionStyle = SuperResolutionStyle.BASIC, - ) -> Response[Image]: + return self.__background_handler + + @property + def edits(self) -> Edits: """ - Enhance the resolution of an image using the SuperResolutionHandler. - - :param image_path: The path to the source image. - :type image_path: str - :param style: The model version for super resolution. - :type style: :class:SuperResolutionStyle - :return: A response containing the generated error or an :class:`Image` - object. - :rtype: :class:`Response`[:class:`Image`] + Instances of all the methods to edit an image + + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + + :return: An instance of the Edits handler. + :rtype: class:Edits """ - return self.__super_resolution_handler( - image_path=image_path, - model_version=style.value - ) - - def variations( - self, - image_path: str, - prompt: str, - *, - style: GenerationsStyle = GenerationsStyle.IMAGINE_V1, - seed: Optional[int] = None, - steps: Optional[int] = None, - strength: Optional[int] = None, - cfg: Optional[float] = None, - neg_prompt: Optional[str] = None, - ) -> Response[Image]: + return self.__edits_handler + + @property + def enhance(self) -> Enhance: """ - Generate a variation of an image based on specified parameters using - the VariateHandler. It is an extension of generations hence why it - uses the same styles as Generations. - - :param image_path: The path to the source image. - :type image_path: str - :param prompt: The prompt for generating the variation. - :type prompt: str - :param style: The style for generating the variation. - :type style: :class:`GenerationsStyle` - :param seed: The random seed for reproducible generation. - :type seed: Optional[int] - :param steps: The number of steps for generating the variation. - :type steps: Optional[int] - :param strength: The strength of the variation effect. - :type strength: Optional[int] - :param cfg: The cfg parameter for generating the variation. - :type cfg: Optional[float] - :param neg_prompt: The negative prompt for contrasting variations. - :type neg_prompt: Optional[str] - :return: A response containing the generated error or an :class:`Image` - object. - :rtype: :class:`Response`[:class:`Image`] + Instances of all the methods to enhance an image + + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + + :return: An instance of the Enhance handler. + :rtype: class:Enhance """ - return self.__variations_handler( - prompt=prompt, - image_path=image_path, - style_id=style.value, - strength=strength, - seed=seed, - steps=steps, - cfg=cfg, - neg_prompt=neg_prompt, - ) - - def in_painting( - self, - image_path: str, - mask_path: str, - prompt: str, - *, - style: InPaintingStyle = InPaintingStyle.BASIC, - ) -> Response[Image]: + return self.__enhance_handler + + @property + def face(self) -> Face: """ - Perform image in-painting based on specified parameters using the - InPaintHandler. - - :param image_path: The path to the source image. - :type image_path: str - :param mask_path: The path to the mask image for in-painting. - :type mask_path: str - :param prompt: The prompt for guiding the in-painting process. - :type prompt: str - :param style: The model version for in-painting. - :type style: :class:`InPaintingModel` - :return: A response containing the generated error or an :class:`Image` - object. - :rtype: :class:`Response`[:class:`Image`] + Instances of all the methods to edit a subject's image while maintaining facial identity + + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + + :return: An instance of the Face handler. + :rtype: class:Face """ - return self.__in_paint_handler( - prompt=prompt, - image_path=image_path, - mask_path=mask_path, - model_version=style.value, - ) + return self.__face_handler diff --git a/src/imagine/constants/__init__.py b/src/imagine/constants/__init__.py new file mode 100644 index 0000000..4cccce1 --- /dev/null +++ b/src/imagine/constants/__init__.py @@ -0,0 +1,4 @@ +from .filters import * + + +__all__ = [name for name in dir() if not name.startswith("_")] diff --git a/src/imagine/constants/filters.py b/src/imagine/constants/filters.py new file mode 100644 index 0000000..b866a9f --- /dev/null +++ b/src/imagine/constants/filters.py @@ -0,0 +1,2 @@ +DEFAULT_FILTER_ID = 1 +DEFAULT_STYLE_ID = 1 diff --git a/src/imagine/enums/__init__.py b/src/imagine/enums/__init__.py new file mode 100644 index 0000000..7a486f4 --- /dev/null +++ b/src/imagine/enums/__init__.py @@ -0,0 +1,13 @@ +from .aspect_ratio import AspectRatio +from .controls import Controls +from .filters import Filters +from .status import Status +from .styles import Styles + +__all__ = [ + "AspectRatio", + "Controls", + "Filters", + "Status", + "Styles", +] diff --git a/src/imagine/features/aspect_ratio.py b/src/imagine/enums/aspect_ratio.py similarity index 95% rename from src/imagine/features/aspect_ratio.py rename to src/imagine/enums/aspect_ratio.py index 404392b..761ccf5 100644 --- a/src/imagine/features/aspect_ratio.py +++ b/src/imagine/enums/aspect_ratio.py @@ -1,17 +1,18 @@ -from enum import Enum - - -class AspectRatio(Enum): - """ - Enums for supported aspect ratios - """ - ONE_RATIO_ONE = "1:1" - FOUR_RATIO_THREE = "4:3" - THREE_RATIO_TWO = "3:2" - TWO_RATIO_THREE = "2:3" - SIXTEEN_RATIO_NINE = "16:9" - NINE_RATIO_SIXTEEN = "9:16" - FIVE_RATIO_FOUR = "5:4" - FOUR_RATIO_FIVE = "4:5" - THREE_RATIO_ONE = "3:1" - THREE_RATIO_FOUR = "3:4" +from enum import Enum + + +class AspectRatio(Enum): + """ + Enums for supported aspect ratios + """ + + ONE_RATIO_ONE = "1:1" + FOUR_RATIO_THREE = "4:3" + THREE_RATIO_TWO = "3:2" + TWO_RATIO_THREE = "2:3" + SIXTEEN_RATIO_NINE = "16:9" + NINE_RATIO_SIXTEEN = "9:16" + FIVE_RATIO_FOUR = "5:4" + FOUR_RATIO_FIVE = "4:5" + THREE_RATIO_ONE = "3:1" + THREE_RATIO_FOUR = "3:4" diff --git a/src/imagine/enums/controls.py b/src/imagine/enums/controls.py new file mode 100644 index 0000000..b202fe6 --- /dev/null +++ b/src/imagine/enums/controls.py @@ -0,0 +1,14 @@ +from enum import Enum + + +class Controls: + class Remix(Enum): + """ + Enums for image_remix to guide image generation + """ + + OPENPOSE = "openpose" + SCRIBBLE = "scribble" + CANNY = "canny" + LINEART = "lineart" + DEPTH = "depth" diff --git a/src/imagine/enums/filters.py b/src/imagine/enums/filters.py new file mode 100644 index 0000000..c2f9b79 --- /dev/null +++ b/src/imagine/enums/filters.py @@ -0,0 +1,18 @@ +from enum import Enum + + +class Filters(Enum): + """ + Filter ids for Filters endpoint + """ + + VAN_GOUH = 1001 + POP_ART = 1002 + CURE_CHIBI = 1003 + CRACKED_KINTSUGI = 1004 + NEON_ME = 1005 + SIMPLE_CARTOON = 1006 + WESTERN_ANIME = 1007 + EIGHTIES_ANIME = 1008 + NEWSPAPER_RETRO = 1009 + PIXAR_DISNEY = 2001 diff --git a/src/imagine/models/status.py b/src/imagine/enums/status.py similarity index 94% rename from src/imagine/models/status.py rename to src/imagine/enums/status.py index 4f2e529..542ba94 100644 --- a/src/imagine/models/status.py +++ b/src/imagine/enums/status.py @@ -1,17 +1,17 @@ -from enum import Enum - - -class Status(Enum): - """ - Enums for Status - """ - - OK = 200 - BAD_REQUEST = 400 - UNAUTHORIZED = 401 - UNPROCESSABLE_ENTITY = 422 - TOO_MANY_REQUESTS = 429 - INTERNAL_SERVER_ERROR = 500 - SERVICE_UNAVAILABLE = 503 - MODULE_NOT_FOUND = 1000 - NOT_ENOUGH_TOKENS = 424 +from enum import Enum + + +class Status(Enum): + """ + Enums for Status + """ + + OK = 200 + BAD_REQUEST = 400 + UNAUTHORIZED = 401 + UNPROCESSABLE_ENTITY = 422 + TOO_MANY_REQUESTS = 429 + INTERNAL_SERVER_ERROR = 500 + SERVICE_UNAVAILABLE = 503 + MODULE_NOT_FOUND = 1000 + NOT_ENOUGH_TOKENS = 424 diff --git a/src/imagine/enums/styles.py b/src/imagine/enums/styles.py new file mode 100644 index 0000000..fbfb648 --- /dev/null +++ b/src/imagine/enums/styles.py @@ -0,0 +1,89 @@ +from enum import Enum + + +class Styles: + class Generations(Enum): + """ + Enums for generation style_ids + """ + + ANIME = 21 + PORTRAIT = 26 + IMAGINE_V1 = 27 + IMAGINE_V3 = 28 + REALISTIC = 29 + IMAGINE_V4 = 30 + IMAGINE_V4_CREATIVE = 31 + IMAGINE_V4_1 = 32 + IMAGINE_V5 = 33 + DELIBERATE = 100 + MAGIC_MIX = 101 + DISNEY = 102 + ABYSS_ORANGE_MIX = 103 + LYRIEL = 104 + RPG_4 = 105 + REALISTIC_VISION = 110 + DREAM_SHAPER = 111 + REV_ANIMATED = 112 + TOON_YOU = 113 + UNREAL_ENGINE_5 = 114 + EPIC_REALISM = 115 + MEINA_MIX = 116 + XX_MIX_9_REALISTIC = 117 + THREE_D_RENDERING = 118 + ABSOLUTE_REALITY_V1_6 = 119 + + class Variations(Enum): + """ + Enums for generation style_ids + """ + + ANIME = 21 + PORTRAIT = 26 + IMAGINE_V1 = 27 + IMAGINE_V3 = 28 + REALISTIC = 29 + IMAGINE_V4 = 30 + IMAGINE_V4_CREATIVE = 31 + IMAGINE_V4_1 = 32 + IMAGINE_V5 = 33 + DELIBERATE = 100 + MAGIC_MIX = 101 + DISNEY = 102 + ABYSS_ORANGE_MIX = 103 + LYRIEL = 104 + RPG_4 = 105 + REALISTIC_VISION = 110 + DREAM_SHAPER = 111 + REV_ANIMATED = 112 + TOON_YOU = 113 + UNREAL_ENGINE_5 = 114 + EPIC_REALISM = 115 + MEINA_MIX = 116 + XX_MIX_9_REALISTIC = 117 + THREE_D_RENDERING = 118 + ABSOLUTE_REALITY_V1_6 = 119 + + class Remix(Enum): + """ + Enums for Remix style_ids + """ + + ANIME = 21 + IMAGINE_V1 = 22 + REALISTIC = 29 + + class Inpaint(Enum): + """ + Enums for Inpainting models versions + """ + + REALISM = 1 + + class Filters(Enum): + """ + Enums for Filters models versions + """ + + STYLE_1 = 1 + STYLE_2 = 2 diff --git a/src/imagine/features/image_remix/__init__.py b/src/imagine/features/background/__init__.py similarity index 100% rename from src/imagine/features/image_remix/__init__.py rename to src/imagine/features/background/__init__.py diff --git a/src/imagine/features/background/handler.py b/src/imagine/features/background/handler.py new file mode 100644 index 0000000..5967a3c --- /dev/null +++ b/src/imagine/features/background/handler.py @@ -0,0 +1,42 @@ +from ...remote.http_client import HttpClient +from ...models.response import Response +from ...models.image import Image +from .remover.handler import RemoverHandler + + +class Background: + """ + The Background class is responsible for interacting with the + backgrounds of images. + + """ + + __client: HttpClient + + __remover_handler: RemoverHandler + + def __init__(self, client: HttpClient): + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + self.__remover_handler = RemoverHandler(self.__client) + + def remover( + self, + image_path: str, + ) -> Response[Image]: + """ + Remove the background of an image + + :param image_path: The path to the source image. + :type image_path: str + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__remover_handler( + image_path=image_path, + ) diff --git a/src/imagine/features/in_painting/__init__.py b/src/imagine/features/background/remover/__init__.py similarity index 100% rename from src/imagine/features/in_painting/__init__.py rename to src/imagine/features/background/remover/__init__.py diff --git a/src/imagine/features/background/remover/handler.py b/src/imagine/features/background/remover/handler.py new file mode 100644 index 0000000..f3577d0 --- /dev/null +++ b/src/imagine/features/background/remover/handler.py @@ -0,0 +1,44 @@ +from typing import Optional +from ....remote.http_client import HttpClient +from ....models.response import Response +from ....models.image import Image +from ....utils.file.read import read_image_file_as_bytes +from ....utils.error.checker import check_and_raise +from ....utils.parameter.checker import non_optional_parameter_checker + + +class RemoverHandler: + """ + The RemoverHandler class is responsible for removing the background of and image + using the Imagine API's background removal endpoint. + + """ + + __client: HttpClient + __endpoint: str = "/background/remover" + + def __init__(self, client: HttpClient) -> None: + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + def __call__( + self, + image_path: str, + ) -> Response[Image]: + # Validate that image_path is valid + error: Optional[ValueError] = non_optional_parameter_checker( + image_path=image_path + ) + check_and_raise(error) + files = {"image": read_image_file_as_bytes(image_path)} + + status_code, content = self.__client.post(self.__endpoint, files=files) + if status_code != 200: + return Response(None, status_code) + + result = Image(content) + + return Response(result, status_code) diff --git a/src/imagine/features/super_resolution/__init__.py b/src/imagine/features/edits/__init__.py similarity index 100% rename from src/imagine/features/super_resolution/__init__.py rename to src/imagine/features/edits/__init__.py diff --git a/src/imagine/features/edits/filters/__init__.py b/src/imagine/features/edits/filters/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/edits/filters/handler.py b/src/imagine/features/edits/filters/handler.py new file mode 100644 index 0000000..aa1bb1b --- /dev/null +++ b/src/imagine/features/edits/filters/handler.py @@ -0,0 +1,65 @@ +from typing import Optional +from ....remote.http_client import HttpClient +from ....models.response import Response +from ....models.image import Image +from ....utils.file.read import read_image_file_as_bytes +from ....utils.error.checker import check_and_raise +from ....utils.parameter.checker import ( + non_optional_parameter_checker, + parameter_builder, +) +from ....constants import DEFAULT_FILTER_ID, DEFAULT_STYLE_ID +from ....enums import Filters + + +def ids(id): + if not id: + return { + "filterId": DEFAULT_FILTER_ID, + "styleId": DEFAULT_STYLE_ID, + } + + base_value = 1000 + filter_id = id % base_value + style_id = id // base_value + return { + "filterId": filter_id, + "styleId": style_id, + } + + +class FiltersHandler: + """ + The FiltersHandler class is responsible for applying different art + style filters to a provided image. + + """ + + __client: HttpClient + __endpoint: str = "/edits/filters" + + def __init__(self, client: HttpClient) -> None: + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + def __call__(self, image_path: str, filter_id: Filters) -> Response[Image]: + # Validate that image_path is valid + error: Optional[ValueError] = non_optional_parameter_checker( + image_path=image_path, filter_id=filter_id + ) + check_and_raise(error) + + filter_id, style_id = ids(filter_id) + + parameters = parameter_builder(filter_id=filter_id, style_id=style_id) + files = {"image": read_image_file_as_bytes(image_path)} + status_code, content = self.__client.post(self.__endpoint, files, parameters) + if status_code != 200: + return Response(None, status_code) + + result = Image(content) + + return Response(result, status_code) diff --git a/src/imagine/features/edits/handler.py b/src/imagine/features/edits/handler.py new file mode 100644 index 0000000..1fb3d80 --- /dev/null +++ b/src/imagine/features/edits/handler.py @@ -0,0 +1,93 @@ +from ...remote.http_client import HttpClient +from ...models.response import Response +from ...models.image import Image + +from .remix.handler import Remix +from .inpaint.handler import InpaintHandler +from .filters.handler import FiltersHandler + +from ...enums import Styles, Filters + + +class Edits: + """ + The Edits class is responsible for interacting with input images to + edit them based on selected methods and their provided configs. + + """ + + __client: HttpClient + + __remix_handler: Remix + __inpaint_handler: InpaintHandler + __filters_handler: FiltersHandler + + def __init__(self, client: HttpClient): + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + self.__remix_handler = Remix(self.__client) + self.__inpaint_handler = InpaintHandler(self.__client) + self.__filters_handler = FiltersHandler(self.__client) + + @property + def remix(self) -> Remix: + """ + Instances of all the methods to edit an image + + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + + :return: An instance of the Generations handler. + :rtype: Generations + """ + return self.__remix_handler + + def inpaint( + self, + image_path: str, + mask_path: str, + prompt: str, + *, + style: Styles.Inpaint = Styles.Inpaint.REALISM, + ) -> Response[Image]: + """ + Perform image inpainting based on specified parameters using the + InpaintHandler. + + :param image_path: The path to the source image. + :type image_path: str + :param mask_path: The path to the mask image for inpainting. + :type mask_path: str + :param prompt: The prompt for guiding the inpainting process. + :type prompt: str + :param style: The model version for inpainting. + :type style: :class:`InpaintingModel` + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__inpaint_handler( + prompt=prompt, + image_path=image_path, + mask_path=mask_path, + style_id=style.value, + ) + + def filters(self, image_path: str, filter: Filters) -> Response[Image]: + """ + Perform image inpainting based on specified parameters using the + InpaintHandler. + + :param image_path: The path to the source image. + :type image_path: str + :param filter: The filter id for Filters. + :type filter: :class:`EditsFilters` + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__filters_handler(image_path=image_path, filter_id=filter) diff --git a/src/imagine/features/edits/inpaint/__init__.py b/src/imagine/features/edits/inpaint/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/in_painting/handler.py b/src/imagine/features/edits/inpaint/handler.py similarity index 67% rename from src/imagine/features/in_painting/handler.py rename to src/imagine/features/edits/inpaint/handler.py index b04d6a5..cc6387a 100644 --- a/src/imagine/features/in_painting/handler.py +++ b/src/imagine/features/edits/inpaint/handler.py @@ -1,54 +1,57 @@ -from typing import Optional -from ...remote.http_client import HttpClient -from ...models.response import Response -from ...models.image import Image -from ...utils.error.checker import check_and_raise -from ...utils.file.read import read_image_file_as_bytes -from ...utils.parameter.checker import parameter_builder, non_optional_parameter_checker - - -class InPaintHandler: - """ - The InPaintHandler class is responsible for inpainting images using the - Imagine API's image inpainting endpoint. - - This class facilitates the interaction with the Imagine API to perform - image inpainting operations by providing a prompt, the image to be - inpainted, a mask indicating the areas to be filled, and the model - version to be used. - """ - - __client: HttpClient - __endpoint: str = "/edits/inpaint" - - def __init__(self, client: HttpClient) -> None: - """ - :param client: An instance of an HTTP client used to make requests to the API. - :type client: :class:`HttpClient` - """ - self.__client = client - - def __call__( - self, prompt: str, image_path: str, mask_path: str, model_version: str - ) -> Response[Image]: - # Validate prompt and image_path - error: Optional[ValueError] = non_optional_parameter_checker( - prompt=prompt, image_path=image_path, mask_path=mask_path - ) - check_and_raise(error) - - parameters = parameter_builder(prompt=prompt, model_version=model_version) - - files = { - "image": read_image_file_as_bytes(image_path), - "mask": read_image_file_as_bytes(mask_path), - } - - status_code, content = self.__client.post(self.__endpoint, parameters, files) - - if status_code != 200: - return Response(None, status_code) - - result = Image(content) - - return Response(result, status_code) +from typing import Optional +from ....remote.http_client import HttpClient +from ....models.response import Response +from ....models.image import Image +from ....utils.error.checker import check_and_raise +from ....utils.file.read import read_image_file_as_bytes +from ....utils.parameter.checker import ( + parameter_builder, + non_optional_parameter_checker, +) + + +class InpaintHandler: + """ + The InpaintHandler class is responsible for inpainting images using the + Imagine API's image inpainting endpoint. + + This class facilitates the interaction with the Imagine API to perform + image inpainting operations by providing a prompt, the image to be + inpainted, a mask indicating the areas to be filled, and the model + version to be used. + """ + + __client: HttpClient + __endpoint: str = "/edits/inpaint" + + def __init__(self, client: HttpClient) -> None: + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + def __call__( + self, prompt: str, image_path: str, mask_path: str, style_id: int + ) -> Response[Image]: + # Validate prompt and image_path + error: Optional[ValueError] = non_optional_parameter_checker( + prompt=prompt, image_path=image_path, mask_path=mask_path + ) + check_and_raise(error) + + parameters = parameter_builder(prompt=prompt, style_id=style_id) + + files = { + "image": read_image_file_as_bytes(image_path), + "mask": read_image_file_as_bytes(mask_path), + } + + status_code, content = self.__client.post(self.__endpoint, parameters, files) + + if status_code != 200: + return Response(None, status_code) + + result = Image(content) + + return Response(result, status_code) diff --git a/src/imagine/features/edits/remix/__init__.py b/src/imagine/features/edits/remix/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/edits/remix/handler.py b/src/imagine/features/edits/remix/handler.py new file mode 100644 index 0000000..17c119a --- /dev/null +++ b/src/imagine/features/edits/remix/handler.py @@ -0,0 +1,82 @@ +from typing import Optional +from ....remote.http_client import HttpClient +from ....models.response import Response +from ....models.image import Image + +from ....enums import Styles, Controls + +from .remix.handler import RemixHandler + + +class Remix: + """ + The Remix class is responsible for interacting with input images to + edit them based on selected methods and their provided configs. + + """ + + __client: HttpClient + + __remix_handler: RemixHandler + + def __init__(self, client: HttpClient): + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + self.__remix_handler = RemixHandler(self.__client) + + def remix( + self, + image_path: str, + prompt: str, + *, + style: Styles.Remix = Styles.Remix.IMAGINE_V1, + control: Controls.Remix = Controls.Remix.OPENPOSE, + seed: Optional[int] = None, + strength: Optional[int] = None, + steps: Optional[int] = None, + cfg: Optional[float] = None, + neg_prompt: Optional[str] = None, + ) -> Response[Image]: + """ + Remix an image based on specified parameters using the + ImageRemixHandler. + + :param image_path: The path to the source image. + :type image_path: str + :param prompt: The prompt for remixing the image. + :type prompt: str + :param style: The style for the image remixing (default: + ImageRemixStyle.STYLE_IMAGINE_V1). + :type style: :class:`ImageRemixStyle` + :param control: The control settings for remixing (default: + RemixControls.OPENPOSE). + :type control: :class:`RemixControls` + :param seed: The random seed for reproducible remixing (default: None). + :type seed: Optional[int] + :param strength: The strength of the remixing effect (default: None). + :type strength: Optional[int] + :param steps: The number of steps for remixing the image (default: None). + :type steps: Optional[int] + :param cfg: The cfg parameter for remixing (default: None). + :type cfg: Optional[float] + :param neg_prompt: The negative prompt for remixing (default: None). + :type neg_prompt: Optional[str] + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__remix_handler( + prompt=prompt, + image_path=image_path, + style_id=style.value, + control=control.value, + seed=seed, + strength=strength, + steps=steps, + cfg=cfg, + neg_prompt=neg_prompt, + ) diff --git a/src/imagine/features/edits/remix/remix/__init__.py b/src/imagine/features/edits/remix/remix/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/image_remix/handler.py b/src/imagine/features/edits/remix/remix/handler.py similarity index 77% rename from src/imagine/features/image_remix/handler.py rename to src/imagine/features/edits/remix/remix/handler.py index cf585b1..807a6ae 100644 --- a/src/imagine/features/image_remix/handler.py +++ b/src/imagine/features/edits/remix/remix/handler.py @@ -1,69 +1,72 @@ -from typing import Optional -from ...remote.http_client import HttpClient -from ...models.response import Response -from ...models.image import Image -from ...utils.error.checker import check_and_raise -from ...utils.file.read import read_image_file_as_bytes -from ...utils.parameter.checker import parameter_builder, non_optional_parameter_checker - - -class ImageRemixHandler: - """ - The ImageRemixHandler class is responsible for remixing images based on - specified parameters using the Imagine API's image remixing endpoint. - - This class facilitates the interaction with the Imagine API to remix - images by providing an image to be remixed, a prompt, a style ID, and - control parameters for the remixing process. - """ - - __client: HttpClient - __endpoint: str = "/edits/remix" - - def __init__(self, client: HttpClient) -> None: - """ - :param client: An instance of an HTTP client used to make requests to the API. - :type client: :class:`HttpClient` - """ - self.__client = client - - def __call__( - self, - image_path: str, - prompt: str, - style_id: int, - control: str, - *, - seed: Optional[int] = None, - strength: Optional[int] = None, - steps: Optional[int] = None, - cfg: Optional[float] = None, - neg_prompt: Optional[str] = None, - ) -> Response[Image]: - # Validate prompt and image_path - error: Optional[ValueError] = non_optional_parameter_checker( - prompt=prompt, image_path=image_path - ) - check_and_raise(error) - - parameters = parameter_builder( - prompt=prompt, - style_id=style_id, - control=control, - seed=seed, - strength=strength, - steps=steps, - cfg=cfg, - negative_prompt=neg_prompt, - ) - - files = {"image": read_image_file_as_bytes(image_path)} - - status_code, content = self.__client.post(self.__endpoint, parameters, files) - - if status_code != 200: - return Response(None, status_code) - - result = Image(content) - - return Response(result, status_code) +from typing import Optional +from .....remote.http_client import HttpClient +from .....models.response import Response +from .....models.image import Image +from .....utils.error.checker import check_and_raise +from .....utils.file.read import read_image_file_as_bytes +from .....utils.parameter.checker import ( + parameter_builder, + non_optional_parameter_checker, +) + + +class RemixHandler: + """ + The RemixHandler class is responsible for remixing images based on + specified parameters using the Imagine API's image remixing endpoint. + + This class facilitates the interaction with the Imagine API to remix + images by providing an image to be remixed, a prompt, a style ID, and + control parameters for the remixing process. + """ + + __client: HttpClient + __endpoint: str = "/edits/remix" + + def __init__(self, client: HttpClient) -> None: + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + def __call__( + self, + image_path: str, + prompt: str, + style_id: int, + control: str, + *, + seed: Optional[int] = None, + strength: Optional[int] = None, + steps: Optional[int] = None, + cfg: Optional[float] = None, + neg_prompt: Optional[str] = None, + ) -> Response[Image]: + # Validate prompt and image_path + error: Optional[ValueError] = non_optional_parameter_checker( + prompt=prompt, image_path=image_path + ) + check_and_raise(error) + + parameters = parameter_builder( + prompt=prompt, + style_id=style_id, + control=control, + seed=seed, + strength=strength, + steps=steps, + cfg=cfg, + negative_prompt=neg_prompt, + ) + + files = {"image": read_image_file_as_bytes(image_path)} + + status_code, content = self.__client.post(self.__endpoint, parameters, files) + + if status_code != 200: + return Response(None, status_code) + + result = Image(content) + + return Response(result, status_code) diff --git a/src/imagine/features/enhance/__init__.py b/src/imagine/features/enhance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/enhance/handler.py b/src/imagine/features/enhance/handler.py new file mode 100644 index 0000000..3859b70 --- /dev/null +++ b/src/imagine/features/enhance/handler.py @@ -0,0 +1,40 @@ +from ...remote.http_client import HttpClient +from ...models.response import Response +from ...models.image import Image + +from .upsacle.handler import UpscaleHandler + + +class Enhance: + """ + The Enhance class is responsible for enhancing images. + + """ + + __client: HttpClient + + __upscale_handler: UpscaleHandler + + def __init__(self, client: HttpClient): + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + self.__upscale_handler = UpscaleHandler(self.__client) + + def upscale( + self, + image_path: str, + ) -> Response[Image]: + """ + Enhance the resolution of an image using the UpscaleHandler. + + :param image_path: The path to the source image. + :type image_path: str + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__upscale_handler(image_path=image_path) diff --git a/src/imagine/features/enhance/upsacle/__init__.py b/src/imagine/features/enhance/upsacle/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/super_resolution/handler.py b/src/imagine/features/enhance/upsacle/handler.py similarity index 59% rename from src/imagine/features/super_resolution/handler.py rename to src/imagine/features/enhance/upsacle/handler.py index 88f0032..08bd598 100644 --- a/src/imagine/features/super_resolution/handler.py +++ b/src/imagine/features/enhance/upsacle/handler.py @@ -1,24 +1,24 @@ from typing import Optional -from ...remote.http_client import HttpClient -from ...models.response import Response -from ...models.image import Image -from ...utils.error.checker import check_and_raise -from ...utils.file.read import read_image_file_as_bytes -from ...utils.parameter.checker import parameter_builder, non_optional_parameter_checker +from ....remote.http_client import HttpClient +from ....models.response import Response +from ....models.image import Image +from ....utils.error.checker import check_and_raise +from ....utils.file.read import read_image_file_as_bytes +from ....utils.parameter.checker import non_optional_parameter_checker -class SuperResolutionHandler: +class UpscaleHandler: """ - The SuperResolutionHandler class is responsible for performing image + The UpscaleHandler class is responsible for performing image super-resolution using the Imagine API's image upscaling endpoint. This class facilitates the interaction with the Imagine API to upscale images using super-resolution techniques, providing the image to be - upscaled and the model version to be used. + upscaled. """ __client: HttpClient - __endpoint: str = "/upscale/" + __endpoint: str = "/enhance/upscale" def __init__(self, client: HttpClient) -> None: """ @@ -27,18 +27,16 @@ def __init__(self, client: HttpClient) -> None: """ self.__client = client - def __call__(self, image_path: str, model_version: str) -> Response[Image]: + def __call__(self, image_path: str) -> Response[Image]: # Validate prompt and image_path error: Optional[ValueError] = non_optional_parameter_checker( image_path=image_path ) check_and_raise(error) - parameters = parameter_builder(model_version=model_version) - files = {"image": read_image_file_as_bytes(image_path)} - status_code, content = self.__client.post(self.__endpoint, parameters, files) + status_code, content = self.__client.post(self.__endpoint, files) if status_code != 200: return Response(None, status_code) diff --git a/src/imagine/features/face/__init__.py b/src/imagine/features/face/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/face/handler.py b/src/imagine/features/face/handler.py new file mode 100644 index 0000000..e3e85e7 --- /dev/null +++ b/src/imagine/features/face/handler.py @@ -0,0 +1,45 @@ +from ...remote.http_client import HttpClient +from ...models.response import Response +from ...models.image import Image + +from .headshot.handler import HeadshotHandler + + +class Face: + """ + The Face class is responsible for editing an image while + maintaining the facial identity of the subject. + + """ + + __client: HttpClient + + __headshot_handler: HeadshotHandler + + def __init__(self, client: HttpClient): + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + self.__headshot_handler = HeadshotHandler(self.__client) + + def headshot( + self, + image_path: str, + prompt: str, + ) -> Response[Image]: + """ + Change the clothing of a subject using the HeadshotHandler + while maintaining facial identity. + + :param image_path: The path to the source image. + :type image_path: str + :param prompt: The guidance for editing the image. + :type prompt: str + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__headshot_handler(image_path=image_path, prompt=prompt) diff --git a/src/imagine/features/face/headshot/__init__.py b/src/imagine/features/face/headshot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/face/headshot/handler.py b/src/imagine/features/face/headshot/handler.py new file mode 100644 index 0000000..e3f7535 --- /dev/null +++ b/src/imagine/features/face/headshot/handler.py @@ -0,0 +1,46 @@ +from typing import Optional +from ....remote.http_client import HttpClient +from ....models.response import Response +from ....models.image import Image +from ....utils.error.checker import check_and_raise +from ....utils.file.read import read_image_file_as_bytes +from ....utils.parameter.checker import ( + parameter_builder, + non_optional_parameter_checker, +) + + +class HeadshotHandler: + """ + The HeadshotHandler class is responsible for changing the subject's clothes + using the Imagine API's image headshot endpoint. + """ + + __client: HttpClient + __endpoint: str = "/face/headshot" + + def __init__(self, client: HttpClient) -> None: + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + def __call__(self, image_path: str, prompt: str) -> Response[Image]: + # Validate prompt and image_path + error: Optional[ValueError] = non_optional_parameter_checker( + image_path=image_path, prompt=prompt + ) + check_and_raise(error) + + parameters = parameter_builder(prompt=prompt) + + files = {"image": read_image_file_as_bytes(image_path)} + + status_code, content = self.__client.post(self.__endpoint, parameters, files) + if status_code != 200: + return Response(None, status_code) + + result = Image(content) + + return Response(result, status_code) diff --git a/src/imagine/features/generations/background/__init__.py b/src/imagine/features/generations/background/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/generations/background/handler.py b/src/imagine/features/generations/background/handler.py new file mode 100644 index 0000000..e864c7a --- /dev/null +++ b/src/imagine/features/generations/background/handler.py @@ -0,0 +1,46 @@ +from typing import Optional +from remote.http_client import HttpClient +from models.response import Response +from models.image import Image + +from utils.error.checker import check_and_raise +from utils.parameter.checker import parameter_builder, non_optional_parameter_checker +from utils.file.read import read_image_file_as_bytes + + +class BackgroundHandler: + """ + The BackgroundHandler class is responsible for generating a background of an input image + + This class facilitates the interaction with the Imagine API to generate + images by providing a prompt, and an image. + """ + + __client: HttpClient + __endpoint: str = "/generations/background" + + def __init__(self, client: HttpClient) -> None: + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + def __call__(self, prompt: str, image_path: str) -> Response[Image]: + # Validate that prompt is not empty + error: Optional[ValueError] = non_optional_parameter_checker(prompt=prompt) + check_and_raise(error) + + files = {"image": read_image_file_as_bytes(image_path)} + + parameters = parameter_builder( + prompt=prompt, + ) + + status_code, content = self.__client.post(self.__endpoint, parameters, files) + if status_code != 200: + return Response(None, status_code) + + result = Image(content) + + return Response(result, status_code) diff --git a/src/imagine/features/generations/generations/__init__.py b/src/imagine/features/generations/generations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/imagine/features/generations/generations/handler.py b/src/imagine/features/generations/generations/handler.py new file mode 100644 index 0000000..2b9945f --- /dev/null +++ b/src/imagine/features/generations/generations/handler.py @@ -0,0 +1,65 @@ +from typing import Optional +from ....remote.http_client import HttpClient +from ....models.response import Response +from ....models.image import Image +from ....utils.error.checker import check_and_raise +from ....utils.parameter.checker import ( + parameter_builder, + non_optional_parameter_checker, +) + + +class GenerationsHandler: + """ + The GenerationsHandler class is responsible for generating images based on + specified parameters using the Imagine API's image generation endpoint. + + This class facilitates the interaction with the Imagine API to generate + images by providing a prompt, a style ID, and various optional parameters + for control. + """ + + __client: HttpClient + __endpoint: str = "/generations" + + def __init__(self, client: HttpClient) -> None: + """ + :param client: An instance of an HTTP client used to make requests to the API. + :type client: :class:`HttpClient` + """ + self.__client = client + + def __call__( + self, + prompt: str, + *, + style_id: Optional[int] = None, + aspect_ratio: Optional[str] = None, + neg_prompt: Optional[str] = None, + cfg: Optional[float] = None, + seed: Optional[int] = None, + steps: Optional[int] = None, + high_res_results: Optional[int] = None, + ) -> Response[Image]: + # Validate that prompt is not empty + error: Optional[ValueError] = non_optional_parameter_checker(prompt=prompt) + check_and_raise(error) + + parameters = parameter_builder( + style_id=style_id, + prompt=prompt, + aspect_ratio=aspect_ratio, + negative_prompt=neg_prompt, + cfg=cfg, + seed=seed, + steps=steps, + high_res_results=high_res_results, + ) + + status_code, content = self.__client.post(self.__endpoint, parameters) + if status_code != 200: + return Response(None, status_code) + + result = Image(content) + + return Response(result, status_code) diff --git a/src/imagine/features/generations/handler.py b/src/imagine/features/generations/handler.py index fbd0fe6..188237b 100644 --- a/src/imagine/features/generations/handler.py +++ b/src/imagine/features/generations/handler.py @@ -2,61 +2,148 @@ from ...remote.http_client import HttpClient from ...models.response import Response from ...models.image import Image -from ...utils.error.checker import check_and_raise -from ...utils.parameter.checker import parameter_builder, non_optional_parameter_checker +from ...enums import AspectRatio, Styles +from .generations.handler import GenerationsHandler +from .variations.handler import VariationsHandler +from .background.handler import BackgroundHandler -class GenerationsHandler: +class Generations: """ - The GenerationsHandler class is responsible for generating images based on - specified parameters using the Imagine API's image generation endpoint. - - This class facilitates the interaction with the Imagine API to generate - images by providing a prompt, a style ID, and various optional parameters - for control. + The Generations class is responsible for generating images through + various methods that further use Imagine API's generation endpoints. """ __client: HttpClient - __endpoint: str = "/generations" - def __init__(self, client: HttpClient) -> None: + __generations_handler: GenerationsHandler + __variations_handler: VariationsHandler + __background_handler: BackgroundHandler + + def __init__(self, client: HttpClient): """ :param client: An instance of an HTTP client used to make requests to the API. :type client: :class:`HttpClient` """ self.__client = client - def __call__( + self.__generations_handler = GenerationsHandler(self.__client) + self.__variations_handler = VariationsHandler(self.__client) + self.__background_handler = BackgroundHandler(self.__client) + + def generations( self, prompt: str, - style_id: int, *, - aspect_ratio: Optional[str] = None, + style: Styles.Generations = Styles.Generations.IMAGINE_V1, + aspect_ratio: AspectRatio = AspectRatio.ONE_RATIO_ONE, neg_prompt: Optional[str] = None, cfg: Optional[float] = None, seed: Optional[int] = None, steps: Optional[int] = None, - high_res_results: Optional[int] = None, + high_res_results: bool = False, ) -> Response[Image]: - # Validate that prompt is not empty - error: Optional[ValueError] = non_optional_parameter_checker(prompt=prompt) - check_and_raise(error) + """ + Generate an image based on specified parameters using the + Generations. - parameters = parameter_builder( - style_id=style_id, + :param prompt: The prompt for generating the image. + :type prompt: str + :param style: The style for the image generation (default: + GenerationsStyle.STYLE_IMAGINE_V1). + :type style: :class:`GenerationsStyle` + :param aspect_ratio: The aspect ratio of the image (default: None). + :type aspect_ratio: Optional[str] + :param neg_prompt: The negative prompt for contrasting images (default: None). + :type neg_prompt: Optional[str] + :param cfg: The cfg parameter for image generation (default: None). + :type cfg: Optional[float] + :param seed: The random seed for reproducible generation (default: None). + :type seed: Optional[int] + :param steps: The number of steps for generating the image (default: None). + :type steps: Optional[int] + :param high_res_results: The level of high-resolution results (default: False). + :type high_res_results: bool + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__generations_handler( prompt=prompt, - aspect_ratio=aspect_ratio, - negative_prompt=neg_prompt, + style_id=style.value, + aspect_ratio=aspect_ratio.value, cfg=cfg, seed=seed, + neg_prompt=neg_prompt, + high_res_results=int(high_res_results), steps=steps, - high_res_results=high_res_results, ) - status_code, content = self.__client.post(self.__endpoint, parameters) - if status_code != 200: - return Response(None, status_code) + def variations( + self, + image_path: str, + prompt: str, + *, + style: Styles.Variations = Styles.Variations.IMAGINE_V1, + seed: Optional[int] = None, + steps: Optional[int] = None, + strength: Optional[int] = None, + cfg: Optional[float] = None, + neg_prompt: Optional[str] = None, + ) -> Response[Image]: + """ + Generate a variation of an image based on specified parameters using + the VariationsHandler. It is an extension of generations hence why it + uses the same styles as Generations. + + :param image_path: The path to the source image. + :type image_path: str + :param prompt: The prompt for generating the variation. + :type prompt: str + :param style: The style for generating the variation. + :type style: :class:`GenerationsStyle` + :param seed: The random seed for reproducible generation. + :type seed: Optional[int] + :param steps: The number of steps for generating the variation. + :type steps: Optional[int] + :param strength: The strength of the variation effect. + :type strength: Optional[int] + :param cfg: The cfg parameter for generating the variation. + :type cfg: Optional[float] + :param neg_prompt: The negative prompt for contrasting variations. + :type neg_prompt: Optional[str] + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__variations_handler( + prompt=prompt, + image_path=image_path, + style_id=style.value, + strength=strength, + seed=seed, + steps=steps, + cfg=cfg, + neg_prompt=neg_prompt, + ) - result = Image(content) + def background( + self, + image_path: str, + prompt: str, + ) -> Response[Image]: + """ + Generate a background of an image based on a prompt. - return Response(result, status_code) + :param image_path: The path to the source image. + :type image_path: str + :param prompt: The prompt for generating the variation. + :type prompt: str + :return: A response containing the generated error or an :class:`Image` + object. + :rtype: :class:`Response`[:class:`Image`] + """ + return self.__background_handler( + prompt=prompt, + image_path=image_path, + ) diff --git a/src/imagine/features/generations/style_ids.py b/src/imagine/features/generations/style_ids.py deleted file mode 100644 index 019fedb..0000000 --- a/src/imagine/features/generations/style_ids.py +++ /dev/null @@ -1,33 +0,0 @@ -from enum import Enum - - -class GenerationsStyle(Enum): - """ - Enums for generation style_ids - """ - - ANIME = 21 - PORTRAIT = 26 - IMAGINE_V1 = 27 - IMAGINE_V3 = 28 - REALISTIC = 29 - IMAGINE_V4 = 30 - IMAGINE_V4_CREATIVE = 31 - IMAGINE_V4_1 = 32 - IMAGINE_V5 = 33 - DELIBERATE = 100 - MAGIC_MIX = 101 - DISNEY = 102 - ABYSS_ORANGE_MIX = 103 - LYRIEL = 104 - RPG_4 = 105 - REALISTIC_VISION = 110 - DREAM_SHAPER = 111 - REV_ANIMATED = 112 - TOON_YOU = 113 - UNREAL_ENGINE_5 = 114 - EPIC_REALISM = 115 - MEINA_MIX = 116 - XX_MIX_9_REALISTIC = 117 - THREE_D_RENDERING = 118 - ABSOLUTE_REALITY_V1_6 = 119 diff --git a/src/imagine/features/generations/variations/handler.py b/src/imagine/features/generations/variations/handler.py index 13ef0ca..321427f 100644 --- a/src/imagine/features/generations/variations/handler.py +++ b/src/imagine/features/generations/variations/handler.py @@ -4,12 +4,15 @@ from ....models.image import Image from ....utils.error.checker import check_and_raise from ....utils.file.read import read_image_file_as_bytes -from ....utils.parameter.checker import parameter_builder, non_optional_parameter_checker +from ....utils.parameter.checker import ( + parameter_builder, + non_optional_parameter_checker, +) class VariationsHandler: """ - The VariateHandler class is responsible for generating image variations + The VariationsHandler class is responsible for generating image variations based on specified parameters using the Imagine API's image variations endpoint. @@ -58,9 +61,7 @@ def __call__( files = {"image": read_image_file_as_bytes(image_path)} - status_code, content = self.__client.post( - self.__endpoint, parameters=parameters, files=files - ) + status_code, content = self.__client.post(self.__endpoint, parameters, files) if status_code != 200: return Response(None, status_code) diff --git a/src/imagine/features/image_remix/controls.py b/src/imagine/features/image_remix/controls.py deleted file mode 100644 index 3a22f89..0000000 --- a/src/imagine/features/image_remix/controls.py +++ /dev/null @@ -1,13 +0,0 @@ -from enum import Enum - - -class RemixControls(Enum): - """ - Enums for image_remix to guide image generation - """ - - OPENPOSE = "openpose" - SCRIBBLE = "scribble" - CANNY = "canny" - LINEART = "lineart" - DEPTH = "depth" diff --git a/src/imagine/features/image_remix/style_ids.py b/src/imagine/features/image_remix/style_ids.py deleted file mode 100644 index 990c395..0000000 --- a/src/imagine/features/image_remix/style_ids.py +++ /dev/null @@ -1,11 +0,0 @@ -from enum import Enum - - -class ImageRemixStyle(Enum): - """ - Enums for ImageRemix style_ids - """ - - ANIME = 21 - IMAGINE_V1 = 22 - REALISTIC = 29 diff --git a/src/imagine/features/in_painting/style_ids.py b/src/imagine/features/in_painting/style_ids.py deleted file mode 100644 index b6d54fe..0000000 --- a/src/imagine/features/in_painting/style_ids.py +++ /dev/null @@ -1,9 +0,0 @@ -from enum import Enum - - -class InPaintingStyle(Enum): - """ - Enums for InPainting models versions - """ - - BASIC = "1" diff --git a/src/imagine/features/super_resolution/style_ids.py b/src/imagine/features/super_resolution/style_ids.py deleted file mode 100644 index a969b44..0000000 --- a/src/imagine/features/super_resolution/style_ids.py +++ /dev/null @@ -1,9 +0,0 @@ -from enum import Enum - - -class SuperResolutionStyle(Enum): - """ - Enums for SuperResoultion model versions - """ - - BASIC = 1 diff --git a/src/imagine/models/__init__.py b/src/imagine/models/__init__.py index 147de77..e69de29 100644 --- a/src/imagine/models/__init__.py +++ b/src/imagine/models/__init__.py @@ -1,5 +0,0 @@ -from imagine.models.status import Status - -__all__ = [ - "Status", -] diff --git a/src/imagine/models/response.py b/src/imagine/models/response.py index f4a87da..979dfda 100644 --- a/src/imagine/models/response.py +++ b/src/imagine/models/response.py @@ -1,5 +1,5 @@ from typing import TypeVar, Generic, Optional -from .status import Status +from ..enums import Status T = TypeVar("T") @@ -57,7 +57,7 @@ def get_or_throw(self) -> T: if self.__data is None: raise ValueError( "Response data is not available in the response object." - + f" Status Resonse: {self.__status}" + + f" Status Response: {self.__status}" ) return self.__data diff --git a/src/imagine/styles/__init__.py b/src/imagine/styles/__init__.py deleted file mode 100644 index 703deee..0000000 --- a/src/imagine/styles/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -from ..features.generations.style_ids import GenerationsStyle -from ..features.image_remix.style_ids import ImageRemixStyle -from ..features.image_remix.controls import RemixControls -from ..features.in_painting.style_ids import InPaintingStyle -from ..features.super_resolution.style_ids import SuperResolutionStyle - -__all__ = [ - "SuperResolutionStyle", - "InPaintingStyle", - "RemixControls", - "ImageRemixStyle", - "GenerationsStyle", -]