Create Customized Images Effortlessly with the YuvalRef Cognitive Actions

22 Apr 2025
Create Customized Images Effortlessly with the YuvalRef Cognitive Actions

In the rapidly evolving field of artificial intelligence, the ability to generate customized images can greatly enhance applications in various domains such as gaming, marketing, and content creation. The YuvalRef Cognitive Actions provide developers with advanced capabilities for image generation, leveraging sophisticated techniques like inpainting and prompt-based influences. This guide will walk you through the powerful Generate Customized Image action, its functionalities, and how to integrate it into your applications seamlessly.

Prerequisites

Before diving into the integration, ensure you have the following:

  • API Key: Obtain an API key for the Cognitive Actions platform to authenticate your requests.
  • Setup: Familiarize yourself with making HTTP requests and handling JSON data.

Authentication generally involves passing your API key in the request headers, allowing you to access the Cognitive Actions securely.

Cognitive Actions Overview

Generate Customized Image

The Generate Customized Image action allows you to create images tailored to specific requirements. By using advanced inpainting and image-to-image generation techniques, you can customize dimensions, aspect ratios, and quality settings to meet your needs. This action is particularly beneficial for applications requiring personalized content generation.

Input

The action requires a specific JSON schema for input, which includes both required and optional fields:

  • Required:
    • prompt: A string that guides the generation of the image (e.g., a description of the desired output).
  • Optional:
    • mask: (string) An image mask for inpainting mode.
    • seed: (integer) Sets a random seed for reproducibility.
    • image: (string) Input image for image-to-image or inpainting mode.
    • model: (string) Selects the model for inference (dev or schnell).
    • width: (integer) Width of the generated image (if custom aspect ratio).
    • height: (integer) Height of the generated image (if custom aspect ratio).
    • fastMode: (boolean) Enables a model optimized for speed.
    • imageFormat: (string) Format for the output image (webp, jpg, or png).
    • imageQuality: (integer) Quality of the output image (0 to 100).
    • outputQuantity: (integer) Number of outputs to generate (1 to 4).
    • imageAspectRatio: (string) Aspect ratio for the generated image.
    • And more...

Here is an example of the input JSON payload:

{
  "model": "dev",
  "prompt": "yuvalref woman face to the camera\n\n\n",
  "fastMode": false,
  "imageFormat": "jpg",
  "imageQuality": 80,
  "loraIntensity": 1,
  "inferenceSteps": 28,
  "outputQuantity": 1,
  "imageResolution": "1",
  "promptIntensity": 0.8,
  "imageAspectRatio": "16:9",
  "guidanceIntensity": 3,
  "additionalLoraIntensity": 1
}

Output

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

[
  "https://assets.cognitiveactions.com/invocations/8de1b57e-e84b-49ce-99bc-a0c76d1d7d39/e5275e40-13ba-4fcf-bc71-559cda8f8715.jpg"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Customized Image 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 = "f8f861e5-2bd6-48b6-a5dc-aee67fee74f4"  # Action ID for Generate Customized Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "yuvalref woman face to the camera\n\n\n",
    "fastMode": False,
    "imageFormat": "jpg",
    "imageQuality": 80,
    "loraIntensity": 1,
    "inferenceSteps": 28,
    "outputQuantity": 1,
    "imageResolution": "1",
    "promptIntensity": 0.8,
    "imageAspectRatio": "16:9",
    "guidanceIntensity": 3,
    "additionalLoraIntensity": 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 snippet:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action_id corresponds to the Generate Customized Image action.
  • The payload is structured according to the input schema, ensuring all required fields are filled.

Conclusion

The Generate Customized Image action within the YuvalRef Cognitive Actions offers developers a robust tool for creating personalized images tailored to specific styles and requirements. By leveraging this action, you can enhance your applications with unique visual content, streamline your creative processes, and engage your users more effectively.

As a next step, consider exploring other actions provided in the YuvalRef spec to further expand the capabilities of your applications!