Enhance Your Images Effortlessly with Safari Hat Cognitive Actions

22 Apr 2025
Enhance Your Images Effortlessly with Safari Hat Cognitive Actions

In the realm of image generation, the Safari Hat Cognitive Actions offer developers a powerful toolset to create stunning images with customizable options. By leveraging these pre-built actions, you can enhance images to meet specific requirements such as size, quality, and style, without needing extensive background knowledge in image processing. This article will delve into the capabilities of the Generate Enhanced Images action, guiding you through its features, input structure, and practical usage.

Prerequisites

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

  1. API Key: You’ll need an API key to access the Cognitive Actions platform. This key is typically passed in the headers of your requests for authentication.
  2. Environment Setup: Make sure you have a development environment set up for making HTTP requests, such as Python with the requests library.

Cognitive Actions Overview

Generate Enhanced Images

The Generate Enhanced Images action allows you to produce improved images based on a textual prompt. It provides various customization options, including image size, quality, and aspect ratio. You can choose between two inference models—dev for detailed results and schnell for quicker outputs—while additional features like LoRA weights enhance the final image quality.

Input

The input for this action follows a specific schema, which includes several required and optional parameters.

  • Required Fields:
    • prompt: A string describing the image you want to generate.
  • Optional Fields:
    • mask: URI of an image mask for inpainting.
    • seed: An integer for reproducible results.
    • image: URI of an input image for transformation.
    • width and height: Dimensions of the generated image (requires custom aspect ratio).
    • fastMode: Boolean to enable faster predictions.
    • imageFormat: Output format (e.g., webp, jpg, png).
    • imageQuality: Quality of the output image (0-100).
    • Additional parameters for refining the output, including mainLoraScale, inferenceModel, and more.

Example Input:

{
  "prompt": "a handsome man on safari wearing a SFRIHAT hat",
  "fastMode": false,
  "imageFormat": "webp",
  "imageQuality": 80,
  "mainLoraScale": 1,
  "inferenceModel": "dev",
  "imageResolution": "1",
  "numberOfOutputs": 1,
  "promptInfluence": 0.8,
  "imageAspectRatio": "1:1",
  "additionalLoraScale": 1,
  "diffusionGuidanceScale": 3,
  "numberOfInferenceSteps": 28
}

Output

The output of this action is typically a URI pointing to the generated image.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/b6e08022-c5c4-484a-a98e-e309397c0e3e/0fe3a2b3-2b4b-4f75-9128-82f8011f782f.webp"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet demonstrating how to invoke the Generate Enhanced Images 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 = "137dad53-2839-4360-b840-3adc48eee8f4" # Action ID for Generate Enhanced Images

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "a handsome man on safari wearing a SFRIHAT hat",
    "fastMode": False,
    "imageFormat": "webp",
    "imageQuality": 80,
    "mainLoraScale": 1,
    "inferenceModel": "dev",
    "imageResolution": "1",
    "numberOfOutputs": 1,
    "promptInfluence": 0.8,
    "imageAspectRatio": "1:1",
    "additionalLoraScale": 1,
    "diffusionGuidanceScale": 3,
    "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 code snippet, replace the API key and endpoint with your own. The action_id corresponds to the Generate Enhanced Images action, and the payload is structured according to the action's input schema.

Conclusion

The Safari Hat Cognitive Actions provide a robust solution for developers looking to enhance images with ease. By utilizing the Generate Enhanced Images action, you can create customized outputs that meet your specific needs, whether it's for artistic expression or practical applications. As you explore these capabilities, consider experimenting with different prompts and parameters to discover the full potential of image generation in your applications.