Unleashing Creativity: Generate Stunning Images with the luis-mdc/pilsn Cognitive Actions

21 Apr 2025
Unleashing Creativity: Generate Stunning Images with the luis-mdc/pilsn Cognitive Actions

The luis-mdc/pilsn Cognitive Actions provide developers with powerful capabilities for generating high-quality images through innovative inpainting techniques. These actions are designed to streamline the image creation process, allowing you to create visually appealing content based on user-defined prompts. Whether you're developing an application for marketing, e-commerce, or creative storytelling, these pre-built actions can simplify your workflow and enhance your application's functionality.

Prerequisites

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

  • An API key from the Cognitive Actions platform, which is required for authentication.
  • Basic familiarity with making API requests, particularly using JSON format.

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

Cognitive Actions Overview

Generate Image with Inpainting Mode

The Generate Image with Inpainting Mode action utilizes advanced image inpainting techniques to create stunning images based on a specified prompt. This action supports various models, allowing you to adjust factors such as prompt intensity, image size, and aspect ratio, while also optimizing for faster predictions when needed.

Input

The input schema for this action requires the following fields:

  • prompt (required): A detailed description of the image you want to generate.
  • loraScale (optional): Controls the influence of the main LoRA (Low-Rank Adaptation).
  • aspectRatio (optional): Specifies the aspect ratio for the generated image.
  • outputCount (optional): The number of output images to generate.
  • outputFormat (optional): The format for the output images (e.g., webp, jpg, png).
  • guidanceScale (optional): Adjusts the diffusion process' guidance.
  • outputQuality (optional): Determines the quality of the output images.
  • inferenceModel (optional): Selects the model for inference (e.g., dev, schnell).
  • promptStrength (optional): Sets the strength of the prompt when using image-to-image techniques.
  • inferenceStepsCount (optional): Specifies the number of denoising steps.

Here's an example input JSON structure:

{
  "prompt": "Create a high-quality product advertisement featuring a sleek glass PILSEN beer bottle with the brand name “Pilsener” prominently displayed. The bottle should be standing upright in the center of the image, dripping with cold condensation to emphasize its refreshing quality. Surround the bottle with elements inspired by the beauty of Ecuador.",
  "loraScale": 1,
  "aspectRatio": "1:1",
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "inferenceStepsCount": 28,
  "extraLoraWeightScale": 1
}

Output

The action typically returns an array of URLs pointing to the generated images. Here’s an example of the output you might receive:

[
  "https://assets.cognitiveactions.com/invocations/967dea39-6df6-4805-a4a6-4182a958a8b2/1facb001-b1b8-41e5-a448-e218ad74984d.webp"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to invoke the Generate Image with Inpainting Mode 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 = "4ab379fd-301f-4f38-ac55-66644c60c3c0"  # Action ID for Generate Image with Inpainting Mode

# Construct the input payload based on the action's requirements
payload = {
    "prompt": "Create a high-quality product advertisement featuring a sleek glass PILSEN beer bottle with the brand name “Pilsener” prominently displayed. The bottle should be standing upright in the center of the image, dripping with cold condensation to emphasize its refreshing quality. Surround the bottle with elements inspired by the beauty of Ecuador.",
    "loraScale": 1,
    "aspectRatio": "1:1",
    "outputCount": 1,
    "outputFormat": "webp",
    "guidanceScale": 3.5,
    "outputQuality": 90,
    "inferenceModel": "dev",
    "promptStrength": 0.8,
    "inferenceStepsCount": 28,
    "extraLoraWeightScale": 1
}

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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable contains the structured input JSON based on the action's requirements. The endpoint URL and request structure are illustrative and may vary in your implementation.

Conclusion

The Generate Image with Inpainting Mode action from the luis-mdc/pilsn Cognitive Actions offers a robust solution for developers looking to enhance their applications with stunning image generation capabilities. By leveraging the power of this action, you can create visually appealing content that resonates with users. Consider exploring various prompts and configurations to fully utilize the potential of this action in your projects. Happy coding!