Generate Stunning Images with swk23/yoda-live Cognitive Actions

24 Apr 2025
Generate Stunning Images with swk23/yoda-live Cognitive Actions

In the realm of image generation, the swk23/yoda-live API offers powerful Cognitive Actions to create high-quality visuals tailored to your specifications. The "Generate Image with Inpainting" action allows developers to leverage advanced inpainting techniques, enabling customization of parameters like aspect ratio, resolution, and more. By utilizing pre-built actions, developers can streamline their workflows, saving time and resources while achieving impressive results.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which will allow you to authenticate your requests.
  • Familiarity with JSON format, as the input and output will be structured in this format.
  • Basic knowledge of making HTTP requests using libraries like requests in Python.

Conceptually, authentication can be accomplished by passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Image with Inpainting

Description: This action allows you to generate high-quality images using inpainting techniques with customizable parameters. You can enhance image details by adjusting various settings, ensuring optimized performance through models 'dev' and 'schnell'.

Category: image-generation

Input: The action requires a prompt as the fundamental input, with additional optional parameters to fine-tune the image generation. Below is the schema:

{
  "prompt": "string",  // Required
  "mask": "string",  // Optional, URI for image mask
  "seed": "integer",  // Optional for reproducibility
  "image": "string",  // Optional, URI of input image
  "width": "integer",  // Optional, width in pixels
  "height": "integer",  // Optional, height in pixels
  "layerScale": "number",  // Optional, LoRA application strength
  "numOutputs": "integer",  // Optional, number of images to generate
  "modelWeights": "string",  // Optional, source of LoRA weights
  "guidanceScale": "number",  // Optional, scale for realism
  "outputQuality": "integer",  // Optional, quality of output images
  "inferenceModel": "string",  // Optional, model selection
  "promptStrength": "number",  // Optional, strength of prompt
  "imageMegapixels": "string",  // Optional, number of megapixels
  "imageAspectRatio": "string",  // Optional, aspect ratio
  "optimizeForSpeed": "boolean",  // Optional, speed optimization
  "imageOutputFormat": "string",  // Optional, output format
  "numInferenceSteps": "integer",  // Optional, denoising steps
  "additionalLayerScale": "number",  // Optional, extra LoRA strength
  "disableSafetyChecker": "boolean",  // Optional, disable checker
  "additionalLayerWeights": "string"  // Optional, additional weights
}

Example Input:

{
  "prompt": "Grand Master Yoda stands alone in the vast halls of the Jedi Temple, his small figure framed by towering columns and intricate stonework. His wise, ancient eyes hold a quiet intensity, his expression thoughtful yet unreadable. Draped in his traditional Jedi robe, the fabric worn yet dignified, he leans slightly on his gimer stick, his grip firm but relaxed. The soft glow of temple lanterns casts gentle shadows across his weathered features, emphasizing the weight of centuries of wisdom and leadership. Though alone, his presence fills the space—an enduring symbol of strength, knowledge, and the guiding light of the Jedi Order.",
  "layerScale": 1,
  "numOutputs": 1,
  "guidanceScale": 3,
  "outputQuality": 80,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "21:9",
  "optimizeForSpeed": false,
  "imageOutputFormat": "jpg",
  "numInferenceSteps": 28,
  "additionalLayerScale": 1
}

Output: The action typically returns a URL to the generated image. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/59698564-e82e-4250-89c4-1ded3538df0e/f20b6e88-adb5-4d81-a040-9ddeff0794fe.jpg"
]

Conceptual Usage Example (Python): Here’s how you can invoke the "Generate Image with Inpainting" action 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 = "fd15d87e-b5f9-40b5-bd02-0aeef0e46e15" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Grand Master Yoda stands alone in the vast halls of the Jedi Temple, his small figure framed by towering columns and intricate stonework. His wise, ancient eyes hold a quiet intensity, his expression thoughtful yet unreadable. Draped in his traditional Jedi robe, the fabric worn yet dignified, he leans slightly on his gimer stick, his grip firm but relaxed. The soft glow of temple lanterns casts gentle shadows across his weathered features, emphasizing the weight of centuries of wisdom and leadership. Though alone, his presence fills the space—an enduring symbol of strength, knowledge, and the guiding light of the Jedi Order.",
    "layerScale": 1,
    "numOutputs": 1,
    "guidanceScale": 3,
    "outputQuality": 80,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "21:9",
    "optimizeForSpeed": False,
    "imageOutputFormat": "jpg",
    "numInferenceSteps": 28,
    "additionalLayerScale": 1
}

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 example, replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key and adjust the endpoint URL as needed. The input payload is structured according to the specifications of the action, ensuring you can efficiently generate stunning images.

Conclusion

The swk23/yoda-live Cognitive Actions provide robust capabilities for image generation, allowing developers to create tailored visuals with ease. By understanding the parameters and utilizing the provided examples, you can unlock the full potential of image generation in your applications. Consider experimenting with various settings to see how they influence the final output, and integrate these actions into your projects to enhance user experiences. Happy coding!