Generate Stunning Images with the bpriddy/dj-test-2 Cognitive Actions

22 Apr 2025
Generate Stunning Images with the bpriddy/dj-test-2 Cognitive Actions

In the realm of artificial intelligence, the ability to generate images based on textual prompts is revolutionizing creativity and design. The bpriddy/dj-test-2 API offers a powerful Cognitive Action called Generate Image with Prompt, which enables developers to create stunning visuals using descriptive input. This action supports various options for refinement, dimensions, and noise control, making it an essential tool for applications that require dynamic image generation.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • A basic understanding of JSON format and Python programming, as we will be structuring input payloads in JSON.

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

Cognitive Actions Overview

Generate Image with Prompt

The Generate Image with Prompt action allows you to create an image by providing a descriptive text prompt. This action offers flexibility with various options like img2img and inpainting modes, enabling fine-tuning of generated images.

  • Category: Image Generation

Input

The input schema for this action is a JSON object that includes several parameters. Below are the key fields along with their descriptions:

  • prompt (string): A descriptive input prompt that guides the generation of images. Default is "An astronaut riding a rainbow unicorn".
  • width (integer): Width of the output image in pixels. Default is 1024.
  • height (integer): Height of the output image in pixels. Default is 1024.
  • numOutputs (integer): The number of images to generate. Default is 1, maximum is 4.
  • guidanceScale (number): Scale factor for classifier-free guidance, ranging from 1 to 50. Default is 7.5.
  • promptStrength (number): Strength of the prompt when using img2img or inpaint mode, ranging from 0 to 1. Default is 0.8.
  • refinementMethod (string): Method to refine images, with options including "no_refiner", "expert_ensemble_refiner", and "base_image_refiner". Default is "no_refiner".

Here is an example of the JSON payload you might use:

{
  "width": 1024,
  "height": 1024,
  "prompt": "a photo of an authenticMX woman sitting in a garden",
  "loraScale": 0.6,
  "numOutputs": 1,
  "guidanceScale": 7.5,
  "highNoiseFrac": 0.8,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "refinementMethod": "no_refiner",
  "schedulingMethod": "K_EULER",
  "numInferenceSteps": 50
}

Output

Upon successful execution, the action will return a URL linking to the generated image. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/02ead33d-00bd-4f37-8884-6097c252ff0b/47eb018d-ad77-4c1a-80d6-6b08e7435edc.png"
]

This output provides a direct link to the newly generated image, allowing developers to easily retrieve and display it in their applications.

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Image with Prompt 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 = "5019dce2-bd54-4f53-8e2e-e47365582929" # Action ID for Generate Image with Prompt

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "a photo of an authenticMX woman sitting in a garden",
    "loraScale": 0.6,
    "numOutputs": 1,
    "guidanceScale": 7.5,
    "highNoiseFrac": 0.8,
    "applyWatermark": true,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "refinementMethod": "no_refiner",
    "schedulingMethod": "K_EULER",
    "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}")

In this example, the action ID and input payload are clearly structured, showcasing how to send a request to the Cognitive Actions endpoint. The output is handled gracefully, capturing any potential errors.

Conclusion

The Generate Image with Prompt action from the bpriddy/dj-test-2 API empowers developers to create visually appealing images based on text descriptions. With flexible parameters for customization, this action can be effortlessly integrated into various applications, enhancing user experience with AI-generated content.

Explore the possibilities of image generation and consider the various use cases where this technology can elevate your projects!