Create Stunning Inpainted Images with the stasdeep/superside-small Cognitive Actions

In the world of image processing, creativity meets technology through the use of Cognitive Actions. The stasdeep/superside-small spec offers a powerful Cognitive Action designed to generate inpainted images. By leveraging AI-guided prompts, developers can create customized images by filling specified areas effectively. This can enhance applications in various fields, such as gaming, design, and content creation.
Prerequisites
Before diving into the integration, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic knowledge of making API requests, particularly with JSON payloads.
- Familiarity with Python for executing conceptual code samples.
Authentication typically involves passing your API key in the headers of your requests, ensuring secure access to the Cognitive Actions services.
Cognitive Actions Overview
Generate Inpainted Image
Description: This action creates inpainted images from input images by filling specified areas using AI-guided prompts, offering customization in refinement and style.
Category: Image-Processing
Input
The input for this action is defined in the CompositeRequest schema. Here's a breakdown of the required and optional fields:
- mask (string, required): URI of the input mask for inpaint mode, where black areas remain unchanged and white areas are inpainted.
- seed (integer, optional): A random seed for image generation. Leave blank for a randomized seed.
- image (string, required): URI of the input image for img2img or inpaint mode.
- width (integer, optional): Desired width of the output image in pixels. Default is 1024.
- height (integer, optional): Desired height of the output image in pixels. Default is 1024.
- prompt (string, required): Descriptive prompt for generating the image.
- refine (string, optional): Specifies the refinement style ('no_refiner', 'expert_ensemble_refiner', 'base_image_refiner'). Default is 'no_refiner'.
- scheduler (string, optional): Algorithm used for generating images. Default is 'K_EULER'.
- numOutputs (integer, optional): Total number of images to generate (1 to 4). Default is 1.
- loraWeights (string, optional): URI of LoRA weights file to use.
- refineSteps (integer, optional): Applicable when 'base_image_refiner' is selected. Determines the number of refinement steps.
- guidanceScale (number, optional): Adjusts classifier-free guidance scale (1 to 50). Default is 7.5.
- applyWatermark (boolean, optional): Enables watermark on generated images. Default is true.
- negativePrompt (string, optional): Optional negative prompt to counterbalance the main prompt.
- promptStrength (number, optional): Determines the prompt's impact during img2img or inpainting (0 to 1). Default is 0.8.
- highNoiseFraction (number, optional): Applicable to 'expert_ensemble_refiner'. Valid range is 0 to 1. Default is 0.8.
- loraScalingFactor (number, optional): Factor for adjusting LoRA scale. Default is 0.6.
- numInferenceSteps (integer, optional): Total number of denoising steps (1 to 500). Default is 50.
- disableSafetyChecker (boolean, optional): Option to disable safety checks on generated images. Default is false.
Example Input:
Here’s a practical example of the JSON payload needed to invoke the action:
{
"width": 1000,
"height": 1000,
"prompt": "In the style of TOK, a vector flat illustration of a small gaming controller in dark sky",
"refine": "no_refiner",
"scheduler": "K_EULER",
"numOutputs": 2,
"guidanceScale": 7.5,
"applyWatermark": true,
"negativePrompt": "",
"promptStrength": 0.8,
"highNoiseFraction": 0.8,
"loraScalingFactor": 0.7,
"numInferenceSteps": 50
}
Output
Upon execution, the action typically returns a list of URLs pointing to the generated images. Here's an example of the output:
[
"https://assets.cognitiveactions.com/invocations/93fa7fd0-9f93-4f11-85b7-06a666c8bcd3/67b5280a-0121-4d62-8fcd-13809d1afd28.png",
"https://assets.cognitiveactions.com/invocations/93fa7fd0-9f93-4f11-85b7-06a666c8bcd3/579514ff-e65f-4ceb-b49b-ef7a711669dc.png"
]
The output will include the URLs of the generated images based on the input parameters specified.
Conceptual Usage Example (Python)
Below is a conceptual Python code snippet demonstrating how to call the hypothetical Cognitive Actions execution endpoint:
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 = "f5a824d3-15e4-48d9-8f9a-7357dfb31a2a" # Action ID for Generate Inpainted Image
# Construct the input payload based on the action's requirements
payload = {
"width": 1000,
"height": 1000,
"prompt": "In the style of TOK, a vector flat illustration of a small gaming controller in dark sky",
"refine": "no_refiner",
"scheduler": "K_EULER",
"numOutputs": 2,
"guidanceScale": 7.5,
"applyWatermark": True,
"negativePrompt": "",
"promptStrength": 0.8,
"highNoiseFraction": 0.8,
"loraScalingFactor": 0.7,
"numInferenceSteps": 50
}
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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is constructed based on the previously defined input schema. The script sends a POST request to the Cognitive Actions API and prints the resulting image URLs upon successful execution.
Conclusion
The Generate Inpainted Image Cognitive Action provides a remarkable way to create customized images with AI-driven capabilities. By utilizing this action, developers can enhance their applications, making them more engaging and visually appealing.
Explore the potential of this action in your projects, whether for artistic creation, game development, or innovative design solutions. Happy coding!