Enhance Your Application's Creativity with SDXL-Yuki Cognitive Actions

22 Apr 2025
Enhance Your Application's Creativity with SDXL-Yuki Cognitive Actions

In the realm of artificial intelligence and image generation, the code-and-cakes/sdxl-yuki API provides powerful Cognitive Actions designed to create and refine images based on user prompts. With capabilities like inpainting, customizable refinement methods, and the ability to generate multiple outputs, these actions empower developers to integrate creative image generation into their applications seamlessly.

Prerequisites

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

  • An API key for the Cognitive Actions platform that allows access to the image generation features.
  • Basic knowledge of how to make HTTP requests in your programming language of choice.
  • Familiarity with JSON for structuring requests and responses.

For authentication, you will typically include your API key in the headers of your requests. This allows you to securely access the various Cognitive Actions available.

Cognitive Actions Overview

Generate and Inpaint Image

Description: This action enables the creation and refinement of images using prompts, with advanced inpainting capabilities. It allows the selection of multiple schedulers and refinement methods, enhancing the quality of generated images. Additionally, it supports generating multiple outputs, applying watermarks, and even disabling the safety checker if needed.

Category: image-generation

Input

The input for this action requires a JSON object structured according to the following schema:

{
  "mask": "string (uri)",
  "seed": "integer",
  "image": "string (uri)",
  "width": "integer (default: 1024)",
  "height": "integer (default: 1024)",
  "prompt": "string (default: 'An astronaut riding a rainbow unicorn')",
  "refine": "enum (no_refiner, expert_ensemble_refiner, base_image_refiner)",
  "loraScale": "number (default: 0.6)",
  "scheduler": "enum (DDIM, DPMSolverMultistep, HeunDiscrete, KarrasDPM, K_EULER_ANCESTRAL, K_EULER, PNDM)",
  "refineSteps": "integer",
  "addWatermark": "boolean (default: true)",
  "guidanceScale": "number (default: 7.5)",
  "negativePrompt": "string",
  "promptStrength": "number (default: 0.8)",
  "numberOfOutputs": "integer (default: 1)",
  "additionalWeights": "string",
  "highNoiseFraction": "number (default: 0.8)",
  "safetyCheckerDisabled": "boolean (default: false)",
  "numberOfInferenceSteps": "integer (default: 50)"
}

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "In the style of TOK, a photo of a cat in the river high quality, well-detailed",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "KarrasDPM",
  "addWatermark": true,
  "guidanceScale": 7.5,
  "negativePrompt": "Deformed eyes, wrinkled, wrinkles, old, ((disfigured)), ((bad art)), ((deformed)), ((extra limbs)), ((duplicated)), ((morbid)), ((mutilated)), out of frame, extra fingers, mutated hands, poorly drawn eyes, ((poorly drawn hands)), ((poorly drawn face)), ((extra legs))), (fused fingers), (too many fingers), ((long neck)), tiling, poorly drawn, mutated, cross-eye, canvas frame, frame, cartoon, 3d, weird colors, blurry, ((old)), ((ugly)), ((child))",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 50
}

Output

The output of this action is a JSON array containing the URLs of the generated images. Here is a typical example of the output:

[
  "https://assets.cognitiveactions.com/invocations/374c30e1-a3e0-4959-b3c8-4b3d51f7157d/31a6bbf3-7f9a-4269-a2c0-b8d9c3a9f10b.png"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to call the Generate and Inpaint Image 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 = "37abb748-d986-4cbe-873a-4764f31d74b1" # Action ID for Generate and Inpaint Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "In the style of TOK, a photo of a cat in the river high quality, well-detailed",
    "refine": "no_refiner",
    "loraScale": 0.6,
    "scheduler": "KarrasDPM",
    "addWatermark": True,
    "guidanceScale": 7.5,
    "negativePrompt": "Deformed eyes, wrinkled, wrinkles, old, ((disfigured)), ((bad art)), ((deformed)), ((extra limbs)), ((duplicated)), ((morbid)), ((mutilated)), out of frame, extra fingers, mutated hands, poorly drawn eyes, ((poorly drawn hands)), ((poorly drawn face)), ((extra legs))), (fused fingers), (too many fingers), ((long neck)), tiling, poorly drawn, mutated, cross-eye, canvas frame, frame, cartoon, 3d, weird colors, blurry, ((old)), ((ugly)), ((child))",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "highNoiseFraction": 0.8,
    "numberOfInferenceSteps": 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 snippet, the action ID and input payload are included, and the request is sent to the hypothetical endpoint. The response is printed out, allowing for easy debugging and verification.

Conclusion

The code-and-cakes/sdxl-yuki Cognitive Actions provide developers with a robust toolkit for generating and refining images through intuitive prompts. By integrating these actions, you can enhance your applications with advanced image creation capabilities, offering users a unique and creative experience. Explore the various configurations and customize the output to fit your needs, and start building innovative applications today!