Unleashing Image Generation with Inpainting Using the jesuserondon/tokjer1 Cognitive Actions

21 Apr 2025
Unleashing Image Generation with Inpainting Using the jesuserondon/tokjer1 Cognitive Actions

In today's digital landscape, generating images that reflect creativity and precision is crucial for various applications, from marketing to content creation. The jesuserondon/tokjer1 Cognitive Actions offer a powerful set of tools for developers looking to integrate sophisticated image generation capabilities into their applications. Among these tools, the Generate Image with Inpainting action stands out, providing options to manipulate and create stunning visuals using advanced inpainting techniques.

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.
  • Basic knowledge of JSON and RESTful APIs to structure your requests effectively.

To authenticate your requests, you will typically include your API key in the header of your HTTP calls.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images using inpainting techniques while adjusting parameters for optimal results. This action is categorized under image-generation.

Input

The input schema for this action requires you to provide a JSON object with the following fields:

  • prompt (required): A descriptive text prompt for generating the image.
  • image (optional): A URI pointing to an input image for transformation or inpainting.
  • mask (optional): A URI for an image mask that defines areas to inpaint.
  • model (optional): Specifies the model to use, either dev or schnell.
  • width (optional): Custom width for the generated image.
  • height (optional): Custom height for the generated image.
  • aspectRatio (optional): Defines the aspect ratio of the generated image.
  • outputCount (optional): Number of images to generate.
  • outputFormat (optional): Desired format for the output images.
  • guidanceScale (optional): Adjusts the diffusion guidance scale during generation.
  • outputQuality (optional): Quality level of the output images.

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

{
  "image": "https://replicate.delivery/pbxt/MbRLQRBHo5pMKaKVnuY3pQIi0qRzMhickRmKRUSPfEyd8y81/ComfyUI_00004_.png",
  "model": "dev",
  "prompt": "Photorealistic portrait of TokJer1, a confident man in front of a classroom chalkboard with 'Aumenta tus ingresos' written on it, with symbols mathematical complementary. Wearing a white button-up shirt, rolled-up sleeves, and fitted jeans. Friendly expression, slight smile, relaxed posture, soft cinematic lighting.",
  "loraScale": 1,
  "megapixels": "1",
  "aspectRatio": "9:16",
  "outputCount": 2,
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 90,
  "enableFastMode": false,
  "promptStrength": 0.9,
  "numInferenceSteps": 28,
  "additionalLoraScale": 1
}

Output

The output of this action typically consists of an array of image URLs, which point to the generated images. Here’s an example of what you might expect in response:

[
  "https://assets.cognitiveactions.com/invocations/dd3e2571-beb8-4d1d-ab57-b5483e56c118/12273de0-a668-4f39-9814-594a55cfdfd2.webp",
  "https://assets.cognitiveactions.com/invocations/dd3e2571-beb8-4d1d-ab57-b5483e56c118/cbf4b2c8-96b9-4dbf-8923-f7d6ade58e77.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet that demonstrates how to call the Generate Image with Inpainting action. This example uses a hypothetical endpoint and assumes you have set your API key.

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 = "0172be95-d0f3-449f-a85b-5f30be37ac41" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/MbRLQRBHo5pMKaKVnuY3pQIi0qRzMhickRmKRUSPfEyd8y81/ComfyUI_00004_.png",
    "model": "dev",
    "prompt": "Photorealistic portrait of TokJer1...",
    "loraScale": 1,
    "megapixels": "1",
    "aspectRatio": "9:16",
    "outputCount": 2,
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 90,
    "enableFastMode": False,
    "promptStrength": 0.9,
    "numInferenceSteps": 28,
    "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, the action_id variable is set to the ID for the Generate Image with Inpainting action. The input payload is structured according to the action's requirements, and the request is sent to the hypothetical endpoint URL.

Conclusion

The jesuserondon/tokjer1 Cognitive Actions, particularly the Generate Image with Inpainting, empower developers to create high-quality images with ease. By leveraging the flexibility of parameters like prompt strength, aspect ratio, and model selection, you can fine-tune the output to meet your application's needs. As you explore these capabilities, consider various use cases, from enhancing user-generated content to automating creative design processes. Happy coding!