Create Stunning Images with the mdzor/weapons-items Cognitive Actions

21 Apr 2025
Create Stunning Images with the mdzor/weapons-items Cognitive Actions

In the realm of digital content creation, the ability to generate high-quality images can significantly enhance user engagement and experience. The mdzor/weapons-items specification provides a powerful Cognitive Action that enables developers to leverage advanced image generation techniques, including inpainting and img2img processes. This action is designed to facilitate the creation of diverse visual content, allowing for customization in dimensions, prompts, noise levels, and more. In this article, we will delve into the capabilities of the Generate Image with Inpainting action, its input and output structures, and provide a conceptual usage example for integration.

Prerequisites

Before you begin integrating the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of making HTTP requests and handling JSON data.

Authentication typically involves passing your API key in the request headers, which will allow you to access and execute the actions securely.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows developers to create images through advanced generation techniques. This operation can utilize mask-based inpainting, enabling modifications to specific areas of an image while preserving others. It supports various refinement styles and scheduling algorithms, making it ideal for generating unique visual content.

Input

The input for this action requires a structured JSON object, which consists of several fields:

  • mask (string, URI): The URI of the input mask for inpainting. Black areas are preserved, while white areas are modified.
  • seed (integer, optional): A random seed for reproducibility; leave blank for a randomized seed.
  • image (string, URI): The URI of the input image used in img2img or inpainting modes.
  • width (integer, default: 1024): The width of the output image.
  • height (integer, default: 1024): The height of the output image.
  • prompt (string, default: "An astronaut riding a rainbow unicorn"): A text prompt to guide the image generation process.
  • refine (string, default: "no_refiner"): The refinement algorithm applied after initial image generation.
  • scheduler (string, default: "K_EULER"): The algorithm used for scheduling the denoising process.
  • layerScale (number, default: 0.6): Scale for LoRA adjustments, applicable only on trained models.
  • modelWeights (string, optional): LoRA model weights to use; leave blank for defaults.
  • guidanceScale (number, default: 7.5): Strength of classifier-free guidance.
  • numberOfOutputs (integer, default: 1): Number of images to generate, between 1 and 4.
  • promptIntensity (number, default: 0.8): Intensity of the input prompt in img2img or inpainting.
  • refinementSteps (integer, optional): Number of refinement steps used in the base image refiner.
  • highNoiseFraction (number, default: 0.8): Fraction of noise applied in the expert ensemble refiner.
  • inferenceStepCount (integer, default: 50): Total number of denoising steps.
  • inputNegativePrompt (string, default: ""): Negative prompt to suppress specific features.
  • watermarkApplication (boolean, default: true): Adds a watermark to indicate generated content.
  • safetyCheckerDisabled (boolean, default: false): Disable the safety checker for generated images.

Here’s a practical example of the JSON payload needed to invoke this action:

{
  "width": 1024,
  "height": 1024,
  "prompt": "TOK, a chest, with gold coins inside",
  "refine": "no_refiner",
  "scheduler": "K_EULER",
  "layerScale": 0.6,
  "guidanceScale": 7.5,
  "numberOfOutputs": 1,
  "promptIntensity": 0.8,
  "highNoiseFraction": 0.8,
  "inferenceStepCount": 50,
  "inputNegativePrompt": "",
  "watermarkApplication": true
}

Output

Upon successful execution, the action typically returns a JSON response containing the URIs of the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/4e62d5cc-9066-4b40-bf62-81097a3b8bfa/1e32b150-c12f-4c68-be40-3daec028e066.png"
]

This output provides a link to the newly created image, which can be used directly in your application.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet that illustrates how to call the Cognitive Actions execution endpoint:

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 = "e3f9f135-f87a-49c5-b0db-93cbe661e440" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "TOK, a chest, with gold coins inside",
    "refine": "no_refiner",
    "scheduler": "K_EULER",
    "layerScale": 0.6,
    "guidanceScale": 7.5,
    "numberOfOutputs": 1,
    "promptIntensity": 0.8,
    "highNoiseFraction": 0.8,
    "inferenceStepCount": 50,
    "inputNegativePrompt": "",
    "watermarkApplication": true
}

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:

  • Replace the placeholder API key and endpoint with your actual credentials.
  • The action_id corresponds to the Generate Image with Inpainting action.
  • The payload is structured according to the action’s requirements.

Conclusion

The Generate Image with Inpainting Cognitive Action provides developers with powerful tools to create stunning images tailored to their needs. By leveraging advanced image generation techniques, you can enhance your applications with unique visual content. As a next step, consider exploring different prompts and customization options to see how they affect the generated images, and think about integrating this action into your creative workflows. Happy coding!