Enhance Your Images with Elora's Inpainting and Refinement

26 Apr 2025
Enhance Your Images with Elora's Inpainting and Refinement

Elora is an innovative service designed to simplify the process of image generation through advanced cognitive actions. One of its standout features is the ability to generate images using inpainting and refinement techniques. This powerful tool allows developers to create high-quality visuals tailored to their specific needs, making it an invaluable resource for various applications, from creative design to marketing.

Imagine needing to fill in details of an image or create a completely new scene by specifying areas to alter. Elora makes this possible with customizable options for image resolution, style, and refinement, ensuring that the output aligns with your vision. Whether you're an artist looking to expand your creative toolkit or a developer seeking to automate image generation for applications, Elora's capabilities can significantly enhance your workflow.

Prerequisites

To get started with Elora, you'll need a Cognitive Actions API key and a basic understanding of API calls to integrate these features seamlessly into your projects.

Generate Image with Inpainting and Refinement

This operation generates images using inpainting and optional refinement techniques. It allows users to specify the input mask and various parameters for image generation, such as resolution, guidance scale, and refinement style, ensuring high-quality output with customizable styles.

Input Requirements

The input for this action consists of several parameters:

  • Mask: A URI of the input mask image where black areas are preserved and white areas will be altered.
  • Image: A URI of the input image used in img2img or inpaint processes.
  • Width and Height: Define the output image dimensions (default is 1024x1024).
  • Prompt: Descriptive text to guide image generation (default: "An astronaut riding a rainbow unicorn").
  • Output Image Count: Specifies how many images to generate (1 to 4).
  • Refinement Style: Chooses the refinement approach (options include no refiner, expert ensemble refiner, and base image refiner).
  • Guidance Scale: A scale factor for classifier-free guidance during image generation (default is 7.5).
  • Apply Watermark: Indicates whether to apply a watermark to generated images (default is true).
  • Negative Prompt: Additional prompts to influence the model by specifying undesired traits.
  • Prompt Strength: Controls how strongly the input prompt influences the result (default is 0.8).
  • LoRA Scale Factor: Adjusts the integration of Low-Rank Adaptation (default is 0.6).
  • Inference Step Count: Total number of denoising steps taken during image synthesis (default is 50).

Expected Output

The expected output from this action consists of an array of generated images, each represented by a URI link to the resulting image files.

Use Cases for this specific action

This action is particularly useful in scenarios where:

  • You want to creatively alter existing images while preserving certain elements.
  • You require the generation of multiple variations of an image based on specific prompts.
  • You're developing applications that need dynamic image content, such as advertising or social media visuals.
  • You need to automate the creation of high-quality images for web platforms or marketing materials.
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 = "3f3dcea6-57a2-433e-96b2-b5bb8c6df685" # Action ID for: Generate Image with Inpainting and Refinement

# 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": "TOK as a centered portrait of an ultra detailed Mechanical Cyberpunk female Android, looking into the camera, intricate, elegant, super highly detailed, smooth, sharp focus, no blur, no dof, extreme illustration",
  "outputCount": 4,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "promptStrength": 0.8,
  "loraScaleFactor": 0.75,
  "schedulingMethod": "K_EULER",
  "highNoiseFraction": 0.8,
  "inferenceStepCount": 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("------------------------------------------------")

Conclusion

Elora's image generation capabilities through inpainting and refinement offer a robust solution for developers looking to enhance their creative projects. By leveraging customizable parameters, you can create stunning visuals tailored to your specific needs, whether for artistic expression or commercial applications. As you explore these features, consider how they can streamline your workflow and elevate the quality of your image outputs. Start integrating Elora today to unlock the full potential of your image generation projects!