Generate Stunning Images with the Shangray11 Cognitive Actions

21 Apr 2025
Generate Stunning Images with the Shangray11 Cognitive Actions

Creating compelling visuals has never been easier with the Shangray11 Cognitive Actions. This set of powerful image generation actions allows developers to synthesize detailed images based on custom parameters, integrating seamlessly into applications. By leveraging these pre-built actions, you can enhance your projects with tailored image outputs that meet specific requirements, improving both speed and quality.

Prerequisites

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

  • API Key: You will need an API key for the Cognitive Actions platform to authenticate your requests. This key is typically included in the headers of your API calls.
  • Development Environment: A suitable programming environment set up for making HTTP requests (e.g., Python with requests library).

Conceptually, authentication can be handled by passing your API key in the request headers, as demonstrated in the upcoming code examples.

Cognitive Actions Overview

Generate Image Using Custom Parameters

Description: This action allows you to generate detailed images by specifying parameters such as image size, format, and LoRA intensity. You can choose between two models, "dev" for quality and "schnell" for speed, and utilize custom prompts and optional image masks for inpainting.

  • Category: Image Generation

Input: The input schema for this action requires at least a prompt. Here’s a breakdown of the required and optional fields:

{
  "prompt": "a selfie photo of shawn in the mountains, sitting by campfire at night, moon lit sky, half body image wearing a baby blue and white new your yankee jersey and blue jeans, wearing a baby blue new york yankee hat with model shanny in the photo",
  "model": "dev",
  "aspectRatio": "16:9",
  "loraStrength": 1,
  "guidanceScale": 1.52,
  "enableFastMode": false,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "numberOfOutputs": 4,
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "additionalLoraScale": 1,
  "numberOfInferenceSteps": 40
}

Output: The action typically returns an array of URLs pointing to the generated images. Here’s an example of what the output might look like:

[
  "https://assets.cognitiveactions.com/invocations/4e9ec03a-193a-476f-b36f-0c78f8f5830c/694d36f3-e3a0-47a0-ad1d-ec2c7b0e7562.webp",
  "https://assets.cognitiveactions.com/invocations/4e9ec03a-193a-476f-b36f-0c78f8f5830c/58c3dda1-4003-4116-a9cb-a19697554770.webp",
  "https://assets.cognitiveactions.com/invocations/4e9ec03a-193a-476f-b36f-0c78f8f5830c/588c42d0-95bf-4802-b595-d1a9fda33d4f.webp",
  "https://assets.cognitiveactions.com/invocations/4e9ec03a-193a-476f-b36f-0c78f8f5830c/9ad040d1-7119-41ae-8f5b-18ef6ec136e7.webp"
]

Conceptual Usage Example (Python):

Here’s a conceptual Python code snippet illustrating how to call the 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 = "ae262ba4-693b-4609-96e2-599130d5ced7"  # Action ID for Generate Image Using Custom Parameters

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "a selfie photo of shawn in the mountains, sitting by campfire at night, moon lit sky, half body image wearing a baby blue and white new your yankee jersey and blue jeans, wearing a baby blue new york yankee hat with model shanny in the photo",
    "aspectRatio": "16:9",
    "loraStrength": 1,
    "guidanceScale": 1.52,
    "enableFastMode": False,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "numberOfOutputs": 4,
    "imageOutputFormat": "webp",
    "imageOutputQuality": 80,
    "additionalLoraScale": 1,
    "numberOfInferenceSteps": 40
}

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 placeholders with your actual API key and ensure the action ID and input payload are structured correctly. The endpoint URL is illustrative and should be modified based on the actual API documentation.

Conclusion

The Shangray11 Cognitive Actions empower developers to create stunning images tailored to specific needs with ease. By utilizing the image generation capabilities, you can enhance user experiences and deliver visually engaging content. Explore more potential use cases, and consider integrating these actions into your applications to unlock new creative possibilities.