Create Stunning Custom Images with Lemuia's Inpainting Action

26 Apr 2025
Create Stunning Custom Images with Lemuia's Inpainting Action

In the world of digital content creation, the demand for high-quality, customized images is ever-growing. Lemuia offers a powerful Cognitive Action that allows developers to generate custom images through advanced inpainting techniques. This action not only simplifies the image creation process but also enhances the creative possibilities by enabling users to define specific attributes such as resolution, aspect ratio, and output format.

Imagine being able to transform a basic image into a stunning piece of art with just a few parameters. Whether you're building an app that requires unique graphics or enhancing a website with tailored visuals, Lemuia's image generation capabilities can streamline your workflow and elevate your projects. Common use cases for this action include creating marketing materials, generating illustrations for articles, or designing unique avatars for users in gaming applications.

Prerequisites

To get started with Lemuia's Cognitive Actions, you will need an API key and a basic understanding of making API calls.

Generate Custom Image with Inpainting

This operation generates custom images using image-to-image transformation and inpainting capabilities. It allows users to specify image attributes such as resolution, aspect ratio, and output format, while also providing options for faster predictions and enhanced detail through adjustable LoRA scales and inference steps.

Input Requirements

The input for this action requires a JSON object with the following fields:

  • prompt (string, required): A detailed textual description of the image you want to generate. Including specific trigger words can help evoke the intended style or concept.
  • mask (string, optional): An image mask for inpainting mode. If provided, other dimensions will be ignored.
  • image (string, optional): Input image for image-to-image transformation. If provided, dimensions will also be ignored.
  • width (integer, optional): Width of the generated image in pixels (only if aspect_ratio is set to 'custom').
  • height (integer, optional): Height of the generated image in pixels (only if aspect_ratio is set to 'custom').
  • goFast (boolean, optional): Enables faster predictions using a speed-optimized model.
  • imageFormat (string, optional): Specifies the output image format (e.g., webp, jpg, png).
  • outputCount (integer, optional): Specifies the number of images to generate (1-4).
  • guidanceScale (number, optional): Defines the guidance scale for the diffusion process.
  • outputQuality (integer, optional): Sets the quality level for saving output images.
  • denoisingSteps (integer, optional): Determines the number of denoising steps for image generation.
  • extraLoraScale (number, optional): Adjusts the intensity of additional LoRA applications.
  • inferenceModel (string, optional): Selects the model for running inference.

Expected Output

The action returns an array of URLs pointing to the generated images. Each URL corresponds to an image created based on the provided prompt and specifications.

Use Cases for this Specific Action

  • Marketing Campaigns: Create tailored visuals for ads or social media posts that resonate with your audience.
  • Content Creation: Generate unique images for blog posts, articles, or eBooks that stand out.
  • Gaming Applications: Design custom avatars or game assets that enhance user engagement and creativity.
  • Personal Projects: Bring your artistic visions to life with personalized images for gifts or personal websites.
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 = "b9fa0c7f-1d27-4a70-9f2b-aafcf8f72971" # Action ID for: Generate Custom 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 = {
  "goFast": false,
  "prompt": "\"Lemu, a man with a perfectly shaved, smooth bald head that reflects a clean and polished look, is featured in a high-quality, casual yet formal portrait. He has a medium-length, well-groomed, and neatly trimmed black beard with sharp, delineated edges, paired with modern rectangular glasses. Lemu weighs around 100 kg and has a moderately muscular build, with a strong but not overly bulky physique. He is dressed in a stylish, tailored navy blue suit with a crisp white open-collared shirt, no tie, giving a relaxed yet professional vibe. He is sitting in a legal office, showing a warm, confident smile on his face, his body slightly turned to the side in a relaxed posture. The background features a sophisticated legal office setting with large floor-to-ceiling windows, soft natural light streaming in, a polished wooden desk with legal books and a gavel, and a leather chair. The overall atmosphere is polished and approachable, with a focus on sharp details in the navy blue suit, the perfectly shaved bald head, and a professional legal office environment.\"",
  "loraScale": 1,
  "imageFormat": "webp",
  "outputCount": 2,
  "guidanceScale": 2.54,
  "outputQuality": 80,
  "denoisingSteps": 28,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "approxMegapixels": "1",
  "imageAspectRatio": "1: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

Lemuia's image generation capabilities offer developers a flexible and powerful tool for creating custom visuals. By leveraging advanced inpainting techniques, you can generate unique images that meet your specific needs, whether for marketing, content creation, or gaming. The ease of use and customization options make it an invaluable resource for any developer looking to enhance their applications with high-quality imagery. Start integrating Lemuia's Cognitive Actions today and unlock a world of creative possibilities!