Generate Stunning Images with warf23/agrat_me Cognitive Actions

22 Apr 2025
Generate Stunning Images with warf23/agrat_me Cognitive Actions

In today's digital landscape, the ability to generate custom images based on specific prompts opens up a world of possibilities for developers. The warf23/agrat_me specification provides an innovative Cognitive Action that allows you to create images with ease. This action empowers you to specify detailed prompts, control the generation parameters, and customize output formats. In this post, we will explore how to leverage this powerful action to enhance your applications.

Prerequisites

To get started with the warf23/agrat_me Cognitive Actions, you'll need an API key from the Cognitive Actions platform. Authentication typically involves passing this key in the request headers. Ensure you have the required setup in place to make API calls effectively.

Cognitive Actions Overview

Generate Custom Image

The Generate Custom Image action is designed to create images based on user-defined prompts. It supports various modes, including image-to-image and inpainting, allowing for flexibility in output. This action also provides control over denoising steps, guidance scale, and output formats, making it a robust tool for image generation.

Input

The input for this action is structured as follows:

{
  "prompt": "AGRAT as a 1920s gangster, three-quarter profile, smoky speakeasy setting, film noir style",
  "model": "dev",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 80,
  "extraLoraScale": 0.8,
  "numInferenceSteps": 28
}

Required Fields:

  • prompt: The prompt for generating the image.

Optional Fields:

  • mask: Image mask for inpainting mode.
  • seed: Random seed for reproducible results.
  • image: URI of the input image for image-to-image or inpainting.
  • model: Selects the model type (dev or schnell).
  • width and height: Specify dimensions when using custom aspect ratio.
  • goFast: Enables faster predictions.
  • numOutputs: Number of images to generate (1-4).
  • aspectRatio: Aspect ratio for the generated image.
  • outputFormat: Format of the output image.
  • guidanceScale: Scale for diffusion guidance.
  • outputQuality: Quality of the output image.
  • extraLoraScale: Intensity of extra LoRA application.
  • promptStrength: Strength of the prompt when using img2img.
  • numInferenceSteps: Number of denoising steps.
  • disableSafetyChecker: Disables safety checks.

Output

The output of this action is a URL pointing to the generated image. Here’s an example of what you might receive:

[
  "https://assets.cognitiveactions.com/invocations/e1c5d24d-1de5-4122-9f4b-6b47abb36115/e3b56987-392e-429b-9c9e-55109c8f42e6.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Custom 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 = "4a21ed1f-335b-4a94-8a9f-cfb751cd56d2"  # Action ID for Generate Custom Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "AGRAT as a 1920s gangster, three-quarter profile, smoky speakeasy setting, film noir style",
    "loraScale": 1,
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 80,
    "extraLoraScale": 0.8,
    "numInferenceSteps": 28
}

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 example, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The payload is constructed according to the input schema, and the action ID is specified for the request.

Conclusion

The warf23/agrat_me Cognitive Action for generating custom images provides a powerful tool for developers looking to enhance their applications with dynamic visual content. By leveraging this action, you can easily create customized images based on user input, control various parameters, and choose the desired output format. Explore the potential of this action in your projects and unlock new creative opportunities!