Generate Stunning Images with Inpainting: A Guide to bugnin/photo-black Cognitive Actions

24 Apr 2025
Generate Stunning Images with Inpainting: A Guide to bugnin/photo-black Cognitive Actions

In the world of AI and machine learning, image generation has become a rapidly evolving field. The bugnin/photo-black spec provides developers with powerful Cognitive Actions to generate high-quality images using advanced inpainting techniques. These pre-built actions simplify the process of creating images by allowing customization through various parameters such as image masks, aspect ratios, and output formats. This guide will walk you through the essentials of integrating the Generate Image with Inpainting action into your applications.

Prerequisites

Before you begin using the Cognitive Actions provided by the bugnin/photo-black spec, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Familiarity with JSON payloads and HTTP requests.
  • Basic knowledge of Python will be beneficial as we will demonstrate the conceptual usage with a Python code snippet.

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

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create detailed images by filling in parts of an image or generating new images based on a prompt. This action is categorized under image-generation.

Input

The required and optional fields for the input schema are as follows:

  • prompt (required): A string that describes the desired image content (e.g., "Beautiful woman is sad").
  • mask (optional): A URI string for an image mask used in inpainting mode.
  • image (optional): A URI string for an input image for image-to-image or inpainting mode.
  • model (optional): Specifies the model to use, either "dev" or "schnell" (default is "dev").
  • width (optional): An integer for the width of the generated image (256-1440).
  • height (optional): An integer for the height of the generated image (256-1440).
  • numberOfOutputs (optional): Specifies how many output images to generate (1-4).
  • imageAspectRatio (optional): Aspect ratio for the generated image (default is "1:1").
  • imageOutputFormat (optional): Format of the output image (default is "webp").
  • imageGuidanceScale (optional): A number that guides the diffusion process (0-10, default 3).
  • imageOutputQuality (optional): Quality of output images (0-100, default 80).
  • additionalLoraScale (optional): Adjusts intensity of additional LoRA (default 1).
  • imagePromptStrength (optional): Strength of the prompt during image-to-image mode (0-1, default 0.8).
  • numberOfInferenceSteps (optional): Number of denoising steps (1-50, default 28).

Here’s an example of the input JSON payload for invoking this action:

{
  "model": "schnell",
  "prompt": "Beautiful woman is sad",
  "numberOfOutputs": 1,
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "png",
  "imageGuidanceScale": 3.5,
  "imageOutputQuality": 90,
  "additionalLoraScale": 1,
  "imagePromptStrength": 0.8,
  "numberOfInferenceSteps": 28
}

Output

The output of this action typically includes a URL to the generated image. Here’s an example of what the output might look like:

[
  "https://assets.cognitiveactions.com/invocations/d2cdbdc3-41d3-4643-b2d8-679dd3b6a462/a3303a5c-6b5d-46f2-bb04-5ab62449b578.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Generate Image with Inpainting 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 = "08f41b09-b5de-45e3-9b56-fa3bd387d609" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "schnell",
    "prompt": "Beautiful woman is sad",
    "numberOfOutputs": 1,
    "imageAspectRatio": "16:9",
    "imageOutputFormat": "png",
    "imageGuidanceScale": 3.5,
    "imageOutputQuality": 90,
    "additionalLoraScale": 1,
    "imagePromptStrength": 0.8,
    "numberOfInferenceSteps": 28
}

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 snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the input schema, and the action ID corresponds to the Generate Image with Inpainting action. The endpoint URL is illustrative; consult the documentation for the exact endpoint.

Conclusion

The Generate Image with Inpainting action from the bugnin/photo-black spec provides developers with a robust tool to create stunning, high-quality images with customizable parameters. By leveraging this action, you can enhance your applications with advanced image generation capabilities.

Explore further by integrating this action into your workflows, experimenting with different parameters, and unlocking the potential of AI-driven image creation!