Generate Stunning Images with Inpainting and LoRA Using pninitsaban/pninit Actions

24 Apr 2025
Generate Stunning Images with Inpainting and LoRA Using pninitsaban/pninit Actions

In the world of digital content creation, generating high-quality images quickly and efficiently is paramount. The pninitsaban/pninit API offers powerful Cognitive Actions that leverage advanced image generation techniques, specifically focusing on inpainting and LoRA (Low-Rank Adaptation). These actions allow developers to create stunning images by customizing resolutions, aspect ratios, and more. In this article, we will explore the capabilities of the Generate Image with Inpainting and LoRA action, guiding you through its integration into your applications.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic understanding of making API calls and handling JSON data.
  • Familiarity with Python is beneficial for implementing the provided examples.

Authentication typically involves passing your API key in the headers of your requests, allowing you to access the Cognitive Actions securely.

Cognitive Actions Overview

Generate Image with Inpainting and LoRA

The Generate Image with Inpainting and LoRA action enables you to create images using advanced inpainting techniques. This action supports customizable parameters such as resolution, aspect ratio, and LoRA weights, providing options for detailed or rapid inference models to achieve high-quality results.

Input

The input for this action is a JSON object that requires specific fields. Here’s a breakdown:

  • Required Fields:
    • prompt: The text prompt that guides the image generation.
  • Optional Fields:
    • mask: URI for the image mask in inpainting mode.
    • seed: Random seed for reproducibility.
    • image: URI for the input image in image-to-image modes.
    • model: Select between dev (detailed) or schnell (rapid).
    • width and height: Define the dimensions when using a custom aspect ratio.
    • goFast: Toggle for faster predictions.
    • loraStrength: Controls the application strength of the LoRA.
    • imageAspectRatio: Configures the aspect ratio for the generated image.
    • imageOutputFormat: Format of the output images (e.g., webp, jpg, png).
    • numberOfOutputs: Number of images to generate.

Here’s an example input JSON payload:

{
  "model": "dev",
  "goFast": false,
  "prompt": "relaxed profile image of Pninit, dressed in smart casual attire, with a hint of a smile and soft natural lighting, backgroung blurred to emphazise her personality in a genuine, down to earth way. keep short gray hair , full body proportion and real original nose",
  "loraStrength": 1,
  "imageMegapixels": "1",
  "numberOfOutputs": 1,
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "imageOutputQuality": 80,
  "initialPromptStrength": 0.8,
  "additionalLoraStrength": 1,
  "diffusionGuidanceScale": 3,
  "numberOfInferenceSteps": 28
}

Output

When you successfully execute the action, you will receive an array of URLs pointing to the generated images. For example:

[
  "https://assets.cognitiveactions.com/invocations/a9e80f82-6629-499b-9de7-c74d2188172f/7d6f7601-5815-4f8d-86c9-720bf6e196e3.webp"
]

This output provides direct links to the images created based on your input parameters.

Conceptual Usage Example (Python)

Here is a conceptual Python code snippet that demonstrates how to call the Generate Image with Inpainting and LoRA action:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "ce5dda49-f2ed-4fec-bfeb-d0729aaf8e84" # Action ID for Generate Image with Inpainting and LoRA

# Construct the input payload based on the action's requirements
payload = {
    "model": "dev",
    "goFast": False,
    "prompt": "relaxed profile image of Pninit, dressed in smart casual attire, with a hint of a smile and soft natural lighting, backgroung blurred to emphazise her personality in a genuine, down to earth way. keep short gray hair , full body proportion and real original nose",
    "loraStrength": 1,
    "imageMegapixels": "1",
    "numberOfOutputs": 1,
    "imageAspectRatio": "1:1",
    "imageOutputFormat": "webp",
    "imageOutputQuality": 80,
    "initialPromptStrength": 0.8,
    "additionalLoraStrength": 1,
    "diffusionGuidanceScale": 3,
    "numberOfInferenceSteps": 28
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this code snippet, replace the placeholder API key and endpoint with your actual credentials. The action ID corresponds to the Generate Image with Inpainting and LoRA action. The payload is constructed based on the required and optional fields outlined earlier.

Conclusion

By integrating the Generate Image with Inpainting and LoRA action from the pninitsaban/pninit API, developers can effortlessly create compelling images tailored to their specific needs. This action opens up new possibilities in content creation, allowing for intricate customizations and rapid image generation. Explore these capabilities further, experiment with different parameters, and take your applications to the next level!