Create Stunning Images with Advanced Inpainting Actions

26 Apr 2025
Create Stunning Images with Advanced Inpainting Actions

In the world of digital content creation, the ability to generate high-quality images is paramount. The "Pillowcases" service offers a powerful Cognitive Action that enables developers to create stunning images through advanced features like inpainting, customizable settings, and model selection. This action is designed to simplify the image generation process while ensuring high-quality outputs, making it an invaluable tool for developers in various industries, from e-commerce to marketing.

Imagine being able to enhance product images effortlessly or create captivating visuals for blogs and social media. With Pillowcases, you can do just that by generating images that meet specific requirements and aesthetic preferences. Whether you’re looking to create beautiful product displays or artistic representations, the flexibility and power of this service can save you time and resources.

Prerequisites

To get started with Pillowcases, you will need a Cognitive Actions API key and a basic understanding of API calls to integrate this service into your applications seamlessly.

Generate Enhanced Images with Inpainting

The primary action offered by Pillowcases is "Generate Enhanced Images with Inpainting." This action is designed to create high-quality images by utilizing advanced inpainting techniques and customizable parameters.

Purpose

This action addresses the need for high-quality image generation while allowing for significant customization. It enables developers to produce images that fit specific dimensions, formats, and qualities tailored to their projects.

Input Requirements

To use this action, the following input parameters are required:

  • Prompt: A descriptive text that guides the image generation, such as "A close-up of a luxurious white pillowcase made from soft, high-quality Supima cotton."
  • Model Type: Select between "dev" for optimal performance or "schnell" for faster results.
  • Aspect Ratio: Choose from predefined ratios or set a custom width and height.
  • Output Count: Specify how many images to generate (1 to 4).
  • Output Format: Choose the desired format for the output images (webp, jpg, png).
  • Additional parameters include guidance scale, LoRA intensity, denoising steps, and more, which further refine the output.

Expected Output

The action produces one or more images based on the provided prompt and parameters. For example, a successful request might return a URL to a generated image like:

  • https://assets.cognitiveactions.com/invocations/c9ab3e1d-e509-4c9c-902d-8095219b7cac/6bdfc619-7257-4d50-8b1e-adfe36d4f06d.webp

Use Cases for this Specific Action

  • E-commerce: Create high-quality product images that can enhance online listings, drawing customer attention and increasing conversion rates.
  • Marketing: Generate unique visuals for campaigns, social media posts, or promotional materials that stand out.
  • Content Creation: Produce custom images for blogs, articles, or websites that align with specific themes or messages.
  • Art and Design: Enable artists and designers to experiment with new concepts and styles by generating images based on descriptive prompts.
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 = "18037d94-f2dc-40f9-9d30-1d6723854050" # Action ID for: Generate Enhanced Images with Inpainting

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "A close-up of a luxurious white pillowcases made from soft, high-quality Supima cotton. The pillowcase features an elegant design with two distinct pleats, adding a sophisticated and exclusive touch. The fabric is silky smooth with a subtle sheen, and gentle natural folds enhance its inviting feel. The background is light and neutral, highlighting the pillowcase's clean aesthetic and premium quality.",
  "modelType": "dev",
  "aspectRatio": "1:1",
  "outputCount": 1,
  "outputFormat": "webp",
  "guidanceScale": 3,
  "loraIntensity": 1,
  "outputQuality": 80,
  "denoisingSteps": 28,
  "promptStrength": 0.8,
  "imageResolution": "1",
  "fasterPrediction": false,
  "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 Pillowcases service offers developers an innovative solution for generating high-quality images with advanced customization options. By leveraging the inpainting capabilities, you can create stunning visuals that meet your specific needs, whether for e-commerce, marketing, or content creation. As you explore the various parameters and possibilities, you'll find that this action not only streamlines your workflow but also enhances the quality of your output. Start integrating Pillowcases into your projects today and elevate your image generation capabilities!