Create Stunning Images with jingyan/cfl-1 Cognitive Actions

21 Apr 2025
Create Stunning Images with jingyan/cfl-1 Cognitive Actions

In today's digital landscape, generating unique and captivating visuals can greatly enhance user engagement. The jingyan/cfl-1 spec offers a powerful Cognitive Action that allows developers to create custom images using advanced machine learning techniques such as Dreambooth and Stable Diffusion (SD 1.5). This action leverages text prompts to guide the image generation process, enabling a wide range of creative possibilities. By integrating these pre-built actions into your applications, you can automate and streamline the process of image creation.

Prerequisites

Before diving into the integration of these Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Basic familiarity with JSON and HTTP requests.

Authentication typically involves passing your API key in the request headers, allowing you to securely access the available actions.

Cognitive Actions Overview

Generate Dreambooth Image

The Generate Dreambooth Image action creates a custom image based on a text prompt, utilizing a model trained with Dreambooth and SD 1.5. This action is categorized under image generation and offers various parameters to tailor the output to your needs.

Input

The input for this action is structured as follows:

  • seed (optional): An integer seed for generating variations. If omitted, a random seed is used.
  • image (optional): A URI of a starting image for generating variations (img2img). If provided, the output will match the dimensions of this image.
  • width (optional): Width of the output image. Defaults to 512, with maximum dimensions of either 1024x768 or 768x1024.
  • height (optional): Height of the output image. Defaults to 512, with the same maximum dimensions as width.
  • prompt (required): A text description of the desired image. For example, "a photo of a cfl boy on great wall of ancient China".
  • scheduler (optional): The algorithm for managing the image generation (default is "DDIM").
  • guidanceScale (optional): A number defining the adherence level to the input prompt, with a default of 7.5.
  • negativePrompt (optional): Elements to exclude from the generated image.
  • promptStrength (optional): A value between 0 and 1 defining the influence of the prompt when an initial image is provided; defaults to 0.8.
  • numberOfOutputs (optional): Specifies how many images to generate in the output (default is 1, maximum is 4).
  • disableSafetyCheck (optional): Option to bypass safety checks (use at your own risk).
  • numberOfInferenceSteps (optional): Total steps for refining the image, with a default of 50.

Here’s an example of the input JSON payload:

{
  "width": 512,
  "height": 512,
  "prompt": "a photo of a cfl boy on great wall of ancient China",
  "scheduler": "DDIM",
  "guidanceScale": 7.5,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 50
}

Output

Upon executing this action, you will receive a response containing the generated image(s). The typical output is a list of URLs to the created images. For instance:

[
  "https://assets.cognitiveactions.com/invocations/ad0eeb2f-f660-4e9c-82a4-92f0b5c7000f/c90fed79-7482-4986-a47f-68fca4305fe9.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Dreambooth 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 = "075faa36-a0d6-40e6-8590-8df48c26dee5" # Action ID for Generate Dreambooth Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 512,
    "height": 512,
    "prompt": "a photo of a cfl boy on great wall of ancient China",
    "scheduler": "DDIM",
    "guidanceScale": 7.5,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 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}")

In this example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The input payload is structured according to the action's requirements, allowing you to customize the image generation process.

Conclusion

The Generate Dreambooth Image action from the jingyan/cfl-1 spec empowers developers to create stunning visuals based on text descriptions, making it easier than ever to enhance applications with custom imagery. With its flexibility and ease of integration, consider exploring additional use cases such as creating marketing materials, enhancing user interfaces, or generating unique artwork. Happy coding!