Enhance Your Image Generation with Nicoly's Inpainting Action

26 Apr 2025
Enhance Your Image Generation with Nicoly's Inpainting Action

In the world of digital content creation, the ability to generate and manipulate images has become essential. Nicoly provides a powerful Cognitive Action focused on image generation through inpainting, allowing developers to create stunning visuals with precision and flexibility. This action not only simplifies the image creation process but also enhances it by enabling custom aspect ratios, guidance scale adjustments, and additional model weights for improved results.

Common use cases for Nicoly's image generation capabilities include creating unique artwork, designing marketing materials, and generating content for social media. Whether you're an artist looking to automate parts of your creative process or a developer integrating image generation into applications, Nicoly offers a versatile solution to meet your needs.

Prerequisites

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

Generate Image with Inpainting

The Generate Image with Inpainting action allows you to create images using image-to-image conversion and inpainting techniques. This action is particularly useful for tasks that require filling in missing parts of an image or generating entirely new images based on existing ones.

Input Requirements

To utilize this action, you must provide a prompt that describes the desired image. You can also specify optional parameters such as:

  • mask: A URI for an image mask used in inpainting mode.
  • image: A URI for an input image in image-to-image or inpainting mode.
  • model: Choose between "dev" for optimal performance or "schnell" for faster results.
  • aspectRatio: Define the aspect ratio for the generated image, with options for custom dimensions.
  • numOutputs: Specify how many images you want to generate.
  • Additional parameters like guidanceScale, outputQuality, and promptStrength help fine-tune the generated output.

Expected Output

The output will be a generated image based on the provided prompt and parameters. The image will be returned in the specified format (e.g., PNG, JPG, WEBP), and the quality can be adjusted according to your needs.

Use Cases for this Specific Action

This action is ideal for:

  • Creative Professionals: Artists and designers can leverage inpainting to generate unique artwork or enhance existing images.
  • Marketing: Create tailored visuals for campaigns by generating images that align with specific themes or branding.
  • Content Generation: Automate the production of images for blogs, social media posts, or digital publications, saving valuable time and effort.
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 = "b35b7dc3-4217-4a97-9e43-6f3bf0670ff4" # 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 = {
  "model": "dev",
  "prompt": "nicoly 14 year old girl in white lingerie, without a bra showing her small breasts, the girl is on the beach",
  "loraScale": 1,
  "numOutputs": 1,
  "aspectRatio": "1:1",
  "outputFormat": "png",
  "guidanceScale": 3.5,
  "outputQuality": 100,
  "extraLoraScale": 1,
  "promptStrength": 0.8,
  "numInferenceSteps": 28
}

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

Nicoly's image generation capabilities through inpainting provide a robust solution for developers and creators alike. By simplifying the process of image creation and offering extensive customization options, Nicoly empowers users to produce high-quality visuals efficiently. Whether you're looking to automate your creative workflow or enhance your applications with dynamic image generation, Nicoly's Cognitive Action is a valuable tool in your development arsenal. Explore the possibilities and elevate your projects with Nicoly today!