Create Stunning Images with In-Painting Cognitive Actions

27 Apr 2025
Create Stunning Images with In-Painting Cognitive Actions

In the world of digital content creation, the ability to generate high-quality images quickly and efficiently is invaluable. "Thismpdoesntexist" offers a powerful Cognitive Action that allows developers to utilize an in-painting process for image generation. This operation not only enhances creativity but also simplifies the workflow by enabling customization through various parameters such as input images, masks, and prompts. With features like classifier-free guidance and LoRA scaling, developers can achieve tailored results that meet their specific needs.

Imagine a scenario where you need to create unique visuals for a marketing campaign or an artistic project. This Cognitive Action can help you generate images that resonate with your audience while saving you time and resources. Whether you're enhancing existing images or creating entirely new ones, the in-painting capabilities offered by this service can elevate your projects.

Prerequisites

Before diving into the Cognitive Actions, you will need an API key for "Thismpdoesntexist" and a basic understanding of making API calls.

Generate Image with In-paint

The Generate Image with In-paint action is designed to facilitate the creation of images using an in-painting process. This operation solves the problem of generating visually appealing content by allowing users to specify various parameters that influence the output.

Input Requirements

To use this action, you will need to provide a JSON object that includes:

  • mask: A URI for the input mask, where black areas are preserved and white areas are inpainted.
  • seed: An optional integer for random seed variance.
  • image: A URI for the input image.
  • width and height: Dimensions for the output image (default 1024x1024).
  • prompt: A text prompt that guides the image generation process.
  • loraScale: A number that applies LoRA scaling, relevant for trained models.
  • outputCount: An integer specifying how many images to generate (1-4).
  • refineStyle: Options for refinement styles.
  • guidanceScale: A number determining how closely the image should follow the prompt.
  • applyWatermark: A boolean to apply a watermark to generated images.
  • negativePrompt: A text prompt for undesired elements.
  • promptStrength: A number indicating the effect strength of the prompt.
  • schedulingMethod: The method for scheduling the generation process.
  • highNoiseFraction: A fraction for noise application during refinement.
  • numInferenceSteps: Specifies the number of denoising steps.
  • disableSafetyChecker: A toggle to disable the safety checker.

Expected Output

The output will be an array of image URLs, each representing a generated image based on the provided input parameters.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "In the style of the House of Commons, a portrait of mr blobby",
  "loraScale": 0.62,
  "outputCount": 4,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "promptStrength": 0.8,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.8,
  "numInferenceSteps": 50
}

Example Output:

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 = "29ce48de-d540-4d4c-85a3-bb70d89d2081" # Action ID for: Generate Image with In-paint

# 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": "In the style of the House of Commons, a portrait of mr blobby",
  "loraScale": 0.62,
  "outputCount": 4,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "promptStrength": 0.8,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.8,
  "numInferenceSteps": 50
}

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("------------------------------------------------")

Use Cases for this Action

This action is perfect for a variety of applications, including:

  • Marketing Campaigns: Quickly generate unique visuals tailored to specific themes or messages.
  • Artistic Projects: Artists can create stunning graphics or illustrations based on their creative prompts.
  • Prototyping: Designers can visualize concepts and variations rapidly during the design phase.
  • Content Creation: Bloggers and social media managers can enhance their posts with custom images that align with their content.

Conclusion

The "Generate Image with In-paint" Cognitive Action provides developers with an innovative way to create and customize images efficiently. With its range of features and adaptability, it opens up countless possibilities for enhancing digital content. Consider integrating this action into your projects to streamline your creative process and produce stunning visuals that captivate your audience. Start exploring the potential of in-painting today!