Create Stunning Images with Inpainting Using yacinesy/dh1212 Cognitive Actions

25 Apr 2025
Create Stunning Images with Inpainting Using yacinesy/dh1212 Cognitive Actions

In the realm of AI-driven creativity, the yacinesy/dh1212 API offers a powerful Cognitive Action that allows developers to generate images through advanced inpainting technology. This action enables users to create customized visuals by leveraging features like image masks, specific models, varying output qualities, and more. By using these pre-built actions, developers can seamlessly integrate sophisticated image generation capabilities into their applications, enhancing user engagement and creativity without requiring deep expertise in machine learning.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • A basic understanding of JSON structure, as the input and output formats will rely on it.

Authentication typically involves passing your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows for the creation of images using inpainting technology, enabling the customization of various components such as image masks, size, and quality.

  • Category: Image Generation

Input

The input schema requires several fields, with prompt being mandatory:

  • prompt (string): A detailed description of the desired image.
  • mask (string, optional): URI of the image mask for inpainting.
  • seed (integer, optional): Random seed for reproducible results.
  • image (string, optional): URI of the input image for inpainting or image-to-image generation.
  • width (integer, optional): Width of the generated image in pixels.
  • height (integer, optional): Height of the generated image in pixels.
  • goFast (boolean, optional): Enable fast generation mode.
  • numOutputs (integer, optional): Number of images to generate (1-4).
  • guidanceScale (number, optional): Guidance scale for the diffusion process.
  • outputQuality (integer, optional): Quality level for output images (0-100).
  • algorithmModel (string, optional): Model selection for inference.
  • imageAspectRatio (string, optional): Desired aspect ratio for the generated image.
  • imageOutputFormat (string, optional): Format for output images (webp, jpg, png).
  • numInferenceSteps (integer, optional): Total number of denoising steps.

Here’s an example of a JSON payload for this action:

{
  "prompt": "A stylish man walks confidently down an outdoor cobblestone street, dressed in an impeccably tailored dark blue three-piece suit. The suit is paired with a crisp white dress shirt and a rich burgundy tie, along with a matching pocket square in the jacket. His polished brown leather dress shoes add a touch of sophistication to the ensemble. The scene takes place in an elegant urban environment, with classic old buildings and cars parked along the sides, emphasizing the refined and upscale atmosphere of the exterior setting",
  "loraScale": 1,
  "numOutputs": 1,
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "algorithmModel": "dev",
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "numInferenceSteps": 28
}

Output

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

[
  "https://assets.cognitiveactions.com/invocations/86474eaf-8315-4177-9ff8-88ad1f012672/1eee778e-cb0f-4f23-85fc-411170d7a855.webp"
]

Conceptual Usage Example (Python)

Here’s how a developer might call this action using a Python script:

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 = "9596c10a-688c-4ac8-92ff-76fe65e4ed9c"  # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "A stylish man walks confidently down an outdoor cobblestone street, dressed in an impeccably tailored dark blue three-piece suit. The suit is paired with a crisp white dress shirt and a rich burgundy tie, along with a matching pocket square in the jacket. His polished brown leather dress shoes add a touch of sophistication to the ensemble. The scene takes place in an elegant urban environment, with classic old buildings and cars parked along the sides, emphasizing the refined and upscale atmosphere of the exterior setting",
    "loraScale": 1,
    "numOutputs": 1,
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "algorithmModel": "dev",
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "numInferenceSteps": 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 code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured according to the required input schema, and the action ID corresponds to the Generate Image with Inpainting action.

Conclusion

The yacinesy/dh1212 Cognitive Actions provide a robust framework for generating customized images through inpainting. By leveraging these actions, developers can enhance their applications with visually captivating content that resonates with users. Consider exploring further use cases such as integrating these image generation capabilities into creative applications, marketing tools, or personalized content platforms. Happy coding!