Generate Stunning Images with ltejedor/cmf Cognitive Actions

24 Apr 2025
Generate Stunning Images with ltejedor/cmf Cognitive Actions

In the realm of creative applications, generating high-quality images from descriptive prompts has become a vital tool for developers. The ltejedor/cmf spec provides a powerful Cognitive Action that leverages a Stable Diffusion model fine-tuned on Color, Material, and Finish samples. This action enables developers to generate and refine images based on text prompts, allowing for extensive customization of various attributes.

The benefits of using these pre-built actions include the ability to produce visually captivating content without requiring deep expertise in image generation models. With a few API calls, you can integrate sophisticated image generation capabilities into your applications.

Prerequisites

Before you start utilizing the Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform.
  • Familiarity with sending HTTP requests to APIs.

Authentication typically involves passing your API key in the headers of your request, allowing for secure access to the actions provided.

Cognitive Actions Overview

Generate Fine-Tuned Image with Stable Diffusion

The Generate Fine-Tuned Image with Stable Diffusion action allows you to create and refine images based on text prompts while offering control over various generation parameters.

  • Category: image-generation
  • Purpose: This action generates images using a fine-tuned Stable Diffusion model, enabling customization of attributes such as image size, prompt strength, and the number of outputs.

Input

The input schema for this action requires the following fields:

  • prompt (string): The text prompt to guide the image generation.
    Example: "a chair made of marble, glossy finish, in the style of TOK"
  • width (integer): The width of the output image in pixels (default: 1024).
    Example: 512
  • height (integer): The height of the output image in pixels (default: 1024).
    Example: 512
  • refine (string): The refinement style to use (no_refiner, expert_ensemble_refiner, base_image_refiner).
    Example: "no_refiner"
  • loraScale (number): Scale factor for LoRA affecting model output (range: 0 to 1).
    Example: 0.6
  • scheduler (string): Specifies the scheduling algorithm to use during image generation.
    Example: "K_EULER"
  • numOutputs (integer): The number of image outputs to generate (range: 1 to 4).
    Example: 3
  • guidanceScale (number): Influences how closely the image follows the prompt (range: 1 to 50).
    Example: 7.5
  • highNoiseFrac (number): Fraction of noise used by the expert ensemble refiner (range: 0 to 1).
    Example: 0.8
  • applyWatermark (boolean): Apply a watermark to indicate image generation (default: true).
    Example: true
  • negativePrompt (string): Text prompt to specify aspects to avoid during image generation.
    Example: "" (empty string)
  • promptStrength (number): Strength of the prompt when using img2img or inpaint modes (range: 0 to 1).
    Example: 0.8
  • numInferenceSteps (integer): Specifies the number of denoising steps taken during inference (range: 1 to 500).
    Example: 50

Example of a complete JSON payload:

{
  "width": 512,
  "height": 512,
  "prompt": "a chair made of marble, glossy finish, in the style of TOK",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "numOutputs": 3,
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numInferenceSteps": 50
}

Output

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

[
  "https://assets.cognitiveactions.com/invocations/6be23b8a-d1ff-4c83-9b58-a281fe89c36f/4313ee49-6210-4de2-a867-1fc1fa1feca9.png",
  "https://assets.cognitiveactions.com/invocations/6be23b8a-d1ff-4c83-9b58-a281fe89c36f/8cef44b6-9f91-40e0-94f9-44df84d6e9cd.png",
  "https://assets.cognitiveactions.com/invocations/6be23b8a-d1ff-4c83-9b58-a281fe89c36f/80d9d7f2-120a-49e1-8c38-405905307faa.png"
]

Conceptual Usage Example (Python)

Here’s how you can invoke the Generate Fine-Tuned Image with Stable Diffusion 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 = "7712289d-f97d-4d87-9744-18031554d9f6" # Action ID for Generate Fine-Tuned Image with Stable Diffusion

# Construct the input payload based on the action's requirements
payload = {
    "width": 512,
    "height": 512,
    "prompt": "a chair made of marble, glossy finish, in the style of TOK",
    "refine": "no_refiner",
    "loraScale": 0.6,
    "scheduler": "K_EULER",
    "numOutputs": 3,
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": true,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numInferenceSteps": 50
}

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}")

This Python code snippet demonstrates how to set up the request, including the action ID and the input payload. The endpoint URL and request structure are illustrative and should be adjusted to match the actual API documentation.

Conclusion

The ltejedor/cmf Cognitive Actions provide developers with powerful image generation capabilities tailored to specific needs. By integrating the Generate Fine-Tuned Image with Stable Diffusion action into your applications, you can create stunning visual content quickly and efficiently. Explore the possibilities and enhance your applications with rich, customized imagery!