Enhance Your Applications with Image Generation using Mejiabrayan/Bar Cognitive Actions

22 Apr 2025
Enhance Your Applications with Image Generation using Mejiabrayan/Bar Cognitive Actions

In the realm of digital creativity, the Mejiabrayan/Bar Cognitive Actions offer powerful tools for developers looking to integrate advanced image generation capabilities into their applications. These Cognitive Actions, particularly geared towards image generation and inpainting, allow you to create stunning images with a variety of customizable parameters. By utilizing these pre-built actions, developers can save time and effort while achieving impressive results in their projects.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of making API requests, particularly how to send JSON payloads via HTTP.
  • Python installed on your machine, along with the requests library for making API calls.

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

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows developers to create images with enhanced control over various attributes. This includes applying masks, specifying image dimensions, and refining the output quality. It also supports default prompts for quick utilization and allows for custom guidance through various schedulers and classifiers.

Input

The input for this action requires a structured JSON object, as defined in the schema. Here’s a breakdown of key fields:

  • mask (string): URI of the input mask for inpainting. Black areas are preserved; white areas are subject to inpainting.
  • seed (integer, optional): Sets the seed for random processes. If left blank, the seed is randomized.
  • image (string): URI of the input image used for img2img or inpainting modes.
  • width (integer, default 1024): Specifies the width of the output image in pixels.
  • height (integer, default 1024): Specifies the height of the output image in pixels.
  • prompt (string, default "An astronaut riding a rainbow unicorn"): Textual input guiding the image generation process.
  • numberOfOutputs (integer, default 1): Total number of images to produce (1 to 4).

Example Input

Here’s an example of how the JSON payload might look when calling this action:

{
  "width": 1024,
  "height": 1024,
  "prompt": "headshot of a beautiful white woman with dark green eyes glasses and sunkissed brown curly hair",
  "loraScale": 0.55,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.81,
  "numberOfInferenceSteps": 50
}

Output

Upon successful execution, the action returns a URL to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/f871d29a-ddc1-4cc1-b775-4f46e4f53d46/1317e229-7d47-4b8a-8dbc-a0d00beffa71.png"
]

Conceptual Usage Example (Python)

Here’s how you might call the Generate Image with Inpainting action from your Python application:

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 = "f7aaf215-101b-49cc-a3a6-880f1e5ef565"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "headshot of a beautiful white woman with dark green eyes glasses and sunkissed brown curly hair",
    "loraScale": 0.55,
    "refineStyle": "no_refiner",
    "guidanceScale": 7.5,
    "applyWatermark": True,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "schedulingMethod": "K_EULER",
    "highNoiseFraction": 0.81,
    "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 code snippet, you will replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload must be structured appropriately to match the requirements of the Cognitive Action.

Conclusion

The Mejiabrayan/Bar Cognitive Actions, particularly the Generate Image with Inpainting functionality, empower developers to create customized and high-quality images, enhancing their applications significantly. By integrating these actions, you can streamline your workflow and focus on building creative features. Consider exploring additional use cases such as automated content generation or interactive applications that leverage these powerful image generation capabilities. Get started today and see how these Cognitive Actions can transform your digital projects!