Enhance Your App with Image Generation Using Hadasadler Rotemai Cognitive Actions

22 Apr 2025
Enhance Your App with Image Generation Using Hadasadler Rotemai Cognitive Actions

In the evolving landscape of AI and machine learning, the Hadasadler Rotemai API offers a robust set of Cognitive Actions designed for image generation through advanced inpainting techniques. These pre-built actions enable developers to easily integrate powerful image creation capabilities into their applications, allowing for customizable outputs tailored to specific needs. Whether you're building a creative app, enhancing user-generated content, or exploring artistic possibilities, these actions streamline the process of generating images while providing flexibility in parameters.

Prerequisites

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

  • API Key: You will need an API key to authenticate your requests to the Cognitive Actions platform.
  • Endpoint Configuration: Familiarize yourself with the endpoint structure to execute the actions.

Authentication is typically handled by passing your API key in the request headers. This is crucial for ensuring secure access to the services.

Cognitive Actions Overview

Generate Image with Inpainting

This action allows you to create images using a combination of image-to-image and inpainting modes. By specifying various settings such as aspect ratios and output quality, you can generate images tailored to your needs. The action supports both fast and high-quality image generation using 'dev' and 'schnell' models, with enhanced results through LoRA weights.

Input

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

  • prompt (required): Text prompt to generate images.
  • model (optional): Selects the model for inference (dev or schnell).
  • outputQuality (optional): Defines the output image quality (0 to 100).
  • enableFastMode (optional): Activates fast prediction mode.
  • imageResolution (optional): Specifies the approximate megapixel count.
  • numberOfOutputs (optional): Number of outputs to generate.
  • imageAspectRatio (optional): Aspect ratio of the generated image.
  • imageOutputFormat (optional): File format for output images (e.g., webp, jpg, png).
  • Additional parameters for advanced configurations like prompt strength, LoRA application scale, and denoising steps.

Example Input:

{
  "model": "dev",
  "prompt": "rotemai  A woman looking at the camera, holding a microphone in her hand.",
  "outputQuality": 80,
  "enableFastMode": false,
  "imageResolution": "1",
  "numberOfOutputs": 1,
  "imageAspectRatio": "16:9",
  "imageOutputFormat": "webp",
  "additionalLoraScale": 1,
  "denoisingStepsCount": 28,
  "imagePromptStrength": 0.8,
  "loraApplicationScale": 1,
  "diffusionGuidanceScale": 3
}

Output

The output of this action will typically return a URL to the generated image. Here’s an example of what you might expect:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/d5fa60ae-d205-4d56-90ba-4b43203fe93f/4d1e4b09-58ba-40c8-829d-f3938d7cbf6d.webp"
]

Conceptual Usage Example (Python)

Here is a conceptual Python code snippet demonstrating how to call this action using a generic Cognitive Actions endpoint:

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 = "7a4cc6fc-0856-4f51-b49e-265a84e07bff" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "rotemai  A woman looking at the camera, holding a microphone in her hand.",
    "outputQuality": 80,
    "enableFastMode": False,
    "imageResolution": "1",
    "numberOfOutputs": 1,
    "imageAspectRatio": "16:9",
    "imageOutputFormat": "webp",
    "additionalLoraScale": 1,
    "denoisingStepsCount": 28,
    "imagePromptStrength": 0.8,
    "loraApplicationScale": 1,
    "diffusionGuidanceScale": 3
}

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 the placeholder for the API key and adjust the endpoint as needed. The action ID and input payload structure are crucial for ensuring that the request is processed correctly.

Conclusion

The Hadasadler Rotemai Cognitive Actions offer a powerful way to enhance your applications with sophisticated image generation capabilities. By leveraging the Generate Image with Inpainting action, developers can produce tailored images that meet specific requirements and artistic visions. Consider exploring additional use cases, such as integrating user-generated prompts or utilizing advanced image settings to fully capitalize on the potential of these Cognitive Actions. Happy coding!