Create Stunning Images from Text Prompts with Cognitive Actions

26 Apr 2025
Create Stunning Images from Text Prompts with Cognitive Actions

In today's digital landscape, the ability to generate images from textual descriptions opens up a world of creative possibilities. The "Test Model" service provides developers with powerful Cognitive Actions that simplify the image generation process. With features like custom aspect ratios, output formats, and multiple model options for speed or quality, developers can create stunning visuals tailored to their specific needs. Whether you're building an art generation app, enhancing gaming visuals, or creating unique marketing content, this service can streamline your workflow and elevate your projects.

Prerequisites

To get started with the Test Model, you'll need an API key for the Cognitive Actions service and a basic understanding of making API calls.

Execute Image Generation

The "Execute Image Generation" action allows you to perform an image generation task using textual prompts. This action is particularly useful for developers looking to create custom images based on specific descriptions. By leveraging this functionality, you can solve the problem of manual image creation, saving time and resources while producing high-quality visuals.

Input Requirements

To utilize this action, you need to provide a structured input that includes:

  • prompt: A detailed textual description of the desired image. This is the only required field.
  • mask: Optional URI for an image mask to use in inpainting mode.
  • seed: An integer to ensure reproducibility of the generated image.
  • model: Specifies which model to use, with options like "dev" for speed or "schnell" for quality.
  • width, height: Dimensions for the image, applicable if using a custom aspect ratio.
  • aspectRatio: Defines the image's aspect ratio, with options for common ratios or a custom setting.
  • imageFormat: The output format, such as "webp", "jpg", or "png".
  • Additional parameters like guidanceScale, outputQuality, numberOfOutputs, and others allow for further customization.

Expected Output

The output will be a URI link to the generated image, which can be used directly in your applications or for further processing.

Use Cases for this specific action

This action is ideal for various scenarios, including:

  • Art Generation: Artists can generate artworks based on their descriptions, experimenting with styles and themes.
  • Game Development: Game developers can create unique character designs or environments by simply describing them in text.
  • Marketing Content: Marketers can generate eye-catching visuals for campaigns without needing graphic design skills.
  • Personal Projects: Hobbyists and enthusiasts can explore their creativity by generating images based on their ideas and prompts.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "9c2aaa62-85e2-4b35-becd-6f41c5ff75c8" # Action ID for: Execute Image Generation

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "model": "dev",
  "prompt": "female warrior TOKTOK in an opal chainmail cuirass, her hand on the hilt of a sheathed sword. Torches gutter behind her in the dark room, creating rim lighting. Rendered in the Arcane (Netflix) style: stylized realism, painterly brushwork, cinematic color grading, and emotionally expressive lighting",
  "loraScale": 1,
  "megapixels": "1",
  "aspectRatio": "1:1",
  "imageFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "enableFastMode": false,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 28
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The "Test Model" service with its image generation capabilities offers developers a powerful tool to create custom visuals efficiently. By utilizing the Execute Image Generation action, you can streamline your creative processes, whether for professional projects or personal endeavors. The flexibility in customization allows you to experiment with various inputs to achieve the desired outcome. As you integrate this functionality, consider how it can enhance your applications and engage your audience with stunning, tailor-made images. Start exploring the possibilities today!