Enhance Your Applications with Image Generation: A Guide to the SDXL-Hiroshinagai Actions

24 Apr 2025
Enhance Your Applications with Image Generation: A Guide to the SDXL-Hiroshinagai Actions

In today's digital landscape, generating high-quality visuals programmatically can significantly enhance user experience and engagement. The SDXL-Hiroshinagai Cognitive Actions provide developers with a robust set of tools to create stunning images using advanced models. These actions support various functionalities including img2img transformations and inpainting, allowing for extensive customization of output dimensions, refinement methods, guidance scales, and more. In this article, we will explore how to utilize these Cognitive Actions effectively in your applications.

Prerequisites

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

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with making HTTP requests and handling JSON data.
  • Understanding of basic programming concepts, particularly in Python.

Authentication is typically handled by passing your API key in the headers of your requests, allowing you to interact with the Cognitive Actions seamlessly.

Cognitive Actions Overview

Generate Image using SDXL-Hiroshinagai Model

Description:
This action generates images utilizing a specialized SDXL model optimized for high-quality visual outputs. It supports both img2img and inpainting modes, with options for customizable output dimensions, refinement methods, guidance scales, and more.

Category: Image Generation

Input

The following schema outlines the required and optional inputs for this action:

{
  "mask": "string (uri) - URI of the input mask used in inpaint mode",
  "seed": "integer - Random seed for generation",
  "image": "string (uri) - URI of the input image for img2img or inpaint mode",
  "width": "integer - Width of the output image in pixels (default: 1024)",
  "height": "integer - Height of the output image in pixels (default: 1024)",
  "prompt": "string - Text prompt describing the desired output image",
  "refine": "string - Refinement method (default: no_refiner)",
  "loraScale": "number - LoRA scale factor (default: 0.6)",
  "scheduler": "string - Image generation scheduling method (default: K_EULER)",
  "numOutputs": "integer - Number of images to output (default: 1)",
  "loraWeights": "string - Specifies the LoRA weights to use",
  "refineSteps": "integer - Number of steps to refine the image when using base_image_refiner",
  "guidanceScale": "number - Classifier-free guidance scale (default: 7.5)",
  "highNoiseFrac": "number - Fraction of noise for expert_ensemble_refiner (default: 0.8)",
  "applyWatermark": "boolean - Apply watermark (default: true)",
  "negativePrompt": "string - Text prompt specifying unwanted elements",
  "promptStrength": "number - Strength of the text prompt (default: 0.8)",
  "numInferenceSteps": "integer - Number of denoising steps (default: 50)",
  "disableSafetyChecker": "boolean - Disable safety checker (default: false)"
}

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "In the style of HRNG women in white, sunflower field",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "numOutputs": 1,
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "dull, mediaeval, gore ",
  "promptStrength": 0.8,
  "numInferenceSteps": 50
}

Output

The action typically returns a list of URLs pointing to the generated images. Here’s an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/f028c132-0682-4b61-9b19-7a2f93327568/e19fc7af-f2c5-497b-ab93-816f4e59fde0.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet that demonstrates how to call this 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 = "ed120147-e2cb-493b-9f72-4191db003429"  # Action ID for Generate Image using SDXL-Hiroshinagai Model

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "In the style of HRNG women in white, sunflower field",
    "refine": "no_refiner",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "numOutputs": 1,
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": True,
    "negativePrompt": "dull, mediaeval, gore ",
    "promptStrength": 0.8,
    "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 action_id corresponds to the image generation action. The payload is structured according to the required input schema, and the request is sent to the hypothetical endpoint.

Conclusion

The SDXL-Hiroshinagai Cognitive Actions provide an impressive array of capabilities for developers looking to integrate advanced image generation features into their applications. With options for customization and high-quality output, these actions can significantly enhance user interaction and satisfaction. Start experimenting with these actions to unlock new creative possibilities in your projects!