Unleashing Creativity: Generate Images with Cognitive Actions from JDPFlux

21 Apr 2025
Unleashing Creativity: Generate Images with Cognitive Actions from JDPFlux

In the realm of image generation, the JDPFlux Cognitive Actions provide developers with powerful tools to create stunning visuals through customizable parameters. The Generate Image with Inpainting action allows you to harness sophisticated image-to-image techniques to produce high-quality images tailored to your specifications. By integrating these pre-built actions into your applications, you can automate and enhance your creative workflows with ease.

Prerequisites

To get started with the JDPFlux Cognitive Actions, you will need:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of JSON and making API calls.

Authentication typically involves passing your API key in the request headers, ensuring secure access to the action functionalities.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images using either image-to-image or inpainting modes. You can customize the output with various parameters such as aspect ratio, dimensions, and even choose between high-quality or faster processing models.

Input

The input for this action is defined by a schema that includes several required and optional fields. Below is the structure you need to follow:

  • prompt (required): A string that describes the desired image.
  • mask (optional): A URI pointing to an image mask for inpainting mode.
  • seed (optional): An integer for reproducible results.
  • image (optional): A URI for the input image.
  • width (optional): An integer that defines the image width (256 to 1440).
  • height (optional): An integer that defines the image height (256 to 1440).
  • goFast (optional): A boolean to enable faster processing.
  • aspectRatio (optional): A string defining the aspect ratio (e.g., "16:9", "custom").
  • outputFormat (optional): A string specifying the image format (e.g., "png", "jpg").
  • numOutputs (optional): An integer indicating the number of images to generate (1 to 4).

Here’s an example of the expected input JSON payload:

{
  "goFast": false,
  "prompt": "a cinematic closeup photo of jossedepauw dressed as a gritty, heavily battle scarred fremen warrior with tribal face tattoos, explosions in the background, standing in the desert of arrakis. ultra realistic.",
  "loraScale": 1,
  "numOutputs": 4,
  "aspectRatio": "16:9",
  "outputFormat": "png",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numInferenceSteps": 28
}

Output

The action returns an array of image URLs, providing the generated images based on your specifications. Each output URL links to the newly created images. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/57e51ed5-c6a6-4f57-a899-f8c84cd3de2c/a5428ace-59bf-49be-9194-f7b4b3ef6ed1.png",
  "https://assets.cognitiveactions.com/invocations/57e51ed5-c6a6-4f57-a899-f8c84cd3de2c/3cae91fc-0990-412c-b0f2-c9161094ae93.png",
  "https://assets.cognitiveactions.com/invocations/57e51ed5-c6a6-4f57-a899-f8c84cd3de2c/bc9cbe27-0fef-42b4-8b1e-36a8b7f7afad.png",
  "https://assets.cognitiveactions.com/invocations/57e51ed5-c6a6-4f57-a899-f8c84cd3de2c/67efc13f-1cce-4007-be96-3c95164d8e9e.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet to illustrate how to execute the Generate Image with Inpainting action:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "09dd2838-5832-4728-97b7-df2a6f2d0b77" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "a cinematic closeup photo of jossedepauw dressed as a gritty, heavily battle scarred fremen warrior with tribal face tattoos, explosions in the background, standing in the desert of arrakis. ultra realistic.",
    "loraScale": 1,
    "numOutputs": 4,
    "aspectRatio": "16:9",
    "outputFormat": "png",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "numInferenceSteps": 28
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The payload contains the input JSON structure needed for the action, and the endpoint is a hypothetical URL that represents where to send your request.

Conclusion

The Generate Image with Inpainting action from the JDPFlux Cognitive Actions suite empowers developers to create customized images efficiently. With its extensive set of parameters, you can tailor the output to meet your specific needs, making it an invaluable resource for automating creative processes. Start exploring these capabilities today and integrate them into your applications for stunning visual results!