Create Stunning Images with the gunipersonal/punya Cognitive Actions

24 Apr 2025
Create Stunning Images with the gunipersonal/punya Cognitive Actions

In today's digital landscape, the ability to generate images programmatically opens up exciting opportunities for developers. The gunipersonal/punya API offers a powerful Cognitive Action designed for image generation through inpainting and image-to-image techniques. With an array of customizable options, developers can create unique visuals tailored to their applications seamlessly.

In this article, we will explore the Generate Image with Inpainting action, detailing its capabilities, input requirements, output structure, and how to implement it in your projects.

Prerequisites

Before getting started with the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • A basic understanding of making HTTP requests and handling JSON data.

Authentication typically involves passing the API key in the request headers, ensuring secure access to the service.

Cognitive Actions Overview

Generate Image with Inpainting

The Generate Image with Inpainting action allows developers to create images using custom prompts, with options for image quality, aspect ratio, and more. It supports optimized models for quick inference and enhanced image detail.

Category: Image Generation

Input

To invoke this action, you will need to construct a JSON payload with the following fields:

  • prompt (required): A description to guide the image generation.
  • mask (optional): URI of an image mask for inpainting.
  • image (optional): URI of an input image for processing.
  • model (optional): Choose between "dev" and "schnell" models.
  • width (optional): Specify image width (only for custom aspect ratios).
  • height (optional): Specify image height (only for custom aspect ratios).
  • goFast (optional): Enable fast predictions.
  • numOutputs (optional): The number of images to generate (1-4).
  • aspectRatio (optional): Set the aspect ratio for the image.
  • imageFormat (optional): Specify the output format (e.g., png, jpg).
  • guidanceScale (optional): Adjust the guidance scale for the diffusion process.

Here’s an example input payload:

{
  "mask": "https://replicate.delivery/pbxt/MFgCtFQU5162mVzkkN6f09BAZIlKyPznoYb6xKTkuEYDXCPV/Chapter%206-1%20masked.png",
  "image": "https://replicate.delivery/pbxt/MFgCsppJmaNu1YT3AQkMi3AK8foR19zlrLQqlImeW2G6W10J/Chapter%206-1.tiff",
  "model": "dev",
  "goFast": false,
  "prompt": "PUNYA_ laughing with sarcasm and listening to the man\nCARTOON IMAGE",
  "loraScale": 1,
  "numOutputs": 4,
  "aspectRatio": "1:1",
  "imageFormat": "png",
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "numInferenceSteps": 28,
  "approximateMegapixels": "1"
}

Output

The action returns a list of URLs pointing to the generated images. Here is an example of what you can expect as output:

[
  "https://assets.cognitiveactions.com/invocations/0751313c-1142-4180-a647-0a4fe1ee8a64/855b5c9e-7351-47cd-85d4-f53191588c59.png",
  "https://assets.cognitiveactions.com/invocations/0751313c-1142-4180-a647-0a4fe1ee8a64/719a083a-b0ba-49e0-b630-f32e6b11632b.png",
  "https://assets.cognitiveactions.com/invocations/0751313c-1142-4180-a647-0a4fe1ee8a64/f5a79445-9148-4051-b857-1eefd70e4c33.png",
  "https://assets.cognitiveactions.com/invocations/0751313c-1142-4180-a647-0a4fe1ee8a64/ab1e8fe9-dae7-48c1-b529-139967aab111.png"
]

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to call the Generate Image with Inpainting action. Note that the endpoint URL and request structure are illustrative.

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 = "7b1ceb7e-b73f-4023-8d8a-8dcdeb256235" # Action ID for Generate Image with Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "mask": "https://replicate.delivery/pbxt/MFgCtFQU5162mVzkkN6f09BAZIlKyPznoYb6xKTkuEYDXCPV/Chapter%206-1%20masked.png",
    "image": "https://replicate.delivery/pbxt/MFgCsppJmaNu1YT3AQkMi3AK8foR19zlrLQqlImeW2G6W10J/Chapter%206-1.tiff",
    "model": "dev",
    "goFast": False,
    "prompt": "PUNYA_ laughing with sarcasm and listening to the man\nCARTOON IMAGE",
    "loraScale": 1,
    "numOutputs": 4,
    "aspectRatio": "1:1",
    "imageFormat": "png",
    "guidanceScale": 3,
    "outputQuality": 80,
    "extraLoraScale": 1,
    "promptStrength": 0.8,
    "numInferenceSteps": 28,
    "approximateMegapixels": "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 snippet:

  • The action ID for Generate Image with Inpainting is specified.
  • The input payload is constructed based on the required fields.
  • The API key is included in the request headers, and the response is processed accordingly.

Conclusion

The gunipersonal/punya Cognitive Actions, specifically the Generate Image with Inpainting, provide developers with a versatile tool for creating unique images. By leveraging customizable inputs, you can produce tailored visuals that enhance your applications.

Explore these capabilities in your projects, and consider experimenting with different prompts and configurations to achieve stunning results!