Create Stunning Images with Inpainting Using the lrnzsp/cinelook Cognitive Actions

In the world of digital content creation, the ability to generate high-quality images effortlessly can be a game changer. The lrnzsp/cinelook Cognitive Actions provide developers with powerful tools for image processing, particularly focusing on generating images through advanced techniques like inpainting. By utilizing pre-built actions, you can streamline your image generation process, enhance creativity, and save time.
In this article, we'll dive into the features of the Generate Image with Inpainting action and show you how to integrate it into your applications.
Prerequisites
Before you can start using the Cognitive Actions, ensure you have the following:
- API Key: You will need an API key for the Cognitive Actions platform to authenticate your requests. This key should be included in the authorization headers of your API calls.
- Network Access: Ensure your application has internet access to make API calls.
Authentication typically involves passing the API key in the headers of your requests, as shown in the examples below.
Cognitive Actions Overview
Generate Image with Inpainting
This action allows you to create images by transforming existing images or generating new ones based on a prompt. The inpainting mode provides customizable settings such as aspect ratio, output quality, and inference steps, optimized for both speed and quality.
Input
The input for this action is structured as follows:
{
"prompt": "TOK portrait photo painting of a woman, day backlight",
"model": "dev",
"goFast": false,
"loraScale": 1,
"guidanceScale": 2,
"extraLoraScale": 1,
"promptStrength": 0.47,
"numberOfOutputs": 4,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"numInferenceSteps": 40,
"imageOutputQuality": 100,
"approximateMegapixels": "1"
}
The main required field is prompt, which defines what the generated image should depict. Other fields allow for fine-tuning the output, such as model, numberOfOutputs, imageAspectRatio, and more.
Output
The action typically returns a list of URLs pointing to the generated images. For example:
[
"https://assets.cognitiveactions.com/invocations/1605bf3b-2b8a-4e19-9460-530d309407f2/5ca52bbc-3f22-4eb5-b10e-8f391de47250.png",
"https://assets.cognitiveactions.com/invocations/1605bf3b-2b8a-4e19-9460-530d309407f2/268d007e-5dd2-4d8a-bb79-2431f9712130.png",
"https://assets.cognitiveactions.com/invocations/1605bf3b-2b8a-4e19-9460-530d309407f2/df786745-7d8f-493a-a996-1831d11f3aca.png",
"https://assets.cognitiveactions.com/invocations/1605bf3b-2b8a-4e19-9460-530d309407f2/f677de82-90e7-4108-b355-9d39230ab7bd.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual example of how to call the Generate Image with Inpainting 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 = "dd5b3498-99cc-4cdf-af71-3e2aad4b0973" # Action ID for Generate Image with Inpainting
# Construct the input payload based on the action's requirements
payload = {
"prompt": "TOK portrait photo painting of a woman, day backlight",
"model": "dev",
"goFast": False,
"loraScale": 1,
"guidanceScale": 2,
"extraLoraScale": 1,
"promptStrength": 0.47,
"numberOfOutputs": 4,
"imageAspectRatio": "16:9",
"imageOutputFormat": "png",
"numInferenceSteps": 40,
"imageOutputQuality": 100,
"approximateMegapixels": "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, you replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured according to the required input schema, and the response will provide the URLs of the generated images.
Conclusion
The Generate Image with Inpainting action from the lrnzsp/cinelook Cognitive Actions empowers developers to create stunning visuals with ease. By leveraging customizable settings and optimization for both speed and quality, you can enhance your applications significantly.
Explore more about the capabilities of these Cognitive Actions and consider integrating them into your projects to elevate your content generation to the next level!