Transform Your Images with the Ben Johns Generator Cognitive Actions

23 Apr 2025
Transform Your Images with the Ben Johns Generator Cognitive Actions

In the world of image processing, the chicagohotcoffee/ben-johns-generator offers powerful Cognitive Actions that enable developers to create and manipulate images with ease. One of the standout capabilities is the ability to generate inpainted images, allowing for sophisticated transformations using advanced techniques. This article will guide you through the features of the Generate Inpainted Image action, showcasing its potential and how you can integrate it into your applications.

Prerequisites

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

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with making HTTP requests in your preferred programming language.

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

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows you to create and transform images using inpainting and image-to-image techniques. It optimizes speed and quality while offering customizable parameters like width, height, aspect ratio, and various image formats.

Input

The input for this action requires the following fields, with a mix of required and optional parameters:

  • prompt (required): A description of the desired image (e.g., "Closeup photo of benjohns playing pickleball").
  • mask: An image mask for inpainting mode.
  • seed: A random seed for reproducible generation.
  • image: An input image for image-to-image or inpainting mode.
  • model: Choose between "dev" for detailed output or "schnell" for faster results.
  • width: Width of the generated image (only if aspect_ratio is set to custom).
  • height: Height of the generated image (only if aspect_ratio is set to custom).
  • loraScale: Adjusts the main LoRA application strength.
  • imageFormat: Output format (webp, jpg, png).
  • imageQuality: Quality of the output image, from 0 to 100.
  • guidanceScale: Guidance scale for the diffusion process.
  • inferenceSteps: Number of denoising steps.
  • promptStrength: Strength of the prompt when using img2img.
  • imageResolution: Select the approximate number of megapixels for the generated image.
  • numberOfOutputs: Number of outputs to generate.
  • imageAspectRatio: Choose the aspect ratio for the generated image.

Here’s an example of how the input JSON payload may look:

{
  "model": "dev",
  "width": 1174,
  "prompt": "Closeup photo of benjohns playing pickleball",
  "loraScale": 1,
  "imageFormat": "webp",
  "imageQuality": 90,
  "guidanceScale": 3.5,
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "additionalLoraScale": 1
}

Output

The output of this action returns a URL to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/9e0aa5e2-4d6b-4812-b500-f3eff2431604/71d019c3-4054-4a7d-801e-124adea7ab71.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet to illustrate how you might call the Generate Inpainted 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 = "31162b0b-b161-4a07-8946-536fc57a850c"  # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "width": 1174,
    "prompt": "Closeup photo of benjohns playing pickleball",
    "loraScale": 1,
    "imageFormat": "webp",
    "imageQuality": 90,
    "guidanceScale": 3.5,
    "inferenceSteps": 28,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "imageAspectRatio": "1:1",
    "additionalLoraScale": 1
}

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 the COGNITIVE_ACTIONS_API_KEY with your actual API key and adjust the endpoint as needed. The payload variable contains the JSON structure required to call the Generate Inpainted Image action.

Conclusion

The Generate Inpainted Image action from the chicagohotcoffee/ben-johns-generator opens up a world of possibilities for developers looking to enhance their applications with advanced image generation and transformation capabilities. With customizable parameters, you can create stunning visuals tailored to your needs.

Explore the potential of these Cognitive Actions and consider integrating them into your projects to elevate your image processing capabilities!