### Install ImaginePro SDK Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Install the ImaginePro Python SDK using pip. This command downloads and installs the latest version of the library. ```bash pip install imaginepro ``` -------------------------------- ### Fetch Message Details Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Provides an example of fetching message details using the SDK, including error handling for potential exceptions during the fetch operation. ```python try: message_response = sdk.fetch_message("your-message-id") print(f"Message details: {message_response}") except Exception as error: print(f"Error fetching message: {error}") ``` -------------------------------- ### Initialize ImaginePro SDK Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Demonstrates how to initialize the ImagineProSDK with required and optional configuration parameters like API key, base URL, timeout, and fetch interval. ```python from imaginepro import ImagineProSDK, ImagineProSDKOptions sdk = ImagineProSDK(ImagineProSDKOptions( api_key="your-api-key", base_url="https://api.imaginepro.ai`", # Optional default_timeout=60, # Optional, 1 minute fetch_interval=1 # Optional, 1 second )) ``` -------------------------------- ### Initialize ImaginePro SDK and Generate Image Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Demonstrates how to initialize the ImaginePro SDK with API key and base URL, and then generate an image from a text prompt. It also shows how to fetch the result of the generation. ```python import os from imaginepro import ImagineProSDK, ImagineProSDKOptions # Initialize the SDK sdk = ImagineProSDK(ImagineProSDKOptions( api_key="sk-xxxx", base_url="https://api.imaginepro.ai", # Optional, defaults to 'https://api.imaginepro.ai' default_timeout=300, # Optional, defaults to 1800 seconds (30 minutes) fetch_interval=2, # Optional, defaults to 2 seconds )) # Generate an image try: result = sdk.imagine({ "prompt": "a pretty cat playing with a puppy" }) print(f"Image generation initiated: {result}") # Wait for the generation to complete imagine = sdk.fetch_message(result["messageId"]) print(f"Image generation result: {imagine}") except Exception as error: print(f"Error: {error}") ``` -------------------------------- ### Generate Image with Webhook Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Shows how to generate an image using the SDK, including optional parameters for a reference ID (`ref`) and a custom webhook URL (`webhook_override`) to receive generation results. ```python imagine_response = sdk.imagine({ "prompt": "a serene mountain landscape", "ref": "custom-reference-id", # Optional reference ID "webhook_override": "https://your-custom-webhook.url/callback" # Optional custom webhook URL }) print(f"Imagine response with webhook: {imagine_response}") ``` -------------------------------- ### Imagine: Text-to-Image Generation Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Use the `imagine` method to generate an image from a text description. This is the primary method for creating new images. ```python imagine_response = sdk.imagine({ "prompt": "a futuristic cityscape at sunset" }) print(f"Imagine response: {imagine_response}") ``` -------------------------------- ### Message Response Structure Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Illustrates the structure of the `MessageResponse` dictionary, detailing its properties such as `messageId`, `prompt`, `uri`, `progress`, `status`, and other optional fields. ```python message_response = { "messageId": "abc123", "prompt": "a futuristic cityscape at sunset", "uri": "https://cdn.imaginepro.ai/generated-image.jpg", "progress": 100, "status": "DONE", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-01T00:05:00Z", "buttons": ["U1", "V1"], "ref": "custom-reference-id" } print(f"Message Response: {message_response}") ``` -------------------------------- ### Fetch Message Parameters Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md Details on parameters for the `fetch_message` method, including `message_id`, optional `interval` for polling, and optional `timeout` for the maximum wait time. ```APIDOC fetch_message(message_id: str, interval: int = 2, timeout: int = 1800) -> dict Retrieves the status and details of a specific message. Parameters: message_id (string): The unique identifier for the message. interval (int, optional): The polling interval in seconds. Defaults to 2 seconds. timeout (int, optional): The maximum time to wait for the message status in seconds. Defaults to 30 minutes (1800 seconds). Returns: dict: A dictionary containing the message status and details. ``` -------------------------------- ### Press Button Interaction Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md The `press_button` method allows interaction with buttons associated with a message, such as selecting an image variant or upscale option. Requires message ID and button identifier. ```python button_response = sdk.press_button({ "message_id": "your-message-id", "button": "U1" }) print(f"Button press response: {button_response}") ``` -------------------------------- ### Fetch Message Status and Details Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md The `fetch_message` method retrieves the status and details of a specific generation task using its message ID. It polls until the task is completed or fails, with configurable intervals and timeouts. ```python message_response = sdk.fetch_message("your-message-id") print(f"Message response: {message_response}") ``` -------------------------------- ### Inpainting Image Modification Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md The `inpainting` method allows for selective modification of an image using a mask. Provide the message ID of the image and the mask data. ```python inpainting_response = sdk.inpainting({ "message_id": "your-message-id", "mask": "xxx" }) print(f"Inpainting response: {inpainting_response}") ``` -------------------------------- ### Upscale Image Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md The `upscale` method is used to increase the resolution of a generated image. It requires the message ID of the original image and the index corresponding to the desired upscale button (e.g., 'U1'). ```python upscale_response = sdk.upscale({ "message_id": "your-message-id", "index": 1 # Corresponds to button 'U1' }) print(f"Upscale response: {upscale_response}") ``` -------------------------------- ### Generate Image Variant Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md The `variant` method generates variations of a previously created image. It requires the message ID and the index of the variant button (e.g., 'V1'). ```python variant_response = sdk.variant({ "message_id": "your-message-id", "index": 1 # Corresponds to button 'V1' }) print(f"Variant response: {variant_response}") ``` -------------------------------- ### Reroll Image Generation Source: https://github.com/imaginpro/imaginepro-python-sdk/blob/main/README.md The `reroll` method regenerates an image using the same prompt as a previous generation. It requires the message ID of the image to reroll. ```python reroll_response = sdk.reroll({ "message_id": "your-message-id" }) print(f"Reroll response: {reroll_response}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.