Create Stunning Inpainted Images Effortlessly with Du

27 Apr 2025
Create Stunning Inpainted Images Effortlessly with Du

In the realm of image generation, Du offers a powerful API that simplifies the process of creating inpainted images. By leveraging advanced machine learning techniques, developers can generate tailored images that meet specific requirements, all while enjoying the flexibility to customize various aspects of the output. This service not only enhances productivity by streamlining the image creation workflow but also opens up new creative possibilities.

Imagine a scenario where you need to edit an image by removing unwanted elements or filling in gaps seamlessly. With Du's inpainting capabilities, you can achieve this effortlessly. Whether you're a game developer looking to create immersive environments, an artist seeking to refine your digital artworks, or a marketer needing custom visuals for campaigns, Du provides the tools to bring your vision to life.

Prerequisites

To get started with Du's Cognitive Actions, you will need an API key and a basic understanding of how to make API calls. This will enable you to integrate the inpainting features into your applications effectively.

Generate Inpainted Image

The "Generate Inpainted Image" action allows you to create images with specific areas modified based on a defined mask. This action is part of the image-generation category and addresses the need for precise image editing and enhancement.

Purpose

This action provides a solution for generating images where certain parts are either preserved or altered according to the user's specifications. It enables developers to create visually appealing images without the hassle of manual editing.

Input Requirements

The action requires a structured input that includes:

  • Mask: A URI defining which areas of the image to inpaint (white for inpainting, black for preservation).
  • Image: A URI of the input image you want to modify.
  • Width & Height: Specify the dimensions of the output image (default is 1024x1024).
  • Prompt: A guiding text to influence the image generation.
  • Additional parameters like guidance scale, negative prompt, and number of outputs allow for further customization.

Expected Output

The output will be a URI pointing to the generated inpainted image, tailored to your specifications.

Use Cases for this specific action

  • Artistic Creation: Artists can use this action to refine their digital illustrations by seamlessly integrating new elements or correcting existing ones.
  • Game Development: Game developers can generate unique textures or backgrounds by inpainting specific areas of existing assets, saving time in asset creation.
  • Marketing Materials: Marketers can create customized images for campaigns by modifying stock images to better reflect their brand message.

```python
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 = "f565ef76-d075-46a2-8109-e5829a587bda" # Action ID for: Generate Inpainted Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 1024,
  "height": 1024,
  "prompt": "pixel-art ,photo of TOK, . low-res, blocky, pixel art style, 8-bit graphics",
  "scaleForLoRA": 0.9,
  "guidanceScale": 7.5,
  "inversePrompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic,NSFW",
  "applyWatermark": false,
  "numberOfOutputs": 1,
  "schedulingMethod": "K_EULER"
}

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
Du's inpainting capabilities empower developers to create stunning, customized images with ease. By leveraging this API, you can streamline your workflow, enhance your creative projects, and produce unique visuals that stand out. Whether you're working on art, games, or marketing materials, Du provides the flexibility and functionality needed to bring your ideas to life. Start integrating Du today and unlock the potential of effortless image generation!