Create Stunning Images with swk23/younganakin Cognitive Actions

22 Apr 2025
Create Stunning Images with swk23/younganakin Cognitive Actions

In the rapidly evolving world of AI, the ability to generate high-quality images programmatically opens up a realm of creative possibilities. The swk23/younganakin specification offers a powerful Cognitive Action called Generate Image With Inpainting. This action enables developers to create images using inpainting and image-to-image techniques, providing customizable attributes to meet various requirements. In this blog post, we'll explore how to leverage this action to enhance your applications with dynamic image generation capabilities.

Prerequisites

Before you dive into integrating the Generate Image With Inpainting action, ensure you have the following prerequisites in place:

  • API Key: You'll need an API key to authenticate requests to the Cognitive Actions platform. This key should be included in the request headers for authorization.
  • Setup: Familiarize yourself with the endpoint structure and ensure your development environment is ready for making HTTP requests.

Cognitive Actions Overview

Generate Image With Inpainting

The Generate Image With Inpainting action allows developers to generate high-quality images by providing various parameters such as prompts, aspect ratios, and image sizes. It supports both inpainting and image-to-image modes, enabling creative adjustments to existing images or generating new ones from scratch.

Input

The action requires a JSON payload with the following schema:

{
  "prompt": "string",
  "mask": "string (optional)",
  "seed": "integer (optional)",
  "image": "string (optional)",
  "width": "integer (optional)",
  "height": "integer (optional)",
  "goFast": "boolean (default: false, optional)",
  "imageFormat": "string (default: 'webp', optional)",
  "outputCount": "integer (default: 1, optional)",
  "imageQuality": "integer (default: 80, optional)",
  "modelWeights": "string (optional)",
  "guidanceScale": "number (default: 3, optional)",
  "mainLoraScale": "number (default: 1, optional)",
  "additionalLora": "string (optional)",
  "inferenceModel": "string (default: 'dev', optional)",
  "inferenceSteps": "integer (default: 28, optional)",
  "imageResolution": "string (default: '1', optional)",
  "promptInfluence": "number (default: 0.8, optional)",
  "imageAspectRatio": "string (default: '1:1', optional)",
  "bypassSafetyCheck": "boolean (default: false, optional)",
  "additionalLoraScale": "number (default: 1, optional)"
}

Example Input:

{
  "goFast": false,
  "prompt": "TOK, full body shot of anakin skywalker as a child with shaggy blonde hair walking in the woods holding a green glowing lightsaber with a white core vertically",
  "imageFormat": "jpg",
  "outputCount": 1,
  "imageQuality": 80,
  "guidanceScale": 3,
  "mainLoraScale": 1,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "imageResolution": "1",
  "promptInfluence": 0.8,
  "imageAspectRatio": "21:9",
  "additionalLoraScale": 1
}

Output

Upon successful execution, the action returns a JSON response containing the URL(s) of the generated image(s).

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/43ea6a7d-003b-4395-9828-4ad16c7cf308/b774c011-dc2e-4bb8-81bb-7b3c6f31171f.jpg"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Generate Image With Inpainting action using Python:

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 = "67469063-a411-41f0-8c27-499d144fce17" # Action ID for Generate Image With Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "TOK, full body shot of anakin skywalker as a child with shaggy blonde hair walking in the woods holding a green glowing lightsaber with a white core vertically",
    "imageFormat": "jpg",
    "outputCount": 1,
    "imageQuality": 80,
    "guidanceScale": 3,
    "mainLoraScale": 1,
    "inferenceModel": "dev",
    "inferenceSteps": 28,
    "imageResolution": "1",
    "promptInfluence": 0.8,
    "imageAspectRatio": "21:9",
    "additionalLoraScale": 1
}

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 example, the code snippet constructs the input payload using the required parameters and optional settings for the action. It handles the API request and response, providing clear output for developers to understand the results.

Conclusion

The Generate Image With Inpainting action from the swk23/younganakin specification is a powerful tool for developers looking to integrate image generation capabilities into their applications. By leveraging customizable parameters, you can create unique, high-quality images tailored to your specific needs. Start experimenting with this action today and unlock new creative possibilities in your projects!