Package: imaginesdk
Imagine SDKImagine SDK is a Python library that provides a convenient interface to interact with the Imagine API for image generation and manipulation. This README provides an overview of the library's features, installation instructions, and usage examples.Table of ContentsInstallationUsageImagine ClientResponseImageSome More Usage ExamplesIntegration With Other LibrariesPillow (PIL)NumpySupportLicenseInstallationThe API works for python 3.6 and above. To install the package, execute the following command:pipinstallimaginesdkUsageThe SDK needs to be configured with an API key which is availablehere. It will be passed to the Imagine class as an argument while instantiating it.fromimagineimportImaginefromimagine.stylesimportGenerationsStylefromimagine.modelsimportStatus# Initialize the Imagine client with your API tokenclient=Imagine(token="your-api-token")# Generate an image using the generations featureresponse=client.generations(prompt='''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,)# Check if the request was successfulifresponse.status==Status.OK:image=response.dataimage.as_file("result.png")else:print(f"Status Code:{response.status.value}")Result:Imagine ClientThe 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)For the full list of parameters and other details, check out thedocumentation.ResponseResponse is the return type for each of our functions. It contains the following:status: Status property which returns an enum containing the status code of the response.data: A property which contains the request response.get_or_throw(): either returns the response content or raises an Error if the response content was empty.get_or_else(): either returns the response content or returns the default value if its empty.For the full list of arguments and other details, check out thedocumentation.ImageAll the functions related to Images contain an Image data type as the data in their Response. It currently provides the following:bytesReturns the bytes received after a request operationimage.bytes# -> bytesas_file(file_path: str)Stores the image in the specified path and returns the path.image.as_file("file_path")# -> str (file_path)to_pil_image()The module is loaded dynamically and is not included in the default package, you can choose to forgo this dependency.See thisfor more information.to_numpy()The module is loaded dynamically and is not included in the default package, you can choose to forgo this dependency.See thisfor more information.Some More Usage ExamplesVariationsCurrently Not SupportedfromimagineimportImaginefromimagine.stylesimportGenerationsStylefromimagine.modelsimportStatus# Initialize the Imagine client with your API tokenclient=Imagine(token="your-api-token")# Generate an image using the variations featureresponse=client.variate(image_path="anime_girl.png",prompt="a cute anime girl in a forest",style=GenerationStyle.ANIME,)# Check if the request was successfulifresponse.status==Status.OK:image=response.dataimage.as_file("result.png")else:print(f"Status Code:{response.status.value}")Result:In-PaintingCurrently Not SupportedfromimagineimportImaginefromimagine.stylesimportInPaintingStylefromimagine.modelsimportStatus# Initialize the Imagine client with your API tokenclient=Imagine(token="your-api-token")# Generate an image using the in_painting featureresponse=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 successfulifresponse.status==Status.OK:image=response.dataimage.as_file("result.png")else:print(f"Status Code:{response.status.value}")Result:Integration With Other LibrariesThe 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:pipinstallimaginesdk[all]If you want one but not the other dependency then you also have the option of installing the module separately.Pillow (PIL)If you installed imaginesdk[all], you can skip the first step.First, get the dependency for PillowpipinstallPillowAfter running the aforementioned command you can now use the response data as a pillow object:image.to_pil_image()# -> PIL_ImageNumpyIf you installed imaginesdk[all], you can skip the first step.First, get the dependency for NumpypipinstallnumpyAfter running the aformentioned command you can now use the response data as a numpy object:image.to_numpy()# -> numpy.ndarraySupportIf you run into any version issues, please contact us atapi.imagine@vyro.aiorsupport.imagine.apiLicenseThis project is licensed under the Apache 2 License.