Transform Your Images with Lora Inpainting Actions

26 Apr 2025
Transform Your Images with Lora Inpainting Actions

In the world of digital content creation, the ability to modify images seamlessly can significantly enhance the quality and impact of visual storytelling. Lora Inpainting offers developers a powerful set of tools to perform inpainting, allowing for the intelligent modification of images based on user-defined parameters. By integrating these Cognitive Actions into your applications, you can automate and simplify complex image editing tasks, resulting in faster workflows and higher-quality outputs.

Common use cases for Lora Inpainting include repairing damaged images, enhancing product photos, generating variations of existing artwork, or creatively altering scenes in photography. This capability is especially useful for graphic designers, marketers, and content creators who require flexibility and precision in their visual assets.

Prerequisites

To get started with Lora Inpainting, you will need a valid Cognitive Actions API key and a basic understanding of how to make API calls.

Perform Inpainting Prediction

The Perform Inpainting Prediction action utilizes the SDRV_2.0 model to apply inpainting techniques to an image using a specified mask. This action empowers developers to generate variations of images based on defined attributes such as dimensions, output quantity, and LoRA model configurations. By leveraging prompts and negative prompts, users can finely control the results of the inpainting process, ensuring that the modifications align perfectly with their creative vision.

Input Requirements

  • Mask (URI): A black and white image that serves as the mask for inpainting. Black pixels indicate areas to be inpainted, while white pixels remain unchanged.
  • Seed (integer): A random seed for variation generation, which can be left unset for randomization.
  • Image (URI): The initial image to be modified (optional for Img2Img functionality).
  • Width (integer): The desired width of the output image, with a maximum of 1024 pixels.
  • Height (integer): The desired height of the output image, also capped at 1024 pixels.
  • Prompt (string): A textual input prompt that guides the inpainting process, allowing placeholders for specific LoRA concepts.
  • LoRA URLs (string): URIs of safetensors for LoRA models.
  • Scheduler (string): The scheduler type to control the process.
  • LoRA Scales (string): Scaling factors for the LoRA models.
  • Guidance Scale (number): A scale for classifier-free guidance, ranging between 1 and 20.
  • Negative Prompt (string): Details about unwanted elements in the output image.
  • Prompt Strength (number): Indicates how much of the original image data is replaced.
  • Number of Outputs (integer): Specifies how many images to generate (max 4).
  • Number of Inference Steps (integer): The number of denoising steps to apply.

Expected Output

The action will return a list of generated images based on the inpainting process, providing developers with URLs to access the modified images.

Use Cases for this specific action

  • Image Restoration: Repairing old photographs or damaged artwork by intelligently filling in missing or corrupted sections.
  • Creative Enhancements: Adding elements to an image or altering aspects of a scene to better fit a narrative or marketing campaign.
  • Artistic Variations: Generating multiple versions of an artwork or design to explore different styles or compositions efficiently.

```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 = "3882fd51-10e1-4009-90b3-6417b63b0c73" # Action ID for: Perform Inpainting Prediction

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 768,
  "height": 768,
  "prompt": "(((masterpiece))),(((bestquality))),((ultra-detailed)),(illustration),((anextremelydelicateandbeautiful)),dynamicangle,floating,(beautifuldetailedeyes),(detailedlight) (1girl), solo , floating_hair,glowingeyes,green hair,greeneyes <1>, twintails, halterdress,",
  "loraUrls": "https://replicate.delivery/pbxt/Mf7QBwNXrehQ3k6GwMPpi8bqy0cer9x1NqogXVWylWC9l6YhA/tmp28kwa2ceclexz5tc90001zun1iy5b8x3wzip.safetensors",
  "scheduler": "K_EULER_ANCESTRAL",
  "loraScales": "0.8",
  "guidanceScale": 3.57,
  "negativePrompt": "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, multiple head, lowres, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, watermark, blurry, multiple girls, multiple faces, canvas frame, cartoon, ((multiple head)), ((bad art)), ((extra limbs)), ((b&w)), wierd colors, (((duplicate))), ((morbid)), ((mutilated)), extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), ((bad anatomy)), (((bad proportions))), cloned face, (((disfigured))), out of frame, gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), (fused fingers), (too many fingers), (((long neck))), video game, tiling, poorly drawn feet, mutated, cross-eye, body out of frame, Humpbacked, shadow, nude, naked, NSFW, bad quality, low quality, fused fingers, poorly drawn face, too many fingers",
  "promptStrength": 0.87,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 31
}

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
Lora Inpainting provides developers with a versatile and powerful tool for image modification, enabling a wide range of applications from restoration to creative enhancements. By leveraging the detailed customization options and advanced inpainting capabilities, you can significantly improve your image processing workflows. As a next step, consider experimenting with different prompts and masks to discover the full potential of Lora Inpainting in your projects.