Enhance Your Applications with Image Generation Using Klassenmedia's Henna Moosmed Cognitive Actions

23 Apr 2025
Enhance Your Applications with Image Generation Using Klassenmedia's Henna Moosmed Cognitive Actions

In the realm of AI-driven creativity, the klassenmedia/henna_moosmed Cognitive Actions provide developers with powerful tools for generating images. These pre-built actions leverage advanced inpainting techniques to create stunning visuals based on textual prompts. By integrating these actions into your applications, you can enhance user experience and open new avenues for creativity without the need for extensive machine learning expertise.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which you will use to authenticate your requests.
  • Basic knowledge of JSON and Python for constructing and sending HTTP requests.

To authenticate, you'll typically include the API key in the request headers, allowing you to securely access the Cognitive Actions functionalities.

Cognitive Actions Overview

Generate Image with Inpainting

Description: This action generates an image utilizing inpainting techniques, allowing for modifications in image properties such as aspect ratio, width, height, and output format. You can choose between two models: "dev" for detailed outputs and "schnell" for faster generation. It also provides features for adjusting prompt strength, using LoRA weights, and toggling safety checks.

Category: Image Generation

Input

The input schema for this action requires the following fields:

  • prompt (required): A text prompt guiding image generation. Example:
    "a handcrafted artisanal soap HENNA_MOOSMED standing in the sand in the desert..."

Other optional fields include:

  • mask: URI for the image mask.
  • seed: Integer for reproducibility.
  • image: URI for the input image.
  • model: Selects "dev" or "schnell".
  • width: Specify the width of the generated image.
  • height: Specify the height of the generated image.
  • megapixels: Choose between "0.25" or "1".
  • aspectRatio: Select from predefined ratios or custom.
  • outputFormat: Specify "webp", "jpg", or "png".
  • guidanceScale: Adjusts the guidance scale from 0 to 10.
  • loraIntensity: Control the intensity of LoRA application.
  • outputQuality: Defines image quality from 0 to 100.
  • enableFastMode: Toggle for fast predictions.
  • promptStrength: Set strength for the prompt.
  • numberOfOutputs: Specify how many images to generate.
  • additionalLoraScale: Adjust intensity for additional LoRA application.
  • additionalLoraWeights: Load additional weights from supported URLs.
  • numberOfInferenceSteps: Select the number of denoising steps.
  • isSafetyCheckerDisabled: Enable or disable the safety checker.

Example Input:

{
  "model": "dev",
  "prompt": "a handcrafted artisanal soap HENNA_MOOSMED standing in the sand...",
  "megapixels": "1",
  "aspectRatio": "4:5",
  "outputFormat": "jpg",
  "guidanceScale": 4.5,
  "loraIntensity": 1,
  "outputQuality": 100,
  "enableFastMode": false,
  "promptStrength": 0.89,
  "numberOfOutputs": 1,
  "additionalLoraScale": 1.07,
  "additionalLoraWeights": "https://huggingface.co/drface/JUGO",
  "numberOfInferenceSteps": 28
}

Output

The action typically returns a URL pointing to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/0f58458c-e225-4f40-a733-76bd8f259f42/2de7a19e-cd97-4a9e-9ad3-03d511e9e6f6.jpg"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how to call the Generate Image with Inpainting 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 = "6de2ba1d-b2f5-47ee-94b9-d3b6d5d57518" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "a handcrafted artisanal soap HENNA_MOOSMED standing in the sand...",
    "megapixels": "1",
    "aspectRatio": "4:5",
    "outputFormat": "jpg",
    "guidanceScale": 4.5,
    "loraIntensity": 1,
    "outputQuality": 100,
    "enableFastMode": false,
    "promptStrength": 0.89,
    "numberOfOutputs": 1,
    "additionalLoraScale": 1.07,
    "additionalLoraWeights": "https://huggingface.co/drface/JUGO",
    "numberOfInferenceSteps": 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 example, replace the placeholder API key and endpoint with your actual values. The action_id corresponds to the specific action being executed, and the payload is structured according to the required input schema.

Conclusion

The klassenmedia/henna_moosmed Cognitive Actions empower developers to create stunning images through simple API integration. By leveraging the capabilities of inpainting and customizable image properties, you can enrich your applications with visually engaging content. Explore these actions further and consider various use cases, such as creative design tools, social media applications, or marketing platforms. The possibilities are endless!