Elevate Your Visual Creations with IDNCINEMA Cognitive Actions

21 Apr 2025
Elevate Your Visual Creations with IDNCINEMA Cognitive Actions

In today's digital landscape, creating stunning visuals from textual descriptions has become an integral part of various applications, from gaming to marketing. The IDNCINEMA Cognitive Actions provide developers with the capability to generate detailed images using advanced models. By leveraging these pre-built actions, you can seamlessly integrate image generation into your applications, allowing for creative expressions and enhanced user experiences. In this article, we will explore one powerful action that lets you generate images with inpainting capabilities.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which will be used for authentication.
  • Basic knowledge of JSON and how to structure API requests.

To authenticate your requests, you will typically pass your API key in the request headers.

Cognitive Actions Overview

Generate Image with Inpainting and Prompt

The Generate Image with Inpainting and Prompt action allows you to create detailed images from prompts and input images. You can utilize either the 'dev' or 'schnell' models, which offer different levels of inference steps. This action also supports optional inpainting and speed-optimized modes, making it versatile for various use cases.

Input: This action requires a set of parameters to generate images. The following are the key fields in the input schema:

  • prompt (required): The text prompt to guide the image generation.
  • image (optional): URI of an input image for inpainting mode.
  • mask (optional): URI of an image mask used in image inpainting mode.
  • width (optional): Width of the generated image (only for custom aspect ratios).
  • height (optional): Height of the generated image (only for custom aspect ratios).
  • goFast (optional): Enables faster image generation using a speed-optimized model.
  • aspectRatio (optional): Determines the aspect ratio of the generated image.
  • Additional fields like seed, numOutputs, outputFormat, and others to fine-tune the generation process.

Example Input:

{
  "goFast": false,
  "prompt": "IDNCINEMA An Indonesian man meeting John Wick in a bustling Jakarta street at night. The scene features cinematic lighting, enhancing the high detail of both characters. The Jakarta street is alive with neon lights and urban elements, creating a vibrant and dramatic atmosphere.",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "aspectRatio": "21:9",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "megapixelCount": "1",
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Output: Upon successful execution, the action returns a URL link to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/f0f32098-6e30-4f83-bc43-272c4263cfca/d2a76d78-4e9a-4b7d-ad7c-6c9bc3a51556.webp"
]

Conceptual Usage Example (Python): Below is a Python code snippet illustrating how to call the Generate Image with Inpainting and Prompt 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 = "89215296-2846-4832-beba-24fe0c82fec5"  # Action ID for Generate Image with Inpainting and Prompt

# Construct the input payload based on the action's requirements
payload = {
    "goFast": false,
    "prompt": "IDNCINEMA An Indonesian man meeting John Wick in a bustling Jakarta street at night. The scene features cinematic lighting, enhancing the high detail of both characters. The Jakarta street is alive with neon lights and urban elements, creating a vibrant and dramatic atmosphere.",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "aspectRatio": "21:9",
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "megapixelCount": "1",
    "promptStrength": 0.8,
    "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 the placeholder for the Cognitive Actions API key and endpoint with your actual values. The payload structure aligns with the input requirements of the action, ensuring accurate execution.

Conclusion

The IDNCINEMA Cognitive Actions provide a powerful toolset for developers looking to enrich their applications with advanced image generation capabilities. By leveraging the Generate Image with Inpainting and Prompt action, you can create visually stunning images based on text descriptions and input images, enhancing your project's creative potential. As you explore these possibilities, consider experimenting with different parameter settings to achieve unique and captivating results. Happy coding!