Create Stunning Matrix Code Art with the SDXL Cognitive Actions

21 Apr 2025
Create Stunning Matrix Code Art with the SDXL Cognitive Actions

In the realm of digital art and image generation, the fofr/sdxl-matrix-code API offers powerful Cognitive Actions that allow developers to create captivating visuals effortlessly. The Generate Matrix Code Art action is particularly noteworthy, as it leverages a fine-tuned model to produce images in the iconic style of Matrix Code art. With customizable parameters such as image dimensions, refinement steps, and prompt strength, developers can easily integrate these capabilities into their applications.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with JSON format for structuring requests and handling responses.

For authentication, you'll typically pass your API key in the headers of your requests, allowing you to securely access the Cognitive Actions you need.

Cognitive Actions Overview

Generate Matrix Code Art

Description: This action generates images in the style of Matrix Code art. It allows for fine-tuning through various parameters, making it versatile for different artistic expressions.

Category: Image Generation

Input:

  • mask (string, optional): URI of the input mask for inpainting.
  • seed (integer, optional): Random seed for reproducibility.
  • image (string, optional): URI of the input image for 'img2img' or 'inpaint' modes.
  • width (integer, default: 1024): Width of the output image in pixels.
  • height (integer, default: 1024): Height of the output image in pixels.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): The text prompt guiding the image generation.
  • loraScale (number, default: 0.6, range: 0-1): Scale factor for LoRA.
  • refineStyle (string, default: "no_refiner"): The style of refinement applied.
  • guidanceScale (number, default: 7.5, range: 1-50): Control for stronger guidance during creation.
  • applyWatermark (boolean, default: true): Indicates if a watermark should be added.
  • negativePrompt (string, default: ""): Elements to avoid in the image generation.
  • promptStrength (number, default: 0.8, range: 0-1): Influences the strength of the original prompt.
  • numberOfOutputs (integer, default: 1, range: 1-4): Number of images to generate.
  • refinementSteps (integer, optional): Steps for refining the image.
  • schedulingMethod (string, default: "K_EULER"): Method for scheduling denoising steps.
  • highNoiseFraction (number, default: 0.8, range: 0-1): Fraction of noise to use in refinement.
  • numInferenceSteps (integer, default: 50, range: 1-500): Total number of steps for denoising.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A landscape photo in the style of TOK, detailed, 8k",
  "loraScale": 0.9,
  "refineStyle": "expert_ensemble_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": false,
  "negativePrompt": "skintones, garish, low quality, jpeg artifacts, black and white",
  "promptStrength": 0.8,
  "numberOfOutputs": 4,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.95,
  "numInferenceSteps": 50
}

Output: The action typically returns an array of URLs pointing to the generated images:

[
  "https://assets.cognitiveactions.com/invocations/45cc5cde-f6c8-41ea-b9b3-5adfce17d178/b9dc0345-64f6-4466-91b9-5dc6a98d98ed.png",
  "https://assets.cognitiveactions.com/invocations/45cc5cde-f6c8-41ea-b9b3-5adfce17d178/4d1d062c-e537-4158-9400-eb3dae9f7fa3.png",
  "https://assets.cognitiveactions.com/invocations/45cc5cde-f6c8-41ea-b9b3-5adfce17d178/583db1ba-2bbe-4afe-96c4-85af2535ab2b.png",
  "https://assets.cognitiveactions.com/invocations/45cc5cde-f6c8-41ea-b9b3-5adfce17d178/2b60670d-b7e5-423b-89a1-c7c647b7fb51.png"
]

Conceptual Usage Example (Python): Here's how you might call the Generate Matrix Code Art 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 = "2e061571-1577-4e81-85ea-4f8db83f8a46" # Action ID for Generate Matrix Code Art

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "A landscape photo in the style of TOK, detailed, 8k",
    "loraScale": 0.9,
    "refineStyle": "expert_ensemble_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": False,
    "negativePrompt": "skintones, garish, low quality, jpeg artifacts, black and white",
    "promptStrength": 0.8,
    "numberOfOutputs": 4,
    "schedulingMethod": "K_EULER",
    "highNoiseFraction": 0.95,
    "numInferenceSteps": 50
}

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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable structures the input according to the action's requirements, and the request sends this payload to the Cognitive Actions endpoint. The response will contain the URLs of the generated images.

Conclusion

The Generate Matrix Code Art action from the fofr/sdxl-matrix-code API provides a robust solution for developers looking to create visually stunning images with minimal effort. With customizable parameters, you can tailor the output to your specific needs, allowing for a wide range of artistic expressions. Whether you're building a creative application or enhancing user engagement with generated visuals, these Cognitive Actions can significantly streamline your workflow. Explore the possibilities and start integrating today!