Create Stunning Artwork with adalab-ai/kandinsky_v2_2 Cognitive Actions

25 Apr 2025
Create Stunning Artwork with adalab-ai/kandinsky_v2_2 Cognitive Actions

In the world of AI-driven art generation, the adalab-ai/kandinsky_v2_2 API offers a powerful set of Cognitive Actions designed for developers looking to create unique visual experiences. The primary action available allows you to generate images inspired by the style of Wassily Kandinsky by mixing text prompts and image inputs. This can be a game-changer for applications in creative fields, allowing for the rapid creation of customized artworks based on user input.

Prerequisites

Before you dive into using the Cognitive Actions, ensure you have the following:

  • API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform.
  • Basic Understanding of JSON: Familiarity with JSON format will help you structure your input and interpret the output effectively.

Authentication typically involves sending your API key in the headers of your request, allowing you to securely access the actions.

Cognitive Actions Overview

Generate Kandinsky Style Images

Purpose

This action allows you to generate images using the Kandinsky 2.2 model by combining text prompts and image inputs. You can customize various parameters to influence the style and appearance of the generated artwork.

Category: image-generation

Input

The input for this action is structured as follows:

  • task (string, required): The task to perform. Currently, only "text2img" is supported.
  • width (integer, optional): Width of the output image in pixels (default: 512, range: 64-1024).
  • height (integer, optional): Height of the output image in pixels (default: 512, range: 64-1024).
  • prompt (string, required): Text prompt describing the desired output. Use vivid and descriptive language for best results.
  • scheduler (string, optional): Scheduling strategy (default: "unipc"). Options: "dpm", "ddim", "unipc".
  • imageWeight (number, optional): Influence of the image relative to text (default: 1, range: 0-10).
  • guidanceScale (number, optional): Scale for classifier-free guidance (default: 4, range: 1-10).
  • negativePrompt (string, optional): List aspects to avoid in the output.
  • numberOfOutputs (integer, optional): Number of images to generate (default: 1, range: 1-4).
  • numberOfStepsPrior (integer, optional): Number of initial denoising steps (default: 2, range: 1-500).
  • numberOfInferenceSteps (integer, optional): Total number of denoising inference steps (default: 18, range: 1-500).

Example Input:

{
  "task": "text2img",
  "width": 1024,
  "height": 1024,
  "prompt": "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting",
  "scheduler": "unipc",
  "imageWeight": 1,
  "guidanceScale": 4,
  "negativePrompt": "ugly, tiling, oversaturated, undersaturated, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft",
  "numberOfOutputs": 1,
  "numberOfStepsPrior": 2,
  "numberOfInferenceSteps": 18
}

Output

The action typically returns an array of URIs pointing to the generated images. For example:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/53ee61cf-4c8c-4c32-a2f2-5ad74e625534/1d05e754-ad31-4bb6-9e04-7f92dc00e4b8.png"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how you might call the Cognitive Actions execution endpoint to generate an image.

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 = "336f32e1-1979-46a3-87db-55e64850f169" # Action ID for Generate Kandinsky Style Images

# Construct the input payload based on the action's requirements
payload = {
    "task": "text2img",
    "width": 1024,
    "height": 1024,
    "prompt": "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting",
    "scheduler": "unipc",
    "imageWeight": 1,
    "guidanceScale": 4,
    "negativePrompt": "ugly, tiling, oversaturated, undersaturated, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft",
    "numberOfOutputs": 1,
    "numberOfStepsPrior": 2,
    "numberOfInferenceSteps": 18
}

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 snippet, replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload section is constructed based on the required input schema for the "Generate Kandinsky Style Images" action. The endpoint URL and request structure provided are illustrative; you should adapt them according to the actual API specifications.

Conclusion

Integrating the adalab-ai/kandinsky_v2_2 Cognitive Actions into your application can unlock endless creative possibilities. By leveraging the ability to generate unique images based on text prompts and images, you can enhance user engagement and offer personalized artistic experiences. Whether for a digital art platform, a game, or a social media application, these tools provide a robust foundation for innovative visual content creation. Explore the capabilities and let your creativity flow!