Generate Stunning Images with the hadasadler/yoavai Cognitive Actions

24 Apr 2025
Generate Stunning Images with the hadasadler/yoavai Cognitive Actions

In the world of image generation, the hadasadler/yoavai API offers powerful capabilities that allow developers to create high-quality images with advanced customization options. The Cognitive Actions provided by this API enable a seamless integration of image generation into your applications, allowing for creative and dynamic visual content generation. With the ability to utilize image masks, aspect ratios, and various models optimized for speed and quality, these actions empower developers to enhance their applications significantly.

Prerequisites

Before diving into the Cognitive Actions, ensure you have the following in place:

  • API Key: You will need an API key to authenticate your requests to the hadasadler/yoavai service. This key should be included in the headers of your API requests.
  • Setup: Familiarity with making API calls in your preferred programming language is essential, as this will help you integrate these actions into your applications effectively.

Cognitive Actions Overview

Generate Enhanced Image

The Generate Enhanced Image action allows you to create high-quality images using either image-to-image or inpainting modes. You can customize your outputs extensively, choosing aspects like image masks, aspect ratios, and model-specific optimizations for speed and detail. The action supports two models: 'dev' for optimal performance and 'schnell' for faster generation.

  • Category: image-generation

Input

The required and optional fields for this action are defined in the schema:

  • Required:
    • prompt (string): The text prompt guiding the image generation.
  • Optional:
    • mask (string): URI for image mask (inpainting mode).
    • seed (integer): Seed for reproducibility.
    • image (string): URI for an input image.
    • width (integer): Width of the generated image (custom aspect ratio).
    • height (integer): Height of the generated image (custom aspect ratio).
    • goFast (boolean): Enables a speed-optimized model.
    • outputCount (integer): Number of images to generate (1-4).
    • modelWeights (string): Load LoRA weights from model repositories.
    • guidanceScale (number): Scale for the diffusion process (0-10).
    • mainLoraScale (number): Strength of the main LoRA.
    • outputQuality (integer): Image quality setting (0-100).
    • additionalLora (string): Specify additional LoRA weights.
    • inferenceModel (string): Select model for inference ('dev' or 'schnell').
    • inferenceSteps (integer): Number of denoising steps (1-50).
    • promptStrength (number): Strength when using image-to-image.
    • imageMegapixels (string): Approximate number of megapixels.
    • imageAspectRatio (string): Aspect ratio for the generated image.
    • imageOutputFormat (string): Output file format (webp, jpg, png).
    • additionalLoraScale (number): Strength of the extra LoRA.
    • safetyCheckerDisabled (boolean): Disable the safety checker.

Example Input

Here’s a practical example of how to structure the input JSON payload for this action:

{
  "goFast": false,
  "prompt": "yoavai man, wearing glasses, pulling out a giant dusty book, only for a cascade of hidden bookmarks to fall out like confetti.\n\n",
  "outputCount": 1,
  "guidanceScale": 3,
  "mainLoraScale": 1,
  "outputQuality": 80,
  "inferenceModel": "dev",
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "jpg",
  "additionalLoraScale": 1
}

Output

The action typically returns a list of URLs pointing to the generated images. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/4b8737a6-f4bb-4713-9b51-577b40c617c9/96158663-1b60-4c03-a03d-99197e7bb277.jpg"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Enhanced Image 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 = "c916e0e5-6087-4d54-aa5a-a1346cf706f1" # Action ID for Generate Enhanced Image

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "yoavai man, wearing glasses, pulling out a giant dusty book, only for a cascade of hidden bookmarks to fall out like confetti.\n\n",
    "outputCount": 1,
    "guidanceScale": 3,
    "mainLoraScale": 1,
    "outputQuality": 80,
    "inferenceModel": "dev",
    "inferenceSteps": 28,
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "16:9",
    "imageOutputFormat": "jpg",
    "additionalLoraScale": 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 Python snippet, replace the COGNITIVE_ACTIONS_API_KEY and the endpoint with your actual values. The action_id corresponds to the Generate Enhanced Image action. The input payload is structured based on the required parameters, ensuring that your API call is correctly formatted.

Conclusion

The hadasadler/yoavai Cognitive Actions provide a robust toolkit for developers looking to integrate advanced image generation capabilities into their applications. By utilizing the Generate Enhanced Image action, you can create stunning visuals tailored to your needs. With its extensive customization options, you can explore various creative possibilities. To get started, implement this action in your projects and experiment with different parameters to see what unique images you can generate!