Generate Stunning Portraits with the snapbar-operations/demo-man Cognitive Actions

24 Apr 2025
Generate Stunning Portraits with the snapbar-operations/demo-man Cognitive Actions

In the realm of digital content creation, the ability to generate high-quality images is paramount. The snapbar-operations/demo-man API provides a powerful Cognitive Action known as Generate Portrait Images. This action allows developers to create stunning portrait images using input images or inpainting techniques while offering extensive customization options. By leveraging this API, developers can automate the image generation process, thus enhancing user experiences in applications such as social media filters, personalized avatars, or character design tools.

Prerequisites

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

  • An API key for the Cognitive Actions platform.
  • Basic understanding of JSON for constructing requests.
  • Familiarity with making HTTP requests, particularly in Python.

Authentication generally involves passing your API key in the headers of your requests, which grants access to the Cognitive Actions services.

Cognitive Actions Overview

Generate Portrait Images

Description:
This action generates high-quality portrait images based on a text prompt or provides inpainting capabilities. It allows for adjustments in dimensions, aspect ratios, and image quality, utilizing flexible inference models tailored for speed or high quality. Furthermore, it supports advanced customization through LoRA weight manipulation and guidance settings.

Category: Image Generation

Input

The required input schema for this action is as follows:

  • prompt (string, required): Text prompt for generating the image, e.g., "OHWX man portrait."
  • goFast (boolean, optional): Enable faster predictions using a speed-optimized model (default: false).
  • loraScale (number, optional): Determines the strength of the main LoRA application (default: 1).
  • modelType (string, optional): The model to run inference with (default: "dev").
  • numOutputs (integer, optional): Number of outputs to generate (default: 1).
  • outputFormat (string, optional): Format of the output images (default: "webp").
  • guidanceScale (number, optional): Guidance scale for the diffusion process (default: 3).
  • outputQuality (integer, optional): Quality when saving the output images (default: 80).
  • extraLoraScale (number, optional): Determines the strength of any extra LoRA application (default: 1).
  • megapixelCount (string, optional): Approximate number of megapixels for the generated image (default: "1").
  • promptStrength (number, optional): Strength of the prompt in image-to-image transformations (default: 0.8).
  • aspectRatioType (string, optional): Aspect ratio for the generated image (default: "1:1").
  • numInferenceSteps (integer, optional): Number of denoising steps for image generation (default: 28).

Example Input:

{
  "goFast": false,
  "prompt": "OHWX man portrait",
  "loraScale": 1,
  "modelType": "dev",
  "numOutputs": 1,
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "megapixelCount": "1",
  "promptStrength": 0.8,
  "aspectRatioType": "1:1",
  "numInferenceSteps": 28
}

Output

The action typically returns a URL to the generated image in the specified format.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/3ae613e0-5702-4139-ba80-5ea9350507dc/351e7bc4-02b3-46ff-98b3-4763ebe1ced1.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how a developer might call the Generate Portrait Images 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 = "64c404f0-dcb0-4a9a-b58a-78e922c0c4ad"  # Action ID for Generate Portrait Images

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "OHWX man portrait",
    "loraScale": 1,
    "modelType": "dev",
    "numOutputs": 1,
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "megapixelCount": "1",
    "promptStrength": 0.8,
    "aspectRatioType": "1:1",
    "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, the developer replaces the API key and specifies the action ID for generating portrait images. The input payload is structured according to the requirements, and the request is sent to the Cognitive Actions endpoint. The response is then printed, showing either the generated image URL or any error messages.

Conclusion

The Generate Portrait Images action from the snapbar-operations/demo-man API opens up a world of possibilities for developers looking to enhance their applications with high-quality image generation capabilities. With extensive options for customization, this action can be tailored to suit various use cases, from social media applications to creative design tools. Start integrating this action today to elevate your projects with stunning AI-generated images!