Enhance Image Generation with pagebrain/ghostmix-v2 Cognitive Actions

22 Apr 2025
Enhance Image Generation with pagebrain/ghostmix-v2 Cognitive Actions

In the realm of artificial intelligence, image generation has seen remarkable advancements, allowing developers to create stunning visuals with minimal effort. The pagebrain/ghostmix-v2 API offers powerful Cognitive Actions designed to simplify and enhance image synthesis. These pre-built actions harness the capabilities of sophisticated imaging models, enabling functionalities like img2img processing, inpainting, and more. By leveraging these actions, developers can efficiently generate high-quality images tailored to specific requirements.

Prerequisites

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

  • An API key for the Cognitive Actions platform, which will authenticate your requests.
  • Basic familiarity with making HTTP requests in your preferred programming language, particularly Python for the examples in this article.

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

Cognitive Actions Overview

Generate and Inpaint Image

The Generate and Inpaint Image action utilizes the advanced GhostMix imaging model, leveraging T4 GPUs for accelerated performance in generating images. This action allows for inpainting, where specific areas of an image can be modified while preserving the rest, along with the ability to guide image synthesis through prompts and negative embeddings.

Input

The input for this action requires a JSON object that includes several parameters. Below is an overview of these parameters along with an example input:

{
  "mask": "http://example.com/mask.png",
  "seed": 1015468391,
  "image": "http://example.com/input_image.png",
  "width": 512,
  "height": 512,
  "prompt": "(masterpiece, top quality, best quality, official art, beautiful and aesthetic:1.2), (1girl), extreme detailed,(fractal art:1.3),colorful,highest detailed\n",
  "scheduler": "KarrasDPM",
  "guidanceScale": 6,
  "safetyChecker": true,
  "negativePrompt": "(worst quality, low quality:2), monochrome, zombie,overexposure, watermark,text,bad anatomy,bad hand,extra hands,extra fingers,too many fingers,fused fingers,bad arm,distorted arm,extra arms,fused arms,extra legs,missing leg,disembodied leg,extra nipples, detached arm, liquid hand,inverted hand,disembodied limb, small breasts, loli, oversized head,extra body,completely nude, extra navel,easynegative,(hair between eyes),sketch, duplicate, ugly, huge eyes, text, logo, worst face, (bad and mutated hands:1.3), (blurry:2.0), horror, geometry, bad_prompt, (bad hands), (missing fingers), multiple limbs, bad anatomy, (interlocked fingers:1.2), Ugly Fingers, (extra digit and hands and fingers and legs and arms:1.4), ((2girl)), (deformed fingers:1.2), (long fingers:1.2),(bad-artist-anime), bad-artist, bad hand, extra legs ,(ng_deepnegative_v1_75t)",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 30
}

Output

The output from this action is a JSON array containing URLs of the generated images. Below is a sample output:

[
  "https://assets.cognitiveactions.com/invocations/f47812e1-6d13-4ac9-a488-77007ad611b0/a3d5977b-3b09-4ebe-8098-c6ade70a2c76.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Cognitive Actions execution endpoint to generate and inpaint an image:

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 = "1d369933-05a9-4a18-82ff-de66f7dec184" # Action ID for Generate and Inpaint Image

# Construct the input payload based on the action's requirements
payload = {
    "mask": "http://example.com/mask.png",
    "seed": 1015468391,
    "image": "http://example.com/input_image.png",
    "width": 512,
    "height": 512,
    "prompt": "(masterpiece, top quality, best quality, official art, beautiful and aesthetic:1.2), (1girl), extreme detailed,(fractal art:1.3),colorful,highest detailed\n",
    "scheduler": "KarrasDPM",
    "guidanceScale": 6,
    "safetyChecker": True,
    "negativePrompt": "(worst quality, low quality:2), monochrome, zombie,overexposure, watermark,text,bad anatomy,bad hand,extra hands,extra fingers,too many fingers,fused fingers,bad arm,distorted arm,extra arms,fused arms,extra legs,missing leg,disembodied leg,extra nipples, detached arm, liquid hand,inverted hand,disembodied limb, small breasts, loli, oversized head,extra body,completely nude, extra navel,easynegative,(hair between eyes),sketch, duplicate, ugly, huge eyes, text, logo, worst face, (bad and mutated hands:1.3), (blurry:2.0), horror, geometry, bad_prompt, (bad hands), (missing fingers), multiple limbs, bad anatomy, (interlocked fingers:1.2), Ugly Fingers, (extra digit and hands and fingers and legs and arms:1.4), ((2girl)), (deformed fingers:1.2), (long fingers:1.2),(bad-artist-anime), bad-artist, bad hand, extra legs ,(ng_deepnegative_v1_75t)",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 30
}

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:

  • You replace YOUR_COGNITIVE_ACTIONS_API_KEY and adjust the endpoint URL as needed.
  • The action ID and input payload are seamlessly integrated into the request structure.
  • The output will display the generated image URLs if the action executes successfully.

Conclusion

The pagebrain/ghostmix-v2 Cognitive Actions empower developers to effortlessly generate and manipulate images, offering extensive customization options through prompts and inpainting capabilities. By integrating these actions into your applications, you can unlock endless creative possibilities. Consider exploring various use cases, such as digital art creation, content generation, or enhancing visual media. Happy coding!