Create Stunning Images with the Pokmok Cognitive Actions

22 Apr 2025
Create Stunning Images with the Pokmok Cognitive Actions

In today's digital landscape, creating high-quality images tailored to specific needs can enhance user engagement and experience. The Pokmok Cognitive Actions provide a powerful way to generate images using advanced techniques like image inpainting. By leveraging these pre-built actions, developers can integrate customized image generation capabilities into their applications with ease.

Prerequisites

Before diving into the integration of the Pokmok Cognitive Actions, you'll need:

  • An API key for accessing the Cognitive Actions platform.
  • Familiarity with making HTTP requests, particularly POST requests to execute actions.

To authenticate your requests, you'll typically include the API key in the request headers.

Cognitive Actions Overview

Generate Image Using Pokmok

Description: This action generates images with advanced image inpainting capabilities based on specific prompts. Users can customize various parameters such as seed values, image size, and format, enabling the production of high-quality images tailored to their specifications.

Category: Image Generation

Input

The following fields are required and optional for this action:

  • Required:
    • prompt (string): A text prompt guiding the image generation process.
  • Optional:
    • mask (string): URI of the image mask for inpainting mode.
    • seed (integer): Initializes the random seed for reproducibility.
    • image (string): URI of the input image for image-to-image or inpainting.
    • model (string): Choose between "dev" (default) and "schnell".
    • width (integer): Sets the width of the generated image (valid only with custom aspect ratio).
    • height (integer): Sets the height of the generated image (valid only with custom aspect ratio).
    • megapixels (string): Approximate megapixel count (options: "1", "0.25").
    • aspectRatio (string): Defines the aspect ratio (e.g., "1:1", "16:9").
    • loraStrength, additionalLoraScale (number): Adjusts the intensity of LoRA applications.
    • outputFormat (string): File format for the output image (e.g., "webp", "jpg").
    • guidanceScale, outputQuality, promptStrength, inferenceSteps (number/integer): Various controls over image generation specifics.
    • numberOfOutputs (integer): How many outputs to generate (maximum of 4).
    • enableFastMode (boolean): Activates faster predictions.
    • disableSafetyChecker (boolean): Option to deactivate safety checks.

Example Input:

{
  "model": "dev",
  "prompt": "A high-quality photo of a person POKMOK performing a solo skydive, captured mid-air in a freefall pose with their face clearly visible, expressing focus and exhilaration. The individual is wearing a professional skydiving suit and helmet, with a visible parachute rig on their back. The background features a vast open sky with scattered fluffy clouds and breathtaking scenery below, such as rolling hills, a river, or a coastline. The photo conveys the sense of freedom and adrenaline of a solo jump, with the airplane visible far in the distance, emphasizing the solo nature of the skydive.",
  "megapixels": "1",
  "aspectRatio": "1:1",
  "loraStrength": 1,
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "enableFastMode": false,
  "inferenceSteps": 28,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "additionalLoraScale": 1
}

Output

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

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/8b83c53f-dcfd-47b8-8268-d9473825c6ce/81230c97-78d4-4e05-9c93-f27f369ef002.webp"
]

Conceptual Usage Example (Python)

Here’s how you might structure a request to execute the image generation action using Python:

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 = "9a39f7c4-32e6-4399-a346-8cb94a72a1c5"  # Action ID for Generate Image Using Pokmok

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "prompt": "A high-quality photo of a person POKMOK performing a solo skydive...",
    "megapixels": "1",
    "aspectRatio": "1:1",
    "loraStrength": 1,
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "enableFastMode": False,
    "inferenceSteps": 28,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "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 example, replace the Cognitive Actions API key and endpoint with your actual credentials. The action_id corresponds to the action for generating images, and the payload contains the necessary parameters for the request.

Conclusion

The Pokmok Cognitive Actions provide a flexible and powerful way to generate stunning images with a high degree of customization. By utilizing these actions, developers can seamlessly integrate image generation capabilities into their applications, enhancing creativity and user engagement. Whether you're looking to create visuals for marketing, social media, or artistic projects, these cognitive actions can significantly streamline the process.

Explore the possibilities and start generating your unique images today!