Enhance Your Applications with Image Generation: A Guide to swk23/cwstyle Cognitive Actions

21 Apr 2025
Enhance Your Applications with Image Generation: A Guide to swk23/cwstyle Cognitive Actions

In the realm of artificial intelligence, image generation has transformed the way we create visual content. The swk23/cwstyle API offers powerful Cognitive Actions that allow developers to generate stunning images through cutting-edge techniques such as inpainting and image-to-image processing. These pre-built actions enable you to produce high-quality images tailored to your specific needs with customizable parameters, making it easier than ever to integrate advanced image generation capabilities into your applications.

Prerequisites

To get started with the Cognitive Actions in the swk23/cwstyle API, you need to have:

  • An API key to access the Cognitive Actions platform.
  • Familiarity with sending HTTP requests, as you will be interacting with an API endpoint.

Authentication typically requires you to pass your API key in the request headers to gain access to the image generation functionalities.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images using advanced inpainting and image-to-image techniques. You can customize dimensions, formats, and styles, choosing between 'dev' or 'schnell' models for optimized performance. The action supports various parameters to fine-tune your generated images.

Input

The input schema for this action requires a prompt and accepts a wide range of optional fields:

{
  "prompt": "string",
  "mask": "string (uri)",
  "seed": "integer",
  "image": "string (uri)",
  "model": "string (enum: ['dev', 'schnell'])",
  "width": "integer",
  "height": "integer",
  "fastMode": "boolean",
  "megapixels": "string (enum: ['1', '0.25'])",
  "loraIntensity": "number",
  "denoisingSteps": "integer",
  "outputQuantity": "integer",
  "imageAspectRatio": "string (enum: ['1:1', '16:9', '21:9', '3:2', '2:3', '4:5', '5:4', '3:4', '4:3', '9:16', '9:21', 'custom'])",
  "loraModelWeights": "string",
  "imageOutputFormat": "string (enum: ['webp', 'jpg', 'png'])",
  "imageOutputQuality": "integer",
  "imagePromptStrength": "number",
  "additionalLoraWeights": "string",
  "safetyCheckerDisabled": "boolean",
  "diffusionGuidanceScale": "number",
  "additionalLoraIntensity": "number"
}

Example Input:

{
  "model": "dev",
  "prompt": "\"Luke Skywalker in all-black Jedi clothing, seated cross-legged in a dark, shadowy room, meditating in serene focus. His shaggy blond hair falls softly around his face, illuminated faintly by the gentle green glow of his lightsaber resting before him. The atmosphere is tranquil, with ancient stone walls barely visible in the dim light, creating a sense of mystery and quiet power.\"",
  "fastMode": false,
  "megapixels": "1",
  "loraIntensity": 1,
  "denoisingSteps": 28,
  "outputQuantity": 1,
  "imageAspectRatio": "21:9",
  "imageOutputFormat": "jpg",
  "imageOutputQuality": 80,
  "imagePromptStrength": 0.8,
  "diffusionGuidanceScale": 3,
  "additionalLoraIntensity": 1
}

Output

The action typically returns a list of URLs pointing to the generated images:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/85afc9dd-c8ab-4eea-9346-0bfdac46e4bf/9e358440-772e-4c25-bc4d-037b0f83ef02.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 = "4c95619e-b5bd-4470-9bc2-3cb2bb2f8670" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "\"Luke Skywalker in all-black Jedi clothing, seated cross-legged in a dark, shadowy room, meditating in serene focus. His shaggy blond hair falls softly around his face, illuminated faintly by the gentle green glow of his lightsaber resting before him. The atmosphere is tranquil, with ancient stone walls barely visible in the dim light, creating a sense of mystery and quiet power.\"",
    "fastMode": False,
    "megapixels": "1",
    "loraIntensity": 1,
    "denoisingSteps": 28,
    "outputQuantity": 1,
    "imageAspectRatio": "21:9",
    "imageOutputFormat": "jpg",
    "imageOutputQuality": 80,
    "imagePromptStrength": 0.8,
    "diffusionGuidanceScale": 3,
    "additionalLoraIntensity": 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 Python code snippet, you replace your API key and the hypothetical endpoint with the actual values. The input payload is constructed according to the requirements of the Generate Image with Inpainting action. The response is then printed, showing the generated image's URL(s).

Conclusion

With the swk23/cwstyle Cognitive Actions, generating high-quality images has never been easier. By leveraging powerful features like inpainting and customizable parameters, developers can create unique visual content that enhances their applications. Explore these actions further to unlock new creative possibilities in your projects!