Create Stunning Images with the kayaeh/cha_flux Cognitive Actions

24 Apr 2025
Create Stunning Images with the kayaeh/cha_flux Cognitive Actions

In today's digital landscape, the ability to generate high-quality images programmatically is a game-changer for developers. The kayaeh/cha_flux spec provides powerful Cognitive Actions designed to help you generate images seamlessly using advanced AI models. Whether you're working on an art application, a game, or any other creative project, these pre-built actions simplify the process of image generation, offering flexibility and high-quality outputs.

Prerequisites

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

  • API Key: You will need an API key for the Cognitive Actions platform to authenticate your requests.
  • Setup: Familiarity with making HTTP requests and handling JSON data in your programming environment is required.

Authentication typically involves passing your API key in the request headers, ensuring secure access to the Cognitive Actions.

Cognitive Actions Overview

Generate Image with Prediction Model

The Generate Image with Prediction Model action is designed to create images using advanced techniques such as image-to-image generation and inpainting. By allowing the specification of parameters like dimensions and model types, this action empowers developers to produce high-quality, tailored images.

Input:

The input for this action requires the following fields:

  • prompt (required): A descriptive text that guides the image generation.
  • model (optional): Choose between "dev" for quality or "schnell" for speed.
  • width (optional): The width of the generated image (if applicable).
  • height (optional): The height of the generated image (if applicable).
  • aspectRatio (optional): The desired aspect ratio (e.g., "1:1").
  • outputFormat (optional): Format for the output images (e.g., "webp").
  • numOutputs (optional): The number of images to generate.

Here's an example of a valid input JSON payload:

{
  "model": "dev",
  "prompt": "CHA, a 27-year-old female, stands tall as a regal elf, inspired by \"The Lord of the Rings.\" Her pointed ears protrude gracefully from beneath long silver hair, and she dons an ornate, flowing gown adorned with gold accents and nature motifs. The dense, enchanted forest behind her glows with ethereal light as she gazes forward, her elegant face exuding wisdom and calm. The detailed landscape features towering trees and sparkling streams, blending seamlessly with her majestic presence.",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Output:

Upon successful execution, this action returns a URL pointing to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/8ee9b1e1-3827-4563-a203-f7a15498f832/62a1fdeb-4a59-4163-bed1-d76961f41b5a.webp"
]

Conceptual Usage Example (Python):

Here’s how you can call the Generate Image with Prediction Model 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 = "91e4c144-646a-4293-a5dd-5db199e2f563" # Action ID for Generate Image with Prediction Model

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "CHA, a 27-year-old female, stands tall as a regal elf, inspired by \"The Lord of the Rings.\" Her pointed ears protrude gracefully from beneath long silver hair, and she dons an ornate, flowing gown adorned with gold accents and nature motifs.",
    "loraScale": 1,
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "promptStrength": 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 snippet, replace the placeholder API key with your actual key. The action ID and structured input payload align with the requirements of the Generate Image with Prediction Model action.

Conclusion

The kayaeh/cha_flux Cognitive Actions provide a robust framework for generating images with advanced AI models. With the ability to customize inputs, you can create breathtaking visuals tailored to your application's needs. Explore further possibilities by integrating these actions into your projects, and push the boundaries of what's achievable with AI-generated imagery. Happy coding!