Generate Stunning Images with the Latent Consistency Model Actions

23 Apr 2025
Generate Stunning Images with the Latent Consistency Model Actions

In the rapidly evolving field of artificial intelligence, the ability to generate high-quality images has become increasingly accessible to developers. The fofr/latent-consistency-model provides a powerful Cognitive Action that allows developers to create stunning images using the Latent Consistency Model (LCM). This action offers a range of customization options, including img2img processing, guidance scaling, and image size adjustments, all while maintaining a fast execution time of approximately 0.6 seconds per image.

By integrating this Cognitive Action into your applications, you can enhance user experiences, create unique visuals for projects, and automate content generation with ease.

Prerequisites

Before you can start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which must be included in the request headers for authentication.
  • Familiarity with JSON payload structures and making HTTP requests.

Authentication is typically handled by passing your API key in the headers of your requests.

Cognitive Actions Overview

Generate Images with Latent Consistency Model

The Generate Images with Latent Consistency Model action creates high-quality images based on an input image and text prompt. This action is particularly useful for developers looking to implement advanced image generation features into their applications.

Input

The input for this action requires a JSON object with the following schema:

{
  "seed": "integer (optional)",
  "image": "string (uri, required)",
  "width": "integer (default: 768)",
  "height": "integer (default: 768)",
  "prompt": "string (default: 'Self-portrait oil painting...')",
  "controlImage": "string (uri, optional)",
  "guidanceScale": "number (default: 8, range: 1-20)",
  "archiveOutputs": "boolean (default: false)",
  "lcmOriginSteps": "integer (default: 50, min: 1)",
  "numberOfImages": "integer (default: 1, range: 1-50)",
  "promptStrength": "number (default: 0.8, range: 0-1)",
  "sizingStrategy": "string (default: 'width/height')",
  "cannyLowThreshold": "number (default: 100, range: 1-255)",
  "cannyHighThreshold": "number (default: 200, range: 1-255)",
  "controlGuidanceEnd": "number (default: 1, range: 0-1)",
  "controlGuidanceStart": "number (default: 0, range: 0-1)",
  "disableSafetyChecker": "boolean (default: false)",
  "numberOfInferenceSteps": "integer (default: 8, range: 1-50)",
  "controlnetConditioningScale": "number (default: 2, range: 0.1-4)"
}

Example Input:

{
  "image": "https://replicate.delivery/pbxt/JlG0Efd2ubBp9yGnlOi7I9Se2rXnJSrPFogLf0YieKgjnWN6/download-6.png",
  "width": 768,
  "height": 768,
  "prompt": "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k",
  "guidanceScale": 8,
  "archiveOutputs": false,
  "lcmOriginSteps": 50,
  "numberOfImages": 1,
  "promptStrength": 0.45,
  "sizingStrategy": "width/height",
  "cannyLowThreshold": 100,
  "cannyHighThreshold": 200,
  "controlGuidanceEnd": 1,
  "controlGuidanceStart": 0,
  "numberOfInferenceSteps": 4,
  "controlnetConditioningScale": 2
}

Output

The output from this action typically returns a list of image URIs that have been generated based on the provided input.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/46fd1364-ca9c-405a-82f1-db81d738cdf2/11f3bfc5-1d3a-49c3-a7b7-d459e647d351.jpg"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call this 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 = "d8d20552-2bc4-499e-81a4-b6f19fdd48fb" # Action ID for Generate Images with Latent Consistency Model

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/JlG0Efd2ubBp9yGnlOi7I9Se2rXnJSrPFogLf0YieKgjnWN6/download-6.png",
    "width": 768,
    "height": 768,
    "prompt": "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k",
    "guidanceScale": 8,
    "archiveOutputs": False,
    "lcmOriginSteps": 50,
    "numberOfImages": 1,
    "promptStrength": 0.45,
    "sizingStrategy": "width/height",
    "cannyLowThreshold": 100,
    "cannyHighThreshold": 200,
    "controlGuidanceEnd": 1,
    "controlGuidanceStart": 0,
    "numberOfInferenceSteps": 4,
    "controlnetConditioningScale": 2
}

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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for the image generation action is set, and the input payload is structured according to the action's requirements. The response is captured and printed in a readable format.

Conclusion

The Generate Images with Latent Consistency Model action is an invaluable tool for developers looking to integrate advanced image generation capabilities into their applications. With a plethora of customization options and quick execution times, this Cognitive Action can significantly enhance the creative potential of your projects.

Explore the possibilities of image generation by implementing this action, and consider extending its capabilities by combining it with other features offered by the Cognitive Actions platform!