Enhance Your Images: Integrating the xghm/sdxl-eyemask Cognitive Actions

In today's digital world, enhancing images with precision and creativity is crucial for various applications, from marketing to art. The xghm/sdxl-eyemask API provides a powerful set of Cognitive Actions that allow developers to generate enhanced images through advanced image processing techniques. Among its offerings, the "Generate Enhanced Inpainted Image" action stands out as a versatile tool for modifying specific areas of images based on user-defined prompts.
By leveraging these pre-built actions, developers can save time and effort in building complex image manipulation functionalities from scratch, allowing for high-quality results with just a few lines of code.
Prerequisites
Before you start using the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform, which enables you to authenticate your requests.
- Familiarity with JSON structure and the ability to send HTTP requests.
To authenticate, you will typically pass your API key in the request headers, ensuring secure access to the Cognitive Actions features.
Cognitive Actions Overview
Generate Enhanced Inpainted Image
Description: This action generates enhanced images by leveraging inpaint mode to modify specified areas of input images based on a given prompt. It offers multiple refining styles and customizable parameters for high-quality results.
Category: Image Processing
Input
The input schema for this action requires several parameters to customize the image generation process:
- mask (string, required): URI of the input mask for inpaint mode. Black areas are preserved, and white areas are inpainted.
- seed (integer, optional): Random seed for deterministic outputs. Leave blank to use a random seed each time.
- image (string, required): URI of the input image used for img2img or inpaint modes.
- width (integer, default: 1024, optional): Width of the output image in pixels.
- height (integer, default: 1024, optional): Height of the output image in pixels.
- prompt (string, default: "An astronaut riding a rainbow unicorn", required): Textual description to guide image generation.
- refine (string, default: "no_refiner", optional): Refinement style to be applied to the generated image. Options include 'no_refiner,' 'expert_ensemble_refiner,' or 'base_image_refiner.'
- scheduler (string, default: "K_EULER", optional): Algorithm used for the generation process.
- contraPrompt (string, optional): Text prompt to specify undesired features.
- promptImpact (number, default: 0.8, optional): Strength of the prompt in img2img or inpaint mode.
- additiveScale (number, default: 0.6, optional): Scaling factor for LoRA.
- numberOfOutputs (integer, default: 1, optional): Number of images to be generated per request.
- includeWatermark (boolean, default: true, optional): Enables watermarking of generated images.
- guidanceIntensity (number, default: 7.5, optional): Controls the intensity of guidance during generation.
- highNoiseFraction (number, default: 0.8, optional): Fraction of noise used when 'expert_ensemble_refiner' is selected.
- numberOfRefineSteps (integer, optional): Number of refinement steps during 'base_image_refiner' processing.
- safetyCheckerDisabled (boolean, default: false, optional): Disables the safety checker for generated images.
- numberOfInferenceSteps (integer, default: 50, optional): Number of denoising steps in the image generation process.
Example Input:
{
"width": 1024,
"height": 1024,
"prompt": "a photo of a girl walking in the forest while wearing a TOK eye mask, face visible",
"refine": "expert_ensemble_refiner",
"scheduler": "K_EULER",
"contraPrompt": "",
"promptImpact": 0.8,
"additiveScale": 0.7,
"numberOfOutputs": 1,
"includeWatermark": true,
"guidanceIntensity": 7.5,
"highNoiseFraction": 0.95,
"numberOfInferenceSteps": 50
}
Output
The action typically returns a list of generated image URIs. For example:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/58bb51dd-d6a5-4f21-9df1-48b312865b9f/872c9118-fe38-48cb-bf68-fdc243907c14.png"
]
Conceptual Usage Example (Python)
Here’s how you might call the "Generate Enhanced Inpainted Image" action using Python:
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 = "bb7bfc41-7d9d-4834-b17f-d071c4f5c58f" # Action ID for Generate Enhanced Inpainted Image
# Construct the input payload based on the action's requirements
payload = {
"width": 1024,
"height": 1024,
"prompt": "a photo of a girl walking in the forest while wearing a TOK eye mask, face visible",
"refine": "expert_ensemble_refiner",
"scheduler": "K_EULER",
"contraPrompt": "",
"promptImpact": 0.8,
"additiveScale": 0.7,
"numberOfOutputs": 1,
"includeWatermark": true,
"guidanceIntensity": 7.5,
"highNoiseFraction": 0.95,
"numberOfInferenceSteps": 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 the Python example above, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID for "Generate Enhanced Inpainted Image" is used to specify which action to invoke, and the input payload is structured according to the required parameters.
Conclusion
The xghm/sdxl-eyemask Cognitive Actions enable developers to enhance their applications with advanced image processing capabilities effortlessly. By integrating these actions, you can provide users with high-quality, customized images that meet their unique needs. Explore the possibilities and consider implementing these actions in your next project to take advantage of their powerful features!