Transform Your Images: A Developer's Guide to the Gose Pub Cognitive Actions

23 Apr 2025
Transform Your Images: A Developer's Guide to the Gose Pub Cognitive Actions

In today's digital landscape, the ability to manipulate and generate images programmatically opens up a world of creative possibilities. The Gose Pub Cognitive Actions provide a powerful set of tools for developers to generate and refine images using advanced inpainting techniques. By integrating these pre-built actions into your applications, you can easily customize image generation processes to suit your specific needs.

Prerequisites

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

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Basic knowledge of JSON and Python to construct your input payload and call the API.

Typically, you will pass your API key in the headers of your requests to authenticate against the Cognitive Actions endpoint.

Cognitive Actions Overview

Generate Inpainted Image

The Generate Inpainted Image action allows you to create new images by applying inpainting techniques to a source image. This action enables you to manipulate various parameters, including image size, prompt strength, and guidance scale. You can specify features to add or remove through text prompts, apply refinements, and even manage safety checks.

Input

The input schema for this action requires a JSON object that can include the following fields:

  • mask (string): URI pointing to the input mask for inpainting (required).
  • seed (integer): Integer for random number initialization (optional).
  • image (string): URI pointing to the input image (required).
  • width (integer): Width in pixels of the output image (default: 1024).
  • height (integer): Height in pixels of the output image (default: 1024).
  • prompt (string): Text prompt guiding the image generation (default: "An astronaut riding a rainbow unicorn").
  • loraScale (number): Scale factor for the LoRA model (default: 0.6).
  • numOutputs (integer): Number of images to output (default: 1).
  • refineSteps (integer): Number of refinement steps (optional).
  • guidanceScale (number): Multiplier for classifier-free guidance (default: 7.5).
  • applyWatermark (boolean): Flag to apply a watermark (default: true).
  • negativePrompt (string): Prompt to guide image generation away from undesirable features (optional).
  • promptStrength (number): Influence of the prompt during inpainting (default: 0.8).
  • refinementStyle (string): Selection of the refinement method (default: "no_refiner").
  • alternateWeights (string): Specify LoRA weights (optional).
  • schedulingMethod (string): Algorithm used for image generation scheduling (default: "K_EULER").
  • highNoiseFraction (number): Fraction of noise applied (default: 0.8).
  • numInferenceSteps (integer): Total iterations of denoising applied (default: 50).
  • disableSafetyChecker (boolean): Allows the disabling of the safety checker (default: false).

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "front shot, portrait of TOK with long hair, natural skin, daylight, (cinematic, film grain:1.1)",
  "loraScale": 1,
  "numOutputs": 1,
  "guidanceScale": 7.5,
  "applyWatermark": false,
  "negativePrompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation, defromed EYES",
  "promptStrength": 1,
  "refinementStyle": "no_refiner",
  "schedulingMethod": "KarrasDPM",
  "highNoiseFraction": 0.95,
  "numInferenceSteps": 50
}

Output

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

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/cceeadac-c39b-41df-b39e-01acc7743305/c02a1b55-4448-4522-8d9c-91ab106ede80.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python snippet demonstrating how to call the Generate Inpainted 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 = "2807d2c1-790d-4aba-8174-874462ef6084"  # Action ID for Generate Inpainted Image

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "front shot, portrait of TOK with long hair, natural skin, daylight, (cinematic, film grain:1.1)",
    "loraScale": 1,
    "numOutputs": 1,
    "guidanceScale": 7.5,
    "applyWatermark": False,
    "negativePrompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation, defromed EYES",
    "promptStrength": 1,
    "refinementStyle": "no_refiner",
    "schedulingMethod": "KarrasDPM",
    "highNoiseFraction": 0.95,
    "numInferenceSteps": 50
}

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 COGNITIVE_ACTIONS_API_KEY and the endpoint URL with your actual API key and endpoint. The input payload is structured to meet the requirements of the Generate Inpainted Image action, and the code demonstrates how to handle the API response effectively.

Conclusion

The Gose Pub Cognitive Actions provide a robust framework for image generation and manipulation, empowering developers to create unique visual content with ease. By leveraging the capabilities of the Generate Inpainted Image action, you can enhance your applications with advanced image processing features. As a next step, consider experimenting with the various parameters to see how they affect the generated images and explore additional use cases for your projects. Happy coding!