Create Stunning Images with Capim Labs' Cognitive Actions

22 Apr 2025
Create Stunning Images with Capim Labs' Cognitive Actions

In the realm of artificial intelligence, image generation has taken a significant leap forward, thanks to powerful tools that allow developers to create rich, high-quality visuals from mere text prompts. The Capim Labs' Cognitive Actions provide a seamless way to generate custom images using advanced models, incorporating features such as inpainting and various output formats. This article will guide you through the capabilities of the Generate Custom Image with Inpainting action, showing you how to integrate it into your applications effectively.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic familiarity with JSON and making HTTP requests.

Authentication is typically done by including the API key in the request headers. For instance, you would pass your API key as a bearer token when making requests to the Cognitive Actions endpoint.

Cognitive Actions Overview

Generate Custom Image with Inpainting

The Generate Custom Image with Inpainting action allows you to create high-quality images guided by a text prompt. This action supports specific models for optimized performance and provides image inpainting capabilities using masks. You can generate images that are not only visually appealing but also contextually relevant to your requirements.

Input: The input to this action is a JSON object that requires a prompt and supports a variety of optional fields. Here’s a breakdown of the input schema along with an example payload:

  • Required Field:
    • prompt (string): A descriptive text prompt for image generation.
  • Optional Fields:
    • mask (string): An image mask for inpainting (format: URI).
    • seed (integer): Random seed for consistent generation.
    • image (string): Input image for image to image or inpainting mode (format: URI).
    • width (integer): Width of the generated image (256-1440).
    • height (integer): Height of the generated image (256-1440).
    • goFast (boolean): Enable faster predictions.
    • aspectRatio (string): Aspect ratio for the generated image.
    • outputFormat (string): Format of the output image (webp, jpg, png).
    • guidanceScale (number): Scale for guiding the diffusion process.
    • numOutputs (integer): Number of images to generate (1-4).
    • Other parameters controlling various aspects of the generation process.

Example Input:

{
  "goFast": false,
  "prompt": "Quero uma foto profissional de Domingues, vestindo traje formal e posicionado de frente para a câmera. O fundo deve ser neutro e discreto, garantindo um visual sofisticado. A imagem deve transmitir a sensação de sucesso, confiança e profissionalismo. Apenas Domingues deve aparecer na foto.",
  "loraScale": 1,
  "modelType": "dev",
  "megapixels": "1",
  "numOutputs": 1,
  "aspectRatio": "16:9",
  "outputFormat": "jpg",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 1,
  "numInferenceSteps": 28
}

Output: The action typically returns a URL to the generated image. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/e2b0dcc4-e69d-42f1-b434-5c3c08f61796/a0c7c148-8744-4323-ab43-27ec71fe0ed8.jpg"
]

Conceptual Usage Example (Python): Here’s a conceptual Python code snippet to demonstrate how you might call the Cognitive Actions API to generate an image.

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 = "318d5b58-10e8-4e0f-9fa7-3f852364c874"  # Action ID for Generate Custom Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "Quero uma foto profissional de Domingues, vestindo traje formal e posicionado de frente para a câmera. O fundo deve ser neutro e discreto, garantindo um visual sofisticado. A imagem deve transmitir a sensação de sucesso, confiança e profissionalismo. Apenas Domingues deve aparecer na foto.",
    "loraScale": 1,
    "modelType": "dev",
    "megapixels": "1",
    "numOutputs": 1,
    "aspectRatio": "16:9",
    "outputFormat": "jpg",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 1,
    "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 variable is structured according to the input schema required by the action.
  • The response is handled gracefully, printing the generated image URL or any error messages encountered.

Conclusion

The Generate Custom Image with Inpainting action from Capim Labs' Cognitive Actions offers developers a robust and flexible tool for image generation. By leveraging this action, you can bring your creative ideas to life, generating stunning visuals in a matter of seconds. Whether for artistic purposes, marketing materials, or application assets, the possibilities are endless. Start integrating these Cognitive Actions into your applications today and unlock the power of AI-driven image generation!