Create Stunning Images with Tql's Inpainting Action

25 Apr 2025
Create Stunning Images with Tql's Inpainting Action

In today's digital landscape, the ability to generate and manipulate images quickly and efficiently is essential for developers and creators. Tql provides a powerful Cognitive Action focused on image generation through inpainting techniques, allowing for rich customization of images based on user-defined parameters. This action not only enhances productivity but also simplifies the creative process, enabling developers to produce high-quality visuals tailored to their needs.

Imagine crafting unique graphics for web applications, creating personalized marketing materials, or designing custom artwork with just a few lines of code. Tql's Generate Image with Inpainting action allows developers to harness the power of AI to transform ideas into stunning imagery, making it an invaluable tool for any project that requires custom visuals.

Prerequisites

To get started with Tql's Cognitive Actions, you'll need an API key and a basic understanding of how to make API calls.

Generate Image with Inpainting

The Generate Image with Inpainting action empowers developers to create images using advanced inpainting techniques. This operation allows for extensive customization, including control over width, height, aspect ratio, and output quality. With options for both fast inference and standard modes, developers can choose between speed and detail based on their specific needs.

Input Requirements

The action requires a prompt that guides the image generation. Additional parameters can be specified, such as:

  • Mask: An image mask for inpainting mode (if provided, width and height inputs are ignored).
  • Seed: A random seed for reproducible image generation.
  • Image: An input image for inpainting (also ignores width and height).
  • Model Type: Choose between 'dev' for detailed generation or 'schnell' for quicker results.
  • Width/Height: Specify dimensions if using a custom aspect ratio.
  • Aspect Ratio: Select from predefined ratios or set a custom one.
  • Output Count: Number of images to generate (1-4).
  • Output Format: Choose between 'webp', 'jpg', or 'png'.
  • Guidance Scale: Adjust the strength of the prompt.
  • Num Inference Steps: Control the number of denoising steps for image refinement.

Expected Output

The output will be a generated image URL, allowing for easy integration into applications or sharing across platforms. Here's an example of a generated image output:

  • https://assets.cognitiveactions.com/invocations/.../image.png

Use Cases for this specific action

  • Content Creation: Quickly generate unique images for articles, blogs, or social media posts.
  • Marketing Materials: Create tailored graphics that resonate with specific audiences or campaigns.
  • Art and Design: Experiment with different styles and concepts, producing artwork that reflects individual creativity.
  • Prototyping: Rapidly visualize ideas during development phases, enhancing collaboration and feedback.

```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 = "dd15d3e4-6dff-4963-b9cd-c44406a74f43" # Action ID for: Generate Image with Inpainting

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "model": "dev",
  "prompt": "TQL is a Shar Pei",
  "aspectRatio": "4:5",
  "outputCount": 1,
  "outputFormat": "png",
  "guidanceScale": 3.5,
  "loraIntensity": 1,
  "outputQuality": 80,
  "numInferenceSteps": 28,
  "additionalLoraIntensity": 0.8
}

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
Tql's Generate Image with Inpainting action provides developers with a robust tool for creating custom images efficiently. With its flexible parameters and options for speed versus detail, this action can cater to a wide range of use cases, from marketing to artistic endeavors. As you explore the capabilities of Tql, consider how these image generation techniques can enhance your projects and streamline your content creation process. Start integrating Tql today and unlock a new realm of creative possibilities!