Create Stunning Images with the carlpuvosx/twittex Cognitive Actions

24 Apr 2025
Create Stunning Images with the carlpuvosx/twittex Cognitive Actions

In today’s digital landscape, the ability to generate hyperrealistic images from text prompts can significantly enhance applications, from social media content creation to gaming environments. The carlpuvosx/twittex Cognitive Actions provide developers with powerful tools to create captivating visuals effortlessly. This guide will delve into the Generate Image from Prompt action, explaining how to integrate it into your applications for impressive results.

Prerequisites

To utilize the Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform.
  • Familiarity with JSON formatting for input data.
  • A basic understanding of making HTTP requests.

Authentication typically involves passing the API key in the request headers.

Cognitive Actions Overview

Generate Image from Prompt

The Generate Image from Prompt action is designed to create hyperrealistic images based on specific prompts and customizable parameters. This action supports various image inpainting features, aspect ratios, and output formats, all optimized for speed and quality enhancements.

Input

The input for this action requires the following:

  • prompt (string, required): The text prompt that guides the image generation. Example: "Create a futuristic cityscape on Mars..."
  • mask (string, optional): URI for an image mask used in inpainting mode.
  • seed (integer, optional): A random seed for consistent image generation.
  • image (string, optional): URI for an input image used in image-to-image or inpainting modes.
  • width (integer, optional): Width of the generated image (256 to 1440 pixels).
  • height (integer, optional): Height of the generated image (256 to 1440 pixels).
  • loraScale (number, optional): Intensity of applying the main LoRA (default 1).
  • aspectRatio (string, optional): The aspect ratio for the generated image (default: 1:1).
  • outputCount (integer, optional): Number of image outputs to generate (1 to 4).
  • outputFormat (string, optional): The output format (default: webp).
  • guidanceScale (number, optional): Guidance scale factor (default 3).
  • outputQuality (integer, optional): Specifies the quality of saved images (0 to 100).
  • Additional fields for advanced image generation options.

Example Input:

{
  "prompt": "TOKx-twitterxxx \"Create a futuristic cityscape on Mars...\"",
  "loraScale": 1,
  "aspectRatio": "3:2",
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "inferenceStepCount": 28
}

Output

The action typically returns a URL pointing to the generated image, formatted based on the requested output format.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/fef0753d-e745-4118-9f24-ff82f863dfb5/34f0b09c-abbd-4568-b8f7-36124ffe460e.webp"
]

Conceptual Usage Example (Python)

Here’s how you can invoke the Generate Image from Prompt action using a conceptual Python script:

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 = "05f25666-841e-4a07-ad50-87169a118085" # Action ID for Generate Image from Prompt

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "TOKx-twitterxxx \"Create a futuristic cityscape on Mars...\"",
    "loraScale": 1,
    "aspectRatio": "3:2",
    "outputCount": 1,
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "inferenceStepCount": 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, we define the action ID and format the input payload according to the action's requirements. The code sends a POST request to a hypothetical endpoint, handling authentication and output processing seamlessly.

Conclusion

The Generate Image from Prompt action from the carlpuvosx/twittex Cognitive Actions suite empowers developers to create stunning, hyperrealistic images using simple text prompts. With customizable parameters and robust features, you can elevate your applications to new heights. Start experimenting with these actions to unlock creative possibilities in your projects!