Create Stunning Images with Danitgr's Inpainting Action

26 Apr 2025
Create Stunning Images with Danitgr's Inpainting Action

In the realm of image generation, Danitgr stands out by offering innovative Cognitive Actions designed to simplify the process of creating high-quality images. One of its most powerful features is the ability to generate images with inpainting, which allows developers to create visually compelling content quickly and efficiently. This action leverages existing images or textual prompts to produce new images, making it a versatile tool for various applications.

The benefits of using Danitgr for image generation are manifold. It provides flexibility in terms of aspect ratios, image quality, and model precision, while emphasizing speed and reproducibility. Whether you're looking to enhance creative projects, generate unique artwork, or automate content creation, this action can significantly streamline the workflow.

Prerequisites

To get started with Danitgr's Cognitive Actions, you'll need an API key and a basic understanding of how to make API calls.

Generate Image with Inpainting

This action produces a generated image based on either an input image or a textual prompt, utilizing image-to-image or inpainting modes. It addresses the need for high-quality, unique images tailored to specific requirements, whether for artistic endeavors or practical applications.

Input Requirements:

  • prompt (string): A description or phrase that guides the image generation (e.g., "danitgr woman face to the camera").
  • image (optional string): An input image for image-to-image or inpainting mode.
  • mask (optional string): An image mask for inpainting mode.
  • width (integer): Width of the generated image (if aspect ratio is custom).
  • height (integer): Height of the generated image (if aspect ratio is custom).
  • outputCount (integer): Number of images to generate (1 to 4).
  • imageFormat (string): Format of the output images (default is webp).
  • imageQuality (integer): Quality of the output images (0 to 100).
  • guidanceScale (number): Affects the realism of the images.
  • inferenceModel (string): The model to run inference with (dev or schnell).
  • Additional parameters for fine-tuning such as promptStrength, mainLoraScale, enableFastMode, and more.

Expected Output: The output will be a URL to the generated image in the specified format. For example:

  • ["https://assets.cognitiveactions.com/invocations/f7bca3ae-6db1-4bbf-99ec-dc96085d0326/78eb2f3f-ea09-4120-97ed-4392dd3f96da.webp"]

Use Cases for this specific action:

  • Artistic Creation: Artists can use this action to generate unique artworks or enhance existing pieces with new elements.
  • Content Generation: Bloggers and marketers can automate the creation of visuals for articles, social media, or advertisements.
  • Game Development: Developers can create assets or backgrounds that fit specific themes or narratives within their games.
  • Personal Projects: Hobbyists can explore their creativity by generating images based on their ideas or inspirations.
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 = "3c8c3ee7-4f64-4f1c-b4de-0b0b754a7aa2" # Action ID for: Generate 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 = {
  "prompt": "danitgr woman face to the camera",
  "imageFormat": "webp",
  "outputCount": 1,
  "imageQuality": 80,
  "guidanceScale": 3,
  "mainLoraScale": 1,
  "enableFastMode": false,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "outputAspectRatio": "16:9",
  "inferenceStepCount": 28,
  "additionalLoraScale": 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

Danitgr's image generation capabilities, particularly through the inpainting action, offer developers a powerful tool for creating high-quality, unique images swiftly. Its flexibility and speed make it suitable for a wide array of applications, from professional projects to personal creative endeavors. By integrating this action into your workflow, you can enhance your projects with stunning visuals that captivate and engage your audience. Explore the possibilities and take your image generation to the next level with Danitgr!