Generate Stunning Images with the fofr/ays-text-to-image Cognitive Actions

22 Apr 2025
Generate Stunning Images with the fofr/ays-text-to-image Cognitive Actions

In the rapidly evolving field of artificial intelligence, the ability to generate high-quality images from textual descriptions has become more accessible than ever. The fofr/ays-text-to-image API provides developers with powerful Cognitive Actions designed for this purpose. Utilizing advanced models and sampling algorithms, these actions enable you to create compelling visuals, enhancing applications in various domains, from marketing to entertainment.

Prerequisites

Before you dive into using the Cognitive Actions, ensure you have the following:

  • API Key: You will need an API key to authenticate your requests. This key should be included in the headers of your API calls.
  • Development Environment: Set up a programming environment that supports making HTTP requests, such as Python with the requests library.

Conceptual Authentication

Authentication typically involves passing your API key in the headers of your requests, allowing you to securely interact with the Cognitive Actions platform.

Cognitive Actions Overview

Generate High-Quality Images with Align Your Steps

This action employs the "Align Your Steps" technique to produce faster and higher-quality images. By leveraging state-of-the-art models like SDXL and various sampling algorithms, it transforms text prompts into stunning visuals.

Input

The action requires the following input fields:

  • prompt (string): The main description for the image.
    Example: "a beautiful portrait photo of a cat"
  • antiPrompt (string): A negative prompt to guide image generation, helping to exclude certain elements.
    Example: ""
  • imageWidth (integer): The width of the generated image.
    Example: 1156
  • imageHeight (integer): The height of the generated image.
    Example: 768
  • imageFormat (string): The output format of the image, with options including "webp", "jpg", and "png".
    Example: "webp"
  • imageQuality (integer): The quality of the output image, ranging from 0 (lowest quality) to 100 (highest quality).
    Example: 80
  • modelVersion (string): Specifies which model version to use for image generation.
    Example: "ProteusV0.4.safetensors"
  • diffusionSteps (integer): The number of diffusion steps used, ranging from 10 to 100.
    Example: 10
  • numberOfOutputs (integer): The number of images to generate, ranging from 1 to 10.
    Example: 1
  • guidanceIntensity (number): The scale for classifier-free guidance, ranging from 0 to 30.
    Example: 7.5
  • samplingAlgorithm (string): The algorithm used for sampling during image generation.
    Example: "euler"

Example Input

{
  "prompt": "a beautiful portrait photo of a cat",
  "antiPrompt": "",
  "imageWidth": 1156,
  "imageFormat": "webp",
  "imageHeight": 768,
  "imageQuality": 80,
  "modelVersion": "ProteusV0.4.safetensors",
  "diffusionSteps": 10,
  "numberOfOutputs": 1,
  "guidanceIntensity": 7.5,
  "samplingAlgorithm": "euler"
}

Output

Upon successful execution, the action returns a URL to the generated image. An example output might look like this:

[
  "https://assets.cognitiveactions.com/invocations/f181d2c8-677a-4424-8617-e146e9d5d3b3/d020eab3-d4cf-4c88-9181-57b02ed6da69.webp"
]

Conceptual Usage Example (Python)

Here’s how you might structure a request to the Cognitive Actions API 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 = "cd6c7f62-3db2-48bf-ba38-4be9cb59af74"  # Action ID for Generate High-Quality Images with Align Your Steps

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "a beautiful portrait photo of a cat",
    "antiPrompt": "",
    "imageWidth": 1156,
    "imageFormat": "webp",
    "imageHeight": 768,
    "imageQuality": 80,
    "modelVersion": "ProteusV0.4.safetensors",
    "diffusionSteps": 10,
    "numberOfOutputs": 1,
    "guidanceIntensity": 7.5,
    "samplingAlgorithm": "euler"
}

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 the placeholder for your API key and adjust the action ID as necessary. The input payload conforms to the requirements of the Generate High-Quality Images action, ensuring a successful execution.

Conclusion

The fofr/ays-text-to-image Cognitive Actions provide developers with an efficient way to generate high-quality images from text prompts. By utilizing advanced models and configurable parameters, you can tailor the outputs to fit your specific needs, whether for creative projects, marketing campaigns, or other applications.

Explore the possibilities of image generation in your applications today with these powerful Cognitive Actions!