Generate Stunning Images with the petraccount/petrnewmod Cognitive Actions

24 Apr 2025
Generate Stunning Images with the petraccount/petrnewmod Cognitive Actions

In the world of AI and machine learning, generating customized images has become a reality thanks to advanced Cognitive Actions. The petraccount/petrnewmod API enables developers to create visually appealing images through image inpainting and image-to-image transformations. This article will guide you through the key capabilities of the Generate Customized Image action, showcasing how to integrate it into your applications with ease.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Familiarity with sending HTTP requests and handling JSON data.
  • Basic knowledge of Python (or your preferred programming language) for making API calls.

Authentication typically involves passing your API key in the request headers to access the Cognitive Actions services.

Cognitive Actions Overview

Generate Customized Image

Description:
The Generate Customized Image action allows users to create customized images by specifying various parameters such as prompt, aspect ratio, and quality settings. It supports two inference models: the 'schnell' model for faster predictions and the 'dev' model for high-quality image generation.

  • Category: Image Generation

Input

The input schema for this action requires a JSON object with the following properties. The only required field is prompt.

PropertyTypeRequiredDescription
promptstringYesA text prompt guiding the image generation.
maskstringNoURI for the image mask used in image inpainting mode.
seedintegerNoRandom seed value for generating consistent outputs.
imagestringNoURI for the input image for conversion or inpainting.
widthintegerNoSpecifies the width of the generated image (must be a multiple of 16).
heightintegerNoSpecifies the height of the generated image (must be a multiple of 16).
goFastbooleanNoEnables a speed-optimized model prediction.
numOutputsintegerNoNumber of output images to generate (1 to 4).
outputQualityintegerNoOutput image quality, ranging from 0 to 100.
guidanceScalenumberNoScale influencing the diffusion process.
inferenceModelstringNoChoose between 'dev' for quality or 'schnell' for speed.
............ (additional parameters available)

Example Input:

{
  "goFast": false,
  "prompt": "exterior of the japanese bar building, one floor, traditional 19th century japanese architecture, there is a sign on the building with word \"IKI\" on it, lots of snow on the ground, night time, with soft lights, snow falling, anime style",
  "loraScale": 1,
  "numOutputs": 1,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "9:16",
  "imageOutputFormat": "jpg",
  "numInferenceSteps": 28
}

Output

The action typically returns a JSON array containing the URLs of the generated images.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/910e57d0-d032-4fc6-bae8-46f39194fb5f/bf1be170-9512-4dea-ba2e-dc9f34ae7970.jpg"
]

Conceptual Usage Example (Python)

Here's a conceptual Python code snippet illustrating how to call the Generate Customized Image 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 = "4ad747d9-89a2-4085-99fe-a096ef704e92"  # Action ID for Generate Customized Image

# Construct the input payload based on the action's requirements
payload = {
    "goFast": False,
    "prompt": "exterior of the japanese bar building, one floor, traditional 19th century japanese architecture, there is a sign on the building with word \"IKI\" on it, lots of snow on the ground, night time, with soft lights, snow falling, anime style",
    "loraScale": 1,
    "numOutputs": 1,
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "imageMegapixels": "1",
    "imageAspectRatio": "9:16",
    "imageOutputFormat": "jpg",
    "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, replace the API key and endpoint with your actual credentials. The payload is structured according to the input schema, and the action ID corresponds to the Generate Customized Image action.

Conclusion

The petraccount/petrnewmod Cognitive Actions allow developers to unleash their creativity by generating customized images tailored to specific requirements. By utilizing the Generate Customized Image action, you can enhance your applications with unique visuals, making them more engaging and visually appealing.

Explore the customizable parameters to fine-tune your image generation process and consider experimenting with different prompts to see the variety of outputs you can achieve! Happy coding!