Generate Stunning Images with the luker2000/sleepmask2 Cognitive Actions

The luker2000/sleepmask2 API provides developers with powerful Cognitive Actions designed to generate high-quality images through advanced image manipulation and generation techniques. These pre-built actions simplify the process of creating visually appealing graphics, enabling developers to integrate sophisticated image generation capabilities into their applications seamlessly.
In this blog post, we will explore one of the key actions available in the luker2000/sleepmask2 suite: Generate Image Using Mask. We'll break down its purpose, input requirements, output format, and provide a conceptual Python code example to demonstrate how to integrate this action into your application.
Prerequisites
Before you can start using the Cognitive Actions, ensure you have the following:
- API Key: You'll need an API key for authentication to access the Cognitive Actions platform.
- Setup: Familiarize yourself with how to pass the API key in the request headers for secure access.
Authentication typically involves including the API key in the request headers, allowing you to make calls to the Cognitive Actions endpoint securely.
Cognitive Actions Overview
Generate Image Using Mask
Purpose:
The Generate Image Using Mask action allows users to create high-quality images by leveraging specific image masks and text prompts. This action utilizes advanced models, balancing speed and aesthetic quality to meet diverse creative needs.
Category: Image Generation
Input
The input schema for this action is structured as follows:
- prompt (required): Text prompt guiding the image generation.
- mask (optional): URI of the image mask for inpainting.
- image (optional): URI of the input image for transformation.
- model (optional): Choose between "dev" (for detail) and "schnell" (for speed).
- width (optional): Width of the image in pixels.
- height (optional): Height of the image in pixels.
- goFast (optional): Boolean to enable speed optimization.
- megapixels (optional): Approximate resolution of the image.
- numberOfOutputs (optional): Number of images to generate (1-4).
- qualityOfOutput (optional): Specifies image quality from 0 to 100.
- formatOfOutputImages (optional): Output format (webp, jpg, png).
Here’s an example input payload:
{
"model": "dev",
"goFast": false,
"prompt": "A model wearing Wearing a SLEEPMSK silk sleep mask pushed up on her forehead, not covering her eyes. This is a fashion photography editorial, a professional photoshoot for a luxury brand product marketing campaign, featuring a modern minimalist style with neutral colors. The high-resolution, high-contrast image has a hyper-realistic quality.",
"megapixels": "1",
"loraIntensity": 1,
"guidanceWeight": 3,
"numberOfOutputs": 2,
"promptIntensity": 0.8,
"qualityOfOutput": 80,
"imageAspectRatio": "1:1",
"inferenceStepsCount": 28,
"formatOfOutputImages": "webp",
"additionalLoraIntensity": 1
}
Output
Upon successful execution, the action returns an array of URLs linking to the generated images. Here’s an example output:
[
"https://assets.cognitiveactions.com/invocations/54009047-34be-43a4-9920-a828276c74a4/a8b5db73-7f46-4320-ad1d-2b0ac274e164.webp",
"https://assets.cognitiveactions.com/invocations/54009047-34be-43a4-9920-a828276c74a4/e304c9ae-9098-497a-88e9-cf6bc9e1f5ea.webp"
]
Conceptual Usage Example (Python)
Here’s a Python code snippet demonstrating how to call the Generate Image Using Mask action. Replace placeholders with your specific API key and action ID:
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 = "aaf20e91-8ba6-4635-bf75-99cad0f145ea" # Action ID for Generate Image Using Mask
# Construct the input payload based on the action's requirements
payload = {
"model": "dev",
"goFast": False,
"prompt": "A model wearing Wearing a SLEEPMSK silk sleep mask pushed up on her forehead, not covering her eyes. This is a fashion photography editorial, a professional photoshoot for a luxury brand product marketing campaign, featuring a modern minimalist style with neutral colors. The high-resolution, high-contrast image has a hyper-realistic quality.",
"megapixels": "1",
"loraIntensity": 1,
"guidanceWeight": 3,
"numberOfOutputs": 2,
"promptIntensity": 0.8,
"qualityOfOutput": 80,
"imageAspectRatio": "1:1",
"inferenceStepsCount": 28,
"formatOfOutputImages": "webp",
"additionalLoraIntensity": 1
}
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, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID aaf20e91-8ba6-4635-bf75-99cad0f145ea corresponds to the Generate Image Using Mask action. The payload structure aligns with the input schema we discussed, ensuring that all necessary parameters are included.
Conclusion
The Generate Image Using Mask action from the luker2000/sleepmask2 API offers developers an efficient way to harness the power of AI for image generation. By following the guidelines and examples provided in this article, you can easily integrate this action into your own applications, enhancing their visual appeal with minimal effort.
Consider exploring additional use cases or combining this action with other functionalities to further enrich your application's capabilities!