Create Stunning Images with Pacx's Inpainting Action

26 Apr 2025
Create Stunning Images with Pacx's Inpainting Action

In the realm of digital creativity, the ability to generate customized images can significantly enhance user engagement and storytelling. Pacx offers a powerful Cognitive Action called "Generate Image with Inpainting Mode," designed to allow developers to create unique images tailored to specific prompts and styles. This action not only supports traditional image generation but also provides advanced features like inpainting and image-to-image transformations, making it a versatile tool for artists, designers, and developers alike.

With Pacx, you can quickly generate images in various formats and qualities, optimizing for speed or detail based on your needs. Whether you're looking to create promotional graphics, enhance visual content for social media, or develop interactive applications, this action simplifies the image creation process, allowing for rapid prototyping and iteration.

Prerequisites

To get started with Pacx, you'll need a Cognitive Actions API key and a basic understanding of API calls to integrate this powerful image generation capability into your projects.

Generate Image with Inpainting Mode

The "Generate Image with Inpainting Mode" action is designed to create images based on detailed prompts, utilizing various customization options to meet your artistic vision.

Purpose

This action generates images while allowing for detailed customization, including inpainting, which lets you modify specific parts of an image. It solves the problem of needing unique visuals that align closely with your creative intent, providing flexibility in output formats and qualities.

Input Requirements

The action requires a JSON object containing several parameters, with the most crucial being the prompt, which describes the desired image. Additional optional parameters include:

  • mask: An image mask for inpainting.
  • image: An input image for transformations.
  • width and height: Dimensions for custom aspect ratios.
  • goFast: A boolean to enable faster image generation.
  • numOutputs: The number of images to generate.

Expected Output

The output will be a generated image URL in the specified format (e.g., webp, jpg, png). For example, a successful invocation might return:

"https://assets.cognitiveactions.com/invocations/e2f1a1ec-f423-409e-9f3e-3950ce2ece70/00b92145-8ade-4a8a-8c86-b5685e4059af.webp"

Use Cases for This Specific Action

  • Marketing and Advertising: Create unique visuals for campaigns that align with specific themes or messages.
  • Content Creation: Generate custom images for blogs or social media posts that require a personal touch.
  • Art Projects: Artists can use the inpainting feature to modify existing images or create new ones from scratch based on creative prompts.
  • Game Development: Developers can generate assets for games or interactive experiences that require specific visual styles or elements.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "31fd8ddb-293d-4e39-86b8-f88148934e78" # Action ID for: Generate Image with Inpainting Mode

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "A pop art comic book image in PACB style of a couple, their backs turned to each other in a dark room filled with broken glass. The woman has a speech bubble with the following text: \"We were never meant to last, were we?\". Ensure the text is accurate. Both characters are lost in their own despair.",
  "loraScale": 1,
  "numOutputs": 1,
  "guidanceScale": 3.5,
  "outputQuality": 90,
  "denoisingSteps": 50,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "additionalLoraScale": 1
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The "Generate Image with Inpainting Mode" action from Pacx empowers developers and creators to produce high-quality, customized images efficiently. With the ability to specify prompts, adjust various parameters, and choose output formats, this action is an invaluable asset for enhancing digital content. Consider integrating this powerful tool into your projects to unlock new possibilities in visual storytelling and creativity. Start experimenting today and see how Pacx can elevate your image generation capabilities!