Transform Your Applications with Image Generation Using the Nigerian Cognitive Actions

22 Apr 2025
Transform Your Applications with Image Generation Using the Nigerian Cognitive Actions

In the realm of artificial intelligence, image generation has gained immense popularity, offering developers the ability to create unique visuals from textual descriptions. The Nigerian Cognitive Actions provide a powerful API for developers to generate images based on custom parameters, enabling various applications such as content creation, marketing, and gaming. In this article, we will explore how to utilize the "Generate Image with Custom Parameters" action effectively, detailing its capabilities, input requirements, output results, and how to implement it in your applications.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which you'll use to authenticate your requests.
  • Basic familiarity with making HTTP requests and handling JSON data.
  • A development environment set up to run Python scripts, with the requests library installed.

To authenticate, you will typically pass your API key in the request headers, allowing you to access the Cognitive Actions service securely.

Cognitive Actions Overview

Generate Image with Custom Parameters

The Generate Image with Custom Parameters action allows developers to create images based on a provided text prompt. This action supports various configurations, including custom image dimensions, aspect ratios, and styles, using LoRA weights. It also provides options for image inpainting and image-to-image generation, as well as two model choices: 'dev' for detailed inference and 'schnell' for faster generation.

  • Category: image-generation

Input

The input schema for this action requires the following fields and supports numerous optional parameters:

  • prompt (required): A string that describes the image you want to generate.
  • seed (optional): An integer to initialize the random number generator.
  • image (optional): URI of an input image for inpainting or image-to-image generation.
  • width and height (optional): Dimensions for custom aspect ratios.
  • aspectRatio (optional): Select from predefined options or set a custom ratio.
  • numOutputs (optional): Number of images to generate (up to 4).
  • outputFormat (optional): Format of the output image (webp, jpg, png).
  • guidanceScale (optional): Controls the influence of the prompt during generation.
  • inferenceModel (optional): Choose between 'dev' and 'schnell' for processing.

Here’s an example input JSON payload:

{
  "seed": 34872,
  "prompt": "An amateur photo of APST holding a bible and smiling. APST is 5'8 tall and has a normal typical man body mass. APST IS wearing a black 3-piece suit",
  "loraScale": 1,
  "numOutputs": 3,
  "aspectRatio": "1:1",
  "outputFormat": "png",
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

Output

Upon successful execution, the action returns an array of image URLs, which point to the generated images. Here’s an example of the expected output:

[
  "https://assets.cognitiveactions.com/invocations/b0eea723-e602-48f8-9be5-9d6d185d2d04/15e4cf0c-a817-4855-b291-d73ba6f60ef1.png",
  "https://assets.cognitiveactions.com/invocations/b0eea723-e602-48f8-9be5-9d6d185d2d04/2d76bdf1-c3fb-4318-8f9b-9b8f0f2fd770.png",
  "https://assets.cognitiveactions.com/invocations/b0eea723-e602-48f8-9be5-9d6d185d2d04/29808ad7-857d-42b3-a999-a01570cf87ff.png"
]

Conceptual Usage Example (Python)

Here's how you can implement the Generate Image with Custom Parameters action in 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 = "7c2b5150-209d-4378-b0d3-216c33a622ae" # Action ID for Generate Image with Custom Parameters

# Construct the input payload based on the action's requirements
payload = {
    "seed": 34872,
    "prompt": "An amateur photo of APST holding a bible and smiling. APST is 5'8 tall and has a normal typical man body mass. APST IS wearing a black 3-piece suit",
    "loraScale": 1,
    "numOutputs": 3,
    "aspectRatio": "1:1",
    "outputFormat": "png",
    "guidanceScale": 3.5,
    "outputQuality": 100,
    "extraLoraScale": 1,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "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 Python code snippet:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action_id is set to the ID of the Generate Image with Custom Parameters action.
  • The payload is constructed using the required fields and example input.
  • The request is sent to the hypothetical endpoint, and the response is handled accordingly.

Conclusion

The Nigerian Cognitive Actions open up a world of possibilities for developers looking to integrate advanced image generation capabilities into their applications. By leveraging the Generate Image with Custom Parameters action, you can create unique visuals tailored to your specific needs.

Explore further by experimenting with different prompts, aspect ratios, and output formats to maximize the potential of your applications. Happy coding!