Enhance Your Applications with Image Generation: Using juuanngonzalez/juango Cognitive Actions

23 Apr 2025
Enhance Your Applications with Image Generation: Using juuanngonzalez/juango Cognitive Actions

In the rapidly evolving landscape of AI-driven applications, integrating image generation capabilities can significantly enhance user experience. The juuanngonzalez/juango Cognitive Actions offer a powerful way to generate inpainted and enhanced images using sophisticated models. With the ability to customize dimensions, adjust guidance scales, and choose between different models (dev or schnell), these actions allow developers to create visually appealing content that meets specific needs.

Prerequisites

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

  • API Key: You will need an API key from the Cognitive Actions platform to authenticate your requests.
  • Basic Understanding of JSON: The input and output payloads for the actions are structured in JSON, so familiarity with JSON format is beneficial.

To authenticate your requests, you will typically include your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Inpainted Images

The Generate Inpainted Images action allows you to create enhanced images by utilizing either the 'dev' model, optimized for quality, or the 'schnell' model, designed for speed. This functionality supports image-to-image transformations, enabling more personalized and realistic outputs.

Input

The input for this action requires a prompt and includes several optional parameters to customize the output.

{
  "model": "dev",
  "goFast": false,
  "prompt": "juango's realistic profile picture for Linkedin, where he has an elegant outfit and can be seen from the chest up, looking at the camera.\nLooking smart and friendly, as a start up founder.\nWith a smaller forehead",
  "loraScale": 1,
  "megapixels": "1",
  "numOutputs": 2,
  "aspectRatio": "1:1",
  "outputFormat": "webp",
  "guidanceScale": 3,
  "outputQuality": 100,
  "extraLoraScale": 1,
  "promptStrength": 0.35,
  "numInferenceSteps": 28
}
  • Required Fields:
    • prompt: Describes the desired image.
  • Optional Fields:
    • mask: Image mask for inpainting.
    • seed: Random seed for reproducibility.
    • image: Input image for transformations.
    • model: Choose between "dev" and "schnell".
    • width, height: Dimensions of the output image.
    • goFast: Optimize for speed (boolean).
    • numOutputs: Number of images to generate (1-4).
    • aspectRatio: Custom aspect ratios for the image.
    • outputFormat: Image format (webp, jpg, png).
    • guidanceScale: Adjust realism.
    • outputQuality: Quality setting for the output image.

Output

The output will return an array of URLs pointing to the generated images.

[
  "https://assets.cognitiveactions.com/invocations/8eb4ee2c-b6ba-4ad5-bf12-3273271fd367/c0f54d02-190d-47a5-91bb-22fdd3495a98.webp",
  "https://assets.cognitiveactions.com/invocations/8eb4ee2c-b6ba-4ad5-bf12-3273271fd367/245ebe1d-5b2a-4b67-9cd3-440fae841a07.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python snippet to demonstrate how to call the Generate Inpainted 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 = "fbc0b8d9-7737-478a-9ffc-4def92ecbaac"  # Action ID for Generate Inpainted Images

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "goFast": False,
    "prompt": "juango's realistic profile picture for Linkedin, where he has an elegant outfit and can be seen from the chest up, looking at the camera.\nLooking smart and friendly, as a start up founder.\nWith a smaller forehead",
    "loraScale": 1,
    "megapixels": "1",
    "numOutputs": 2,
    "aspectRatio": "1:1",
    "outputFormat": "webp",
    "guidanceScale": 3,
    "outputQuality": 100,
    "extraLoraScale": 1,
    "promptStrength": 0.35,
    "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}")

Explanation of the Code Snippet

In this snippet:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The payload dictionary is constructed according to the required and optional input fields for the action.
  • The HTTP request is made to the hypothetical Cognitive Actions execution endpoint, and the response is printed in a readable JSON format.

Conclusion

The juuanngonzalez/juango Cognitive Actions provide a versatile solution for developers looking to enhance their applications with advanced image generation capabilities. By leveraging these pre-built actions, you can create customized and visually appealing images tailored to your specific needs. Start integrating these actions today to elevate your application’s user engagement and create compelling visual content!