Generate Stunning Images with AI: A Guide to Cognitive Actions for Image Generation

25 Apr 2025
Generate Stunning Images with AI: A Guide to Cognitive Actions for Image Generation

In the rapidly evolving field of artificial intelligence, generating images that closely mimic real-life aesthetics has become a sought-after capability. The ai-image-michael/vedana-chocolate-yogurt-2 API provides a powerful Cognitive Action designed for developers who want to leverage advanced image generation techniques. This action allows you to create sophisticated images using inpainting techniques and Low-Rank Adaptation (LoRA) models. By utilizing this pre-built action, you can save time and effort while achieving high-quality outputs tailored to your application's needs.

Prerequisites

To start using the Cognitive Actions for image generation, you’ll need an API key from the Cognitive Actions platform. This key will be used for authentication in your requests. Conceptually, you would pass the API key in the headers of your HTTP requests to authenticate your application with the service.

Cognitive Actions Overview

Generate Advanced Image with Inpainting and LoRA

Description:
This action generates sophisticated images by employing image inpainting techniques and LoRA models. It allows for optimization of the generation process, offering fast predictions or custom aspect ratios. You can choose between the 'dev' model for detailed outputs with 28 steps or the 'schnell' model for rapid results requiring only 4 steps.

Category: image-generation

Input

The following fields are required and optional for the action:

  • Required:
    • prompt: A description of the image you want to generate.
  • Optional:
    • mask: URI of the image mask for inpainting (ignores width, height).
    • seed: Random seed for reproducibility.
    • image: Input image for image-to-image or inpainting mode (ignores width, height).
    • width: Width of the generated image (only for custom aspect ratio).
    • height: Height of the generated image (only for custom aspect ratio).
    • goFast: Boolean to optimize predictions for speed.
    • aspectRatio: Defines the aspect ratio of the output image.
    • numOutputs: Number of output images to generate (1 to 4).
    • modelType: Choose between 'dev' or 'schnell' model.
    • outputFormat: Image format for output (options: webp, jpg, png).
    • guidanceScale: Sets the guidance scale for the diffusion process.
    • outputQuality: Quality level for output images (0-100).
    • extraLoraScale: Controls intensity of additional LoRA application.
    • promptStrength: Strength of the prompt in image generation.
    • imageResolution: Approximate resolution of the generated image.
    • numInferenceSteps: Total number of denoising steps.
    • disableSafetyChecker: Option to disable the safety checker.

Example Input:

{
  "goFast": false,
  "prompt": "A delicious bowl of vanilla yogurt with large cocoa nibs in it, similar to images from TOK. There is honey in the yogurt as well. The bowl is on a wooden kitchen table with a blue towel below it. The image could be featured in a cooking magazine.",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "numInferenceSteps": 28
}

Output

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

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/6aca428c-b019-4f02-b192-03fa2bfd81b2/ca97fe6e-31bf-453a-94a3-3c4e58387108.webp"
]

Conceptual Usage Example (Python)

Here’s how you can call the Cognitive Actions endpoint to generate an image 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 = "8bca4a5d-6800-4b86-a5a0-59cf854884f6" # Action ID for Generate Advanced Image with Inpainting and LoRA

# Construct the input payload based on the action's requirements
payload = {
    "goFast": false,
    "prompt": "A delicious bowl of vanilla yogurt with large cocoa nibs in it, similar to images from TOK. There is honey in the yogurt as well. The bowl is on a wooden kitchen table with a blue towel below it. The image could be featured in a cooking magazine.",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageResolution": "1",
    "numInferenceSteps": 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, replace the COGNITIVE_ACTIONS_API_KEY with your actual API key and adjust the endpoint if necessary. The action ID and input payload are structured according to the requirements of the Cognitive Action.

Conclusion

The Generate Advanced Image with Inpainting and LoRA action provides developers with a robust tool for creating high-quality images tailored to various use cases. By leveraging the power of advanced AI techniques, you can enhance your applications with visually appealing content. Explore this Cognitive Action and consider how it can fit into your next project to create stunning images effortlessly!