Create Stunning Images with the stevo607/ai-stevo Cognitive Actions

23 Apr 2025
Create Stunning Images with the stevo607/ai-stevo Cognitive Actions

In today's digital landscape, generating images from textual prompts has become increasingly valuable for developers looking to enhance their applications with visual content. The stevo607/ai-stevo Cognitive Actions provide a robust method to create images using custom models, allowing for a high degree of personalization and control over the output. This article will guide you through the capabilities of the Generate Image with Custom Model action, detailing how to leverage its features to generate unique images based on your specific requirements.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of JSON and Python programming.
  • A development environment set up to make HTTP requests.

Authentication typically involves passing your API key in the request headers, ensuring that your application can securely interact with the Cognitive Actions service.

Cognitive Actions Overview

Generate Image with Custom Model

The Generate Image with Custom Model action allows you to create images based on a text prompt while providing numerous customization options such as aspect ratio, dimensions, and output quality. It supports advanced features like image-to-image mode and prompt strength, making it an excellent tool for developers looking to integrate sophisticated image generation capabilities into their applications.

Input

The input for this action is defined by the following schema:

{
  "prompt": "a photo of AI-Stevo wearing a dark suit with a red tie",
  "goFast": false,
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "numInferenceSteps": 28
}
  • Required Field:
    • prompt: The text prompt for generating the image.
  • Optional Fields:
    • mask: URI for an image mask (for image inpainting).
    • seed: An integer to set a random seed for reproducible results.
    • image: URI for an input image (for image-to-image generation).
    • width and height: Integers for custom image dimensions.
    • aspectRatio: The aspect ratio for the output image.
    • outputFormat: Format for the output image (e.g., webp, jpg, png).
    • Many more options for scaling, quality, and additional features.

Output

Upon successful execution, the action returns a URL to the generated image. Here’s an example of the output:

[
  "https://assets.cognitiveactions.com/invocations/f4b48e4f-b14e-437a-ae34-fa76d5785164/8f30134d-9649-4025-af2c-3845d3a19235.webp"
]

The URL links to the generated image, allowing you to retrieve and use it in your application.

Conceptual Usage Example (Python)

Here’s a conceptual code snippet demonstrating how you might call this 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 = "f2df050a-3ef2-47d4-a049-9bbbc5e9689f"  # Action ID for Generate Image with Custom Model

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "a photo of AI-Stevo wearing a dark suit with a red tie",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageResolution": "1",
    "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 code, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured to match the input schema, ensuring that all necessary parameters are included.

Conclusion

The stevo607/ai-stevo Cognitive Action for generating images with custom models offers a powerful tool for developers looking to incorporate advanced image generation capabilities into their applications. By understanding the input parameters and output structure, you can create stunning visuals tailored to your needs. As you explore the possibilities of this action, consider experimenting with various prompts and customization options to achieve the best results for your projects. Happy coding!